Skip to content

Commit 529d19f

Browse files
committed
fix(bigquery): proxy env detection and oauth2 client
1 parent 8379602 commit 529d19f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

internal/sources/bigquery/bigquery.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,12 @@ func shouldUseRESTClient(proxyAddress string) bool {
725725
if proxyAddress != "" {
726726
return true
727727
}
728-
return os.Getenv("HTTPS_PROXY") != "" || os.Getenv("HTTP_PROXY") != "" || os.Getenv("https_proxy") != "" || os.Getenv("http_proxy") != ""
728+
req, err := http.NewRequest(http.MethodGet, "https://bigquery.googleapis.com", nil)
729+
if err != nil {
730+
return false
731+
}
732+
proxyURL, err := http.ProxyFromEnvironment(req)
733+
return err == nil && proxyURL != nil
729734
}
730735

731736
func initBigQueryConnection(
@@ -761,6 +766,7 @@ func initBigQueryConnection(
761766
if err != nil {
762767
return nil, nil, nil, fmt.Errorf("failed to configure base transport: %w", err)
763768
}
769+
ctx = context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: baseRT})
764770

765771
if impersonateServiceAccount != "" {
766772
// Use default credentials to call IAMCredentials and mint impersonated tokens.
@@ -871,6 +877,7 @@ func newBigQueryClientCreator(
871877
if err != nil {
872878
return nil, err
873879
}
880+
ctx = context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: baseRT})
874881

875882
return func(tokenString string, wantRestService bool) (*bigqueryapi.Client, *bigqueryrestapi.Service, error) {
876883
return initBigQueryConnectionWithOAuthToken(ctx, tracer, project, location, name, tokenString, wantRestService, baseRT)
@@ -911,6 +918,7 @@ func initDataplexConnection(
911918
if err != nil {
912919
return nil, nil, fmt.Errorf("failed to configure base transport: %w", err)
913920
}
921+
ctx = context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: baseRT})
914922

915923
var tokenSource oauth2.TokenSource
916924
if impersonateServiceAccount != "" {
@@ -1004,6 +1012,7 @@ func newDataplexClientCreator(
10041012
return nil, err
10051013
}
10061014
}
1015+
ctx = context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: baseRT})
10071016
}
10081017
return func(tokenString string) (*dataplexapi.CatalogClient, error) {
10091018
return initDataplexConnectionWithOAuthToken(ctx, project, userAgent, tokenString, useREST, baseRT)

0 commit comments

Comments
 (0)