Skip to content

Commit

Permalink
Merge branch 'main' into release-please--branches--main--components--…
Browse files Browse the repository at this point in the history
…profiler
  • Loading branch information
codyoss authored Jul 1, 2024
2 parents 8eb0b9f + db3c6d1 commit dab48ef
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .release-please-manifest-individual.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"ai": "0.7.0",
"ai": "0.8.0",
"aiplatform": "1.68.0",
"auth": "0.6.0",
"auth": "0.6.1",
"auth/oauth2adapt": "0.2.2",
"bigquery": "1.61.0",
"bigtable": "1.25.0",
Expand Down
13 changes: 13 additions & 0 deletions ai/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [0.8.0](https://github.com/googleapis/google-cloud-go/compare/ai/v0.7.0...ai/v0.8.0) (2024-07-01)


### Features

* **ai/generativelanguage:** Add code execution ([eec7a3b](https://github.com/googleapis/google-cloud-go/commit/eec7a3b5c00fc18076f410ddc4910cdcc61c702c))
* **ai/generativelanguage:** Add max_temperature ([eec7a3b](https://github.com/googleapis/google-cloud-go/commit/eec7a3b5c00fc18076f410ddc4910cdcc61c702c))


### Documentation

* **ai/generativelanguage:** Minor fixes ([eec7a3b](https://github.com/googleapis/google-cloud-go/commit/eec7a3b5c00fc18076f410ddc4910cdcc61c702c))

## [0.7.0](https://github.com/googleapis/google-cloud-go/compare/ai/v0.6.0...ai/v0.7.0) (2024-06-12)


Expand Down
2 changes: 1 addition & 1 deletion ai/internal/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions auth/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [0.6.1](https://github.com/googleapis/google-cloud-go/compare/auth/v0.6.0...auth/v0.6.1) (2024-07-01)


### Bug Fixes

* **auth:** Support gRPC API keys ([#10460](https://github.com/googleapis/google-cloud-go/issues/10460)) ([daa6646](https://github.com/googleapis/google-cloud-go/commit/daa6646d2af5d7fb5b30489f4934c7db89868c7c))
* **auth:** Update http and grpc transports to support token exchange over mTLS ([#10397](https://github.com/googleapis/google-cloud-go/issues/10397)) ([c6dfdcf](https://github.com/googleapis/google-cloud-go/commit/c6dfdcf893c3f971eba15026c12db0a960ae81f2))

## [0.6.0](https://github.com/googleapis/google-cloud-go/compare/auth/v0.5.2...auth/v0.6.0) (2024-06-25)


Expand Down
37 changes: 34 additions & 3 deletions auth/grpctransport/grpctransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ type Options struct {
// configured for the client, which will be compared to the universe domain
// that is separately configured for the credentials.
UniverseDomain string
// APIKey specifies an API key to be used as the basis for authentication.
// If set DetectOpts are ignored.
APIKey string

// InternalOptions are NOT meant to be set directly by consumers of this
// package, they should only be set by generated client code.
Expand All @@ -109,7 +112,8 @@ func (o *Options) validate() error {
if o.InternalOptions != nil && o.InternalOptions.SkipValidation {
return nil
}
hasCreds := o.Credentials != nil ||
hasCreds := o.APIKey != "" ||
o.Credentials != nil ||
(o.DetectOpts != nil && len(o.DetectOpts.CredentialsJSON) > 0) ||
(o.DetectOpts != nil && o.DetectOpts.CredentialsFile != "")
if o.DisableAuthentication && hasCreds {
Expand Down Expand Up @@ -237,8 +241,15 @@ func dial(ctx context.Context, secure bool, opts *Options) (*grpc.ClientConn, er
return nil, err
}

// Authentication can only be sent when communicating over a secure connection.
if !opts.DisableAuthentication {
if opts.APIKey != "" {
grpcOpts = append(grpcOpts,
grpc.WithPerRPCCredentials(&grpcKeyProvider{
apiKey: opts.APIKey,
metadata: opts.Metadata,
secure: secure,
}),
)
} else if !opts.DisableAuthentication {
metadata := opts.Metadata

var creds *auth.Credentials
Expand Down Expand Up @@ -283,6 +294,26 @@ func dial(ctx context.Context, secure bool, opts *Options) (*grpc.ClientConn, er
return grpc.DialContext(ctx, endpoint, grpcOpts...)
}

// grpcKeyProvider satisfies https://pkg.go.dev/google.golang.org/grpc/credentials#PerRPCCredentials.
type grpcKeyProvider struct {
apiKey string
metadata map[string]string
secure bool
}

func (g *grpcKeyProvider) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
metadata := make(map[string]string, len(g.metadata)+1)
metadata["X-goog-api-key"] = g.apiKey
for k, v := range g.metadata {
metadata[k] = v
}
return metadata, nil
}

func (g *grpcKeyProvider) RequireTransportSecurity() bool {
return g.secure
}

// grpcCredentialsProvider satisfies https://pkg.go.dev/google.golang.org/grpc/credentials#PerRPCCredentials.
type grpcCredentialsProvider struct {
creds *auth.Credentials
Expand Down
22 changes: 22 additions & 0 deletions auth/grpctransport/grpctransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,28 @@ func TestNewClient_DetectedServiceAccount(t *testing.T) {
}
}

func TestGRPCKeyProvider_GetRequestMetadata(t *testing.T) {
apiKey := "MY_API_KEY"
reason := "MY_REQUEST_REASON"
ts := grpcKeyProvider{
apiKey: apiKey,
metadata: map[string]string{
"X-goog-request-reason": reason,
},
}
got, err := ts.GetRequestMetadata(context.Background())
if err != nil {
t.Fatal(err)
}
want := map[string]string{
"X-goog-api-key": ts.apiKey,
"X-goog-request-reason": reason,
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("mismatch (-want +got):\n%s", diff)
}
}

type staticTP struct {
tok *auth.Token
}
Expand Down
Loading

0 comments on commit dab48ef

Please sign in to comment.