Skip to content

Commit

Permalink
Merge pull request #3 from telia-oss/graphql-proxy-fix
Browse files Browse the repository at this point in the history
Configure http client through context
  • Loading branch information
albinvass authored Jun 13, 2023
2 parents 73e6c1e + a8b3087 commit a32c2ef
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions backend/plugins/github_graphql/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,28 @@ 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" {
if oauthTransport, ok := httpClient.Transport.(*oauth2.Transport); ok {
if httpTransport, ok := oauthTransport.Base.(*http.Transport); ok {
httpTransport.Proxy = http.ProxyURL(pu)
} else {
return nil, errors.Default.New("unable to set proxy for oauth transport")
}
} else if httpTransport, ok := httpClient.Transport.(*http.Transport); ok {
httpTransport.Proxy = http.ProxyURL(pu)
} else {
return nil, errors.Default.New("unable to set proxy for http transport")
proxyClient := http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(pu)},
}
oauthContext = context.WithValue(
taskCtx.GetContext(),
oauth2.HTTPClient,
proxyClient,
)
}
}

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 a32c2ef

Please sign in to comment.