Skip to content

Commit

Permalink
Merge pull request #4 from telia-oss/graphql-proxy-fixes-v0.17
Browse files Browse the repository at this point in the history
Graphql and git proxy fixes
  • Loading branch information
albinvass authored Jun 26, 2023
2 parents d09b36d + ad680dd commit 2039628
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/plugins/gitextractor/parser/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (l *GitRepoCreator) CloneOverHTTP(repoId, url, user, password, proxy string
return withTempDirectory(func(dir string) (*GitRepo, error) {
cloneOptions := &git.CloneOptions{Bare: true}
if proxy != "" {
cloneOptions.FetchOptions.ProxyOptions.Type = git.ProxyTypeAuto
cloneOptions.FetchOptions.ProxyOptions.Type = git.ProxyTypeSpecified
cloneOptions.FetchOptions.ProxyOptions.Url = proxy
}
if user != "" {
Expand Down
26 changes: 25 additions & 1 deletion backend/plugins/github_graphql/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package impl
import (
"context"
"fmt"
"net/http"
"net/url"
"reflect"
"time"
Expand Down Expand Up @@ -157,7 +158,30 @@ func (p GithubGraphql) PrepareTaskData(taskCtx plugin.TaskContext, options map[s
src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: connection.GetToken()},
)
httpClient := oauth2.NewClient(taskCtx.GetContext(), src)
oauthContext := taskCtx.GetContext()
proxy := connection.GetProxy()
if proxy != "" {
pu, err := url.Parse(proxy)
if err != nil {
return nil, errors.Convert(err)
}
if pu.Scheme == "http" || pu.Scheme == "socks5" {
proxyClient := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(pu)},
}
oauthContext = context.WithValue(
taskCtx.GetContext(),
oauth2.HTTPClient,
proxyClient,
)
logger.Debug("Proxy set in oauthContext to %s", proxy)
} else {
return nil, errors.BadInput.New("Unsupported scheme set in proxy")
}
}


httpClient := oauth2.NewClient(oauthContext, src)
endpoint, err := errors.Convert01(url.JoinPath(connection.Endpoint, `graphql`))
if err != nil {
return nil, errors.BadInput.Wrap(err, fmt.Sprintf("malformed connection endpoint supplied: %s", connection.Endpoint))
Expand Down

0 comments on commit 2039628

Please sign in to comment.