Skip to content

Commit 02244ea

Browse files
committed
refactor buildTransport to match incoming changes
1 parent 30ad910 commit 02244ea

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

internal/api/api.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ type ClientOpts struct {
9696
var ErrCIAccessTokenRequired = errors.New("SRC_ACCESS_TOKEN must be set when CI=true")
9797

9898
func buildTransport(opts ClientOpts, flags *Flags) http.RoundTripper {
99-
transport := http.DefaultTransport.(*http.Transport).Clone()
99+
var transport http.RoundTripper
100+
{
101+
tp := http.DefaultTransport.(*http.Transport).Clone()
100102

101103
if flags.insecureSkipVerify != nil && *flags.insecureSkipVerify {
102104
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
@@ -108,7 +110,15 @@ func buildTransport(opts ClientOpts, flags *Flags) http.RoundTripper {
108110
if opts.AccessToken == "" && opts.OAuthToken != nil {
109111
transport = oauth.NewTransport(transport, opts.OAuthToken)
110112
}
111-
return rt
113+
114+
// not we do not fail here if requireAccessToken is true, because that would
115+
// mean returning an error on construction which we want to avoid for now
116+
// TODO(burmudar): allow returning of an error upon client construction
117+
if opts.AccessToken == "" && opts.OAuthToken != nil {
118+
transport = oauth.NewTransport(transport, opts.OAuthToken)
119+
}
120+
121+
return transport
112122
}
113123

114124
// NewClient creates a new API client.

0 commit comments

Comments
 (0)