Skip to content

Commit

Permalink
Merge branch 'main' into proto-custom-encoder-decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
harshachinta authored Sep 2, 2024
2 parents d177f59 + 633dc86 commit 275097c
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest-individual.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"ai": "0.8.2",
"aiplatform": "1.68.0",
"auth": "0.9.1",
"auth": "0.9.2",
"auth/oauth2adapt": "0.2.4",
"bigquery": "1.62.0",
"bigtable": "1.31.0",
Expand Down
13 changes: 13 additions & 0 deletions auth/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [0.9.2](https://github.com/googleapis/google-cloud-go/compare/auth/v0.9.1...auth/v0.9.2) (2024-08-30)


### Bug Fixes

* **auth:** Handle non-Transport DefaultTransport ([#10733](https://github.com/googleapis/google-cloud-go/issues/10733)) ([98d91dc](https://github.com/googleapis/google-cloud-go/commit/98d91dc8316b247498fab41ab35e57a0446fe556)), refs [#10742](https://github.com/googleapis/google-cloud-go/issues/10742)
* **auth:** Make sure quota option takes precedence over env/file ([#10797](https://github.com/googleapis/google-cloud-go/issues/10797)) ([f1b050d](https://github.com/googleapis/google-cloud-go/commit/f1b050d56d804b245cab048c2980d32b0eaceb4e)), refs [#10795](https://github.com/googleapis/google-cloud-go/issues/10795)


### Documentation

* **auth:** Fix Go doc comment link ([#10751](https://github.com/googleapis/google-cloud-go/issues/10751)) ([015acfa](https://github.com/googleapis/google-cloud-go/commit/015acfab4d172650928bb1119bc2cd6307b9a437))

## [0.9.1](https://github.com/googleapis/google-cloud-go/compare/auth/v0.9.0...auth/v0.9.1) (2024-08-22)


Expand Down
7 changes: 5 additions & 2 deletions auth/grpctransport/grpctransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
// Check env to decide if using google-c2p resolver for DirectPath traffic.
enableDirectPathXdsEnvVar = "GOOGLE_CLOUD_ENABLE_DIRECT_PATH_XDS"

quotaProjectHeaderKey = "X-Goog-User-Project"
quotaProjectHeaderKey = "X-goog-user-project"
)

var (
Expand Down Expand Up @@ -273,7 +273,10 @@ func dial(ctx context.Context, secure bool, opts *Options) (*grpc.ClientConn, er
if metadata == nil {
metadata = make(map[string]string, 1)
}
metadata[quotaProjectHeaderKey] = qp
// Don't overwrite user specified quota
if _, ok := metadata[quotaProjectHeaderKey]; !ok {
metadata[quotaProjectHeaderKey] = qp
}
}
grpcOpts = append(grpcOpts,
grpc.WithPerRPCCredentials(&grpcCredentialsProvider{
Expand Down
50 changes: 50 additions & 0 deletions auth/grpctransport/grpctransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,56 @@ func TestGRPCKeyProvider_GetRequestMetadata(t *testing.T) {
}
}

func TestNewClient_QuotaPrecedence(t *testing.T) {
testQuota := "testquotaWins"
t.Setenv(internal.QuotaProjectEnvVar, "testquotaLoses")
l, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatal(err)
}
gsrv := grpc.NewServer()
defer gsrv.Stop()
echo.RegisterEchoerServer(gsrv, &fakeEchoService{
Fn: func(ctx context.Context, _ *echo.EchoRequest) (*echo.EchoReply, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
t.Error("unable to extract metadata")
return nil, errors.New("oops")
}
if got := md.Get(quotaProjectHeaderKey); len(got) != 1 || got[0] != testQuota {
t.Errorf("got %q, want %q", got, testQuota)
}
return &echo.EchoReply{}, nil
},
})
go func() {
if err := gsrv.Serve(l); err != nil {
panic(err)
}
}()

pool, err := Dial(context.Background(), false, &Options{
Metadata: map[string]string{quotaProjectHeaderKey: "testquotaWins"},
InternalOptions: &InternalOptions{
DefaultEndpointTemplate: l.Addr().String(),
},
DetectOpts: &credentials.DetectOptions{
Audience: l.Addr().String(),
CredentialsFile: "../internal/testdata/sa_universe_domain.json",
UseSelfSignedJWT: true,
},
GRPCDialOpts: []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())},
UniverseDomain: "example.com", // Also configured in sa_universe_domain.json
})
if err != nil {
t.Fatalf("NewClient() = %v", err)
}
client := echo.NewEchoerClient(pool)
if _, err := client.Echo(context.Background(), &echo.EchoRequest{}); err != nil {
t.Fatalf("client.Echo() = %v", err)
}
}

type staticTP struct {
tok *auth.Token
}
Expand Down
31 changes: 31 additions & 0 deletions auth/httptransport/httptransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,37 @@ func TestNewClient_APIKey(t *testing.T) {
}
}

func TestNewClient_QuotaPrecedence(t *testing.T) {
testQuota := "testquotaWins"
t.Setenv(internal.QuotaProjectEnvVar, "testquotaLoses")
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if got := r.Header.Get(quotaProjectHeaderKey); got != testQuota {
t.Errorf("got %q, want %q", got, testQuota)
}
}))
defer ts.Close()

h := make(http.Header)
h.Set(quotaProjectHeaderKey, testQuota)
client, err := NewClient(&Options{
InternalOptions: &InternalOptions{
DefaultEndpointTemplate: ts.URL,
},
DetectOpts: &credentials.DetectOptions{
Audience: ts.URL,
CredentialsFile: "../internal/testdata/sa.json",
UseSelfSignedJWT: true,
},
Headers: h,
})
if err != nil {
t.Fatalf("NewClient() = %v", err)
}
if _, err := client.Get(ts.URL); err != nil {
t.Fatalf("client.Get() = %v", err)
}
}

func TestNewClient_BaseRoundTripper(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
got := r.Header.Get("Foo")
Expand Down
7 changes: 5 additions & 2 deletions auth/httptransport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

const (
quotaProjectHeaderKey = "X-Goog-User-Project"
quotaProjectHeaderKey = "X-goog-user-project"
)

func newTransport(base http.RoundTripper, opts *Options) (http.RoundTripper, error) {
Expand Down Expand Up @@ -76,7 +76,10 @@ func newTransport(base http.RoundTripper, opts *Options) (http.RoundTripper, err
if headers == nil {
headers = make(map[string][]string, 1)
}
headers.Set(quotaProjectHeaderKey, qp)
// Don't overwrite user specified quota
if v := headers.Get(quotaProjectHeaderKey); v == "" {
headers.Set(quotaProjectHeaderKey, qp)
}
}
creds.TokenProvider = auth.NewCachedTokenProvider(creds.TokenProvider, nil)
trans = &authTransport{
Expand Down
2 changes: 1 addition & 1 deletion bigtable/bttest/inmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (s *server) ModifyColumnFamilies(ctx context.Context, req *btapb.ModifyColu
return nil, fmt.Errorf("no such family %q", mod.Id)
}
if cf.valueType != newcf.valueType {
return nil, status.Errorf(codes.InvalidArgument, "Immutable fields 'value_type' cannot be updated")
return nil, status.Errorf(codes.InvalidArgument, "Immutable fields 'value_type.aggregate_type' cannot be updated")
}

// assume that we ALWAYS want to replace by the new setting
Expand Down
4 changes: 2 additions & 2 deletions bigtable/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,11 @@ func TestIntegration_Aggregates(t *testing.T) {
t.Fatalf("Read row mismatch.\n got %#v\nwant %#v", row, wantRow)
}

err = ac.UpdateFamily(ctx, tableName, family, Family{ValueType: Int64Type{}})
err = ac.UpdateFamily(ctx, tableName, family, Family{ValueType: StringType{}})
if err == nil {
t.Fatalf("Expected UpdateFamily to fail, but it didn't")
}
wantError := "Immutable fields 'value_type' cannot be updated"
wantError := "Immutable fields 'value_type.aggregate_type' cannot be updated"
if !strings.Contains(err.Error(), wantError) {
t.Errorf("Wrong error. Expected to containt %q but was %v", wantError, err)
}
Expand Down

0 comments on commit 275097c

Please sign in to comment.