From 7842e85c53642872948a3c8c9103e8641f54a953 Mon Sep 17 00:00:00 2001 From: Albin Vass Date: Mon, 19 Jun 2023 13:15:54 +0200 Subject: [PATCH 1/2] Use proxy settings for graphql connections --- backend/plugins/github_graphql/impl/impl.go | 26 ++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/backend/plugins/github_graphql/impl/impl.go b/backend/plugins/github_graphql/impl/impl.go index 331e285a0b6..fc035caa9dc 100644 --- a/backend/plugins/github_graphql/impl/impl.go +++ b/backend/plugins/github_graphql/impl/impl.go @@ -20,6 +20,7 @@ package impl import ( "context" "fmt" + "net/http" "net/url" "reflect" "time" @@ -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)) From ad680dd43540dd484029083d7aa3a55db3ebadbf Mon Sep 17 00:00:00 2001 From: Albin Vass Date: Wed, 21 Jun 2023 14:47:21 +0200 Subject: [PATCH 2/2] Fix for gitextractor proxy config git.ProxyTypeSpecified should be used when specifying proxy address, otherwise git seems to only use http_proxy configuration from environment variables even when a proxy url has been given. --- backend/plugins/gitextractor/parser/clone.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/plugins/gitextractor/parser/clone.go b/backend/plugins/gitextractor/parser/clone.go index f9e05df8eb3..b9db6820c47 100644 --- a/backend/plugins/gitextractor/parser/clone.go +++ b/backend/plugins/gitextractor/parser/clone.go @@ -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 != "" {