Skip to content

Commit 2039628

Browse files
author
Albin Vass
authored
Merge pull request #4 from telia-oss/graphql-proxy-fixes-v0.17
Graphql and git proxy fixes
2 parents d09b36d + ad680dd commit 2039628

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

backend/plugins/gitextractor/parser/clone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (l *GitRepoCreator) CloneOverHTTP(repoId, url, user, password, proxy string
5959
return withTempDirectory(func(dir string) (*GitRepo, error) {
6060
cloneOptions := &git.CloneOptions{Bare: true}
6161
if proxy != "" {
62-
cloneOptions.FetchOptions.ProxyOptions.Type = git.ProxyTypeAuto
62+
cloneOptions.FetchOptions.ProxyOptions.Type = git.ProxyTypeSpecified
6363
cloneOptions.FetchOptions.ProxyOptions.Url = proxy
6464
}
6565
if user != "" {

backend/plugins/github_graphql/impl/impl.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package impl
2020
import (
2121
"context"
2222
"fmt"
23+
"net/http"
2324
"net/url"
2425
"reflect"
2526
"time"
@@ -157,7 +158,30 @@ func (p GithubGraphql) PrepareTaskData(taskCtx plugin.TaskContext, options map[s
157158
src := oauth2.StaticTokenSource(
158159
&oauth2.Token{AccessToken: connection.GetToken()},
159160
)
160-
httpClient := oauth2.NewClient(taskCtx.GetContext(), src)
161+
oauthContext := taskCtx.GetContext()
162+
proxy := connection.GetProxy()
163+
if proxy != "" {
164+
pu, err := url.Parse(proxy)
165+
if err != nil {
166+
return nil, errors.Convert(err)
167+
}
168+
if pu.Scheme == "http" || pu.Scheme == "socks5" {
169+
proxyClient := &http.Client{
170+
Transport: &http.Transport{Proxy: http.ProxyURL(pu)},
171+
}
172+
oauthContext = context.WithValue(
173+
taskCtx.GetContext(),
174+
oauth2.HTTPClient,
175+
proxyClient,
176+
)
177+
logger.Debug("Proxy set in oauthContext to %s", proxy)
178+
} else {
179+
return nil, errors.BadInput.New("Unsupported scheme set in proxy")
180+
}
181+
}
182+
183+
184+
httpClient := oauth2.NewClient(oauthContext, src)
161185
endpoint, err := errors.Convert01(url.JoinPath(connection.Endpoint, `graphql`))
162186
if err != nil {
163187
return nil, errors.BadInput.Wrap(err, fmt.Sprintf("malformed connection endpoint supplied: %s", connection.Endpoint))

0 commit comments

Comments
 (0)