Skip to content

Commit

Permalink
Merge pull request #2 from telia-oss/graphql-proxy-fix
Browse files Browse the repository at this point in the history
Fix type assert
  • Loading branch information
albinvass authored Jun 13, 2023
2 parents 132c1c8 + 142451c commit 73e6c1e
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions backend/plugins/github_graphql/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package impl
import (
"context"
"fmt"
"net/url"
"net/http"
"net/url"
"reflect"
"time"

Expand Down Expand Up @@ -159,16 +159,26 @@ func (p GithubGraphql) PrepareTaskData(taskCtx plugin.TaskContext, options map[s
&oauth2.Token{AccessToken: connection.GetToken()},
)
httpClient := oauth2.NewClient(taskCtx.GetContext(), src)
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" {
httpClient.Transport.(*http.Transport).Proxy = http.ProxyURL(pu)
}
}
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")
}
}
}

endpoint, err := errors.Convert01(url.JoinPath(connection.Endpoint, `graphql`))
if err != nil {
Expand Down

0 comments on commit 73e6c1e

Please sign in to comment.