From be2d56dd036cde7c55ed60e7df852fdd5571a6cc Mon Sep 17 00:00:00 2001 From: Julie Qiu Date: Thu, 29 Aug 2024 10:15:24 -0400 Subject: [PATCH] chore(auth): fix staticcheck errors (#10780) --- auth/credentials/detect.go | 4 ++-- auth/credentials/idtoken/compute.go | 4 ++-- auth/grpctransport/grpctransport.go | 2 +- auth/grpctransport/pool_test.go | 2 +- auth/internal/transport/s2a.go | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/auth/credentials/detect.go b/auth/credentials/detect.go index cce6224186a7..010afc37c8fe 100644 --- a/auth/credentials/detect.go +++ b/auth/credentials/detect.go @@ -98,8 +98,8 @@ func DetectDefault(opts *DetectOptions) (*auth.Credentials, error) { if OnGCE() { return auth.NewCredentials(&auth.CredentialsOptions{ TokenProvider: computeTokenProvider(opts), - ProjectIDProvider: auth.CredentialsPropertyFunc(func(context.Context) (string, error) { - return metadata.ProjectID() + ProjectIDProvider: auth.CredentialsPropertyFunc(func(ctx context.Context) (string, error) { + return metadata.ProjectIDWithContext(ctx) }), UniverseDomainProvider: &internal.ComputeUniverseDomainProvider{}, }), nil diff --git a/auth/credentials/idtoken/compute.go b/auth/credentials/idtoken/compute.go index fb9c62c610dc..dced1ec40442 100644 --- a/auth/credentials/idtoken/compute.go +++ b/auth/credentials/idtoken/compute.go @@ -43,8 +43,8 @@ func computeCredentials(opts *Options) (*auth.Credentials, error) { TokenProvider: auth.NewCachedTokenProvider(tp, &auth.CachedTokenProviderOptions{ ExpireEarly: 5 * time.Minute, }), - ProjectIDProvider: auth.CredentialsPropertyFunc(func(context.Context) (string, error) { - return metadata.ProjectID() + ProjectIDProvider: auth.CredentialsPropertyFunc(func(ctx context.Context) (string, error) { + return metadata.ProjectIDWithContext(ctx) }), UniverseDomainProvider: &internal.ComputeUniverseDomainProvider{}, }), nil diff --git a/auth/grpctransport/grpctransport.go b/auth/grpctransport/grpctransport.go index c68c4e531e34..b275e1b15d22 100644 --- a/auth/grpctransport/grpctransport.go +++ b/auth/grpctransport/grpctransport.go @@ -293,7 +293,7 @@ func dial(ctx context.Context, secure bool, opts *Options) (*grpc.ClientConn, er grpcOpts = addOCStatsHandler(grpcOpts, opts) grpcOpts = append(grpcOpts, opts.GRPCDialOpts...) - return grpc.DialContext(ctx, endpoint, grpcOpts...) + return grpc.NewClient(endpoint, grpcOpts...) } // grpcKeyProvider satisfies https://pkg.go.dev/google.golang.org/grpc/credentials#PerRPCCredentials. diff --git a/auth/grpctransport/pool_test.go b/auth/grpctransport/pool_test.go index df0fc0b72d28..64e332791a7e 100644 --- a/auth/grpctransport/pool_test.go +++ b/auth/grpctransport/pool_test.go @@ -68,7 +68,7 @@ func TestClose(t *testing.T) { pool := &roundRobinConnPool{} for i := 0; i < 4; i++ { - conn, err := grpc.Dial(l.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) + conn, err := grpc.NewClient(l.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { t.Fatal(err) } diff --git a/auth/internal/transport/s2a.go b/auth/internal/transport/s2a.go index 4df73edce986..37894bfcd013 100644 --- a/auth/internal/transport/s2a.go +++ b/auth/internal/transport/s2a.go @@ -15,6 +15,7 @@ package transport import ( + "context" "encoding/json" "fmt" "log" @@ -84,7 +85,7 @@ func getMetadataMTLSAutoConfig() { } var httpGetMetadataMTLSConfig = func() (string, error) { - return metadata.Get(configEndpointSuffix) + return metadata.GetWithContext(context.Background(), configEndpointSuffix) } func queryConfig() (*mtlsConfig, error) {