Skip to content

Commit

Permalink
feat(gengapic): conditionally enable cloud.google.com/go/auth (#1523)
Browse files Browse the repository at this point in the history
* Initial allowlist: cloudkms.googleapis.com, secretmanager.googleapis.com
* update bazel-contrib/setup-bazel to v0.8.4
  • Loading branch information
quartzmo authored May 22, 2024
1 parent dffa58d commit f4f5cc2
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bazel-contrib/[email protected].3
- uses: bazel-contrib/[email protected].4
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bazel-contrib/[email protected].3
- uses: bazel-contrib/[email protected].4
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
Expand Down
1 change: 1 addition & 0 deletions internal/gengapic/client_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func TestClientOpt(t *testing.T) {
"google.iam.v1.IAMPolicy": iamPolicyMethods(),
},
serviceConfig: &serviceconfig.Service{
Name: "showcase.googleapis.com",
Apis: []*apipb.Api{
{Name: "foo.bar.Baz"},
{Name: "google.iam.v1.IAMPolicy"},
Expand Down
6 changes: 6 additions & 0 deletions internal/gengapic/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ import (
"google.golang.org/protobuf/types/pluginpb"
)

var enableNewAuthLibrary = map[string]bool{
"cloudkms.googleapis.com": true,
"secretmanager.googleapis.com": true,
"showcase.googleapis.com": true,
}

type generator struct {
pt printer.P

Expand Down
3 changes: 3 additions & 0 deletions internal/gengapic/gengrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ func (g *generator) grpcClientOptions(serv *descriptorpb.ServiceDescriptorProto,
p(" internaloption.WithDefaultAudience(%q),", generateDefaultAudience(host))
p(" internaloption.WithDefaultScopes(DefaultAuthScopes()...),")
p(" internaloption.EnableJwtWithScope(),")
if _, ok := enableNewAuthLibrary[g.serviceConfig.GetName()]; ok {
p("internaloption.EnableNewAuthLibrary(),")
}
p(" option.WithGRPCDialOption(grpc.WithDefaultCallOptions(")
p(" grpc.MaxCallRecvMsgSize(math.MaxInt32))),")
p(" }")
Expand Down
3 changes: 3 additions & 0 deletions internal/gengapic/genrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ func (g *generator) restClientOptions(serv *descriptorpb.ServiceDescriptorProto,
p(" internaloption.WithDefaultUniverseDomain(%q),", googleDefaultUniverse)
p(" internaloption.WithDefaultAudience(%q),", generateDefaultAudience(host))
p(" internaloption.WithDefaultScopes(DefaultAuthScopes()...),")
if _, ok := enableNewAuthLibrary[g.serviceConfig.GetName()]; ok {
p("internaloption.EnableNewAuthLibrary(),")
}
p(" }")
p("}")
}
Expand Down
1 change: 1 addition & 0 deletions internal/gengapic/testdata/empty_opt.want
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func defaultGRPCClientOptions() []option.ClientOption {
internaloption.WithDefaultAudience("https://foo.googleapis.com/"),
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
internaloption.EnableJwtWithScope(),
internaloption.EnableNewAuthLibrary(),
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(math.MaxInt32))),
}
Expand Down
1 change: 1 addition & 0 deletions internal/gengapic/testdata/foo_opt.want
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func defaultFooGRPCClientOptions() []option.ClientOption {
internaloption.WithDefaultAudience("https://foo.googleapis.com/"),
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
internaloption.EnableJwtWithScope(),
internaloption.EnableNewAuthLibrary(),
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(math.MaxInt32))),
}
Expand Down
1 change: 1 addition & 0 deletions internal/gengapic/testdata/host_port_opt.want
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func defaultBarGRPCClientOptions() []option.ClientOption {
internaloption.WithDefaultAudience("https://foo.googleapis.com/"),
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
internaloption.EnableJwtWithScope(),
internaloption.EnableNewAuthLibrary(),
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(math.MaxInt32))),
}
Expand Down
1 change: 1 addition & 0 deletions internal/gengapic/testdata/iam_override_opt.want
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func defaultBazGRPCClientOptions() []option.ClientOption {
internaloption.WithDefaultAudience("https://foo.googleapis.com/"),
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
internaloption.EnableJwtWithScope(),
internaloption.EnableNewAuthLibrary(),
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(math.MaxInt32))),
}
Expand Down

0 comments on commit f4f5cc2

Please sign in to comment.