Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(option/internaloption): add WithDefaultMTLSEndpointTemplate #2880

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type DialSettings struct {
DefaultEndpoint string
DefaultEndpointTemplate string
DefaultMTLSEndpoint string
DefaultMTLSEndpointTemplate string
Scopes []string
DefaultScopes []string
EnableJwtWithScope bool
Expand Down
25 changes: 24 additions & 1 deletion option/internaloption/internaloption.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,36 @@ func (o defaultMTLSEndpointOption) Apply(settings *internal.DialSettings) {
settings.DefaultMTLSEndpoint = string(o)
}

// WithDefaultMTLSEndpoint is an option that indicates the default mTLS endpoint.
// WithDefaultMTLSEndpoint is an option that indicates the default mTLS
// endpoint.
//
// It should only be used internally by generated clients.
//
// Deprecated: WithDefaultMTLSEndpoint does not support setting the universe
// domain. Use WithDefaultMTLSEndpointTemplate and WithDefaultUniverseDomain to
// compose the default endpoint instead.
func WithDefaultMTLSEndpoint(url string) option.ClientOption {
return defaultMTLSEndpointOption(url)
}

type defaultMTLSEndpointTemplateOption string

func (o defaultMTLSEndpointTemplateOption) Apply(settings *internal.DialSettings) {
settings.DefaultMTLSEndpointTemplate = string(o)
}

// WithDefaultMTLSEndpointTemplate provides a template for creating the default
// mTLS endpoint using a universe domain. See also WithDefaultUniverseDomain and
// option.WithUniverseDomain. The placeholder UNIVERSE_DOMAIN should be used
// instead of a concrete universe domain such as "googleapis.com".
//
// Example: WithDefaultMTLSEndpointTemplate("https://mtls.UNIVERSE_DOMAIN")
//
// It should only be used internally by generated clients.
func WithDefaultMTLSEndpointTemplate(url string) option.ClientOption {
return defaultMTLSEndpointTemplateOption(url)
}

// SkipDialSettingsValidation bypasses validation on ClientOptions.
//
// It should only be used internally.
Expand Down
14 changes: 8 additions & 6 deletions option/internaloption/internaloption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestDefaultApply(t *testing.T) {
WithDefaultEndpoint("https://example.com:443"),
WithDefaultEndpointTemplate("https://foo.UNIVERSE_DOMAIN/"),
WithDefaultMTLSEndpoint("http://mtls.example.com:445"),
WithDefaultMTLSEndpointTemplate("http://mtls.UNIVERSE_DOMAIN:445"),
WithDefaultScopes("a"),
WithDefaultUniverseDomain("foo.com"),
WithDefaultAudience("audience"),
Expand All @@ -46,12 +47,13 @@ func TestDefaultApply(t *testing.T) {
opt.Apply(&got)
}
want := internal.DialSettings{
DefaultScopes: []string{"a"},
DefaultEndpoint: "https://example.com:443",
DefaultEndpointTemplate: "https://foo.UNIVERSE_DOMAIN/",
DefaultUniverseDomain: "foo.com",
DefaultAudience: "audience",
DefaultMTLSEndpoint: "http://mtls.example.com:445",
DefaultScopes: []string{"a"},
DefaultEndpoint: "https://example.com:443",
DefaultEndpointTemplate: "https://foo.UNIVERSE_DOMAIN/",
DefaultUniverseDomain: "foo.com",
DefaultAudience: "audience",
DefaultMTLSEndpoint: "http://mtls.example.com:445",
DefaultMTLSEndpointTemplate: "http://mtls.UNIVERSE_DOMAIN:445",
}
ignore := []cmp.Option{
cmpopts.IgnoreUnexported(grpc.ClientConn{}),
Expand Down