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: expose experimental universe-related options #2264

Merged
merged 8 commits into from
Nov 30, 2023
Merged
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
2 changes: 2 additions & 0 deletions internal/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type DialSettings struct {
EnableDirectPathXds bool
EnableNewAuthLibrary bool
AllowNonDefaultServiceAccount bool
UniverseDomain string
DefaultUniverseDomain string

// Google API system parameters. For more information please read:
// https://cloud.google.com/apis/docs/system-parameters
Expand Down
16 changes: 16 additions & 0 deletions option/internaloption/internaloption.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ func (w withDefaultScopes) Apply(o *internal.DialSettings) {
copy(o.DefaultScopes, w)
}

// WithDefaultUniverseDomain returns a ClientOption that sets the default universe domain.
//
// It should only be used internally by generated clients.
shollyman marked this conversation as resolved.
Show resolved Hide resolved
//
// This is similar to the public WithUniverse, but allows us to determine whether the user has
// overridden the default universe.
func WithDefaultUniverseDomain(ud string) option.ClientOption {
return withDefaultUniverseDomain(ud)
}

type withDefaultUniverseDomain string

func (w withDefaultUniverseDomain) Apply(o *internal.DialSettings) {
o.DefaultUniverseDomain = string(w)
}

// EnableJwtWithScope returns a ClientOption that specifies if scope can be used
// with self-signed JWT.
func EnableJwtWithScope() option.ClientOption {
Expand Down
28 changes: 28 additions & 0 deletions option/internaloption/internaloption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ package internaloption
import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/api/internal"
"google.golang.org/api/option"
"google.golang.org/grpc"
)

func TestWithCredentials(t *testing.T) {
Expand All @@ -27,3 +31,27 @@ func TestWithCredentials(t *testing.T) {
t.Errorf("ts.Token() = %q, want %q", tok.AccessToken, "")
}
}

func TestDefaultApply(t *testing.T) {
opts := []option.ClientOption{
WithDefaultEndpoint("https://example.com:443"),
WithDefaultMTLSEndpoint("http://mtls.example.com:445"),
WithDefaultScopes("a"),
WithDefaultUniverseDomain("foo.com"),
WithDefaultAudience("audience"),
}
var got internal.DialSettings
for _, opt := range opts {
opt.Apply(&got)
}
want := internal.DialSettings{
DefaultScopes: []string{"a"},
DefaultEndpoint: "https://example.com:443",
DefaultUniverseDomain: "foo.com",
DefaultAudience: "audience",
DefaultMTLSEndpoint: "http://mtls.example.com:445",
}
if !cmp.Equal(got, want, cmpopts.IgnoreUnexported(grpc.ClientConn{}), cmpopts.IgnoreFields(google.Credentials{}, "universeDomain")) {
t.Errorf(cmp.Diff(got, want, cmpopts.IgnoreUnexported(grpc.ClientConn{}), cmpopts.IgnoreFields(google.Credentials{}, "universeDomain")))
}
}
13 changes: 13 additions & 0 deletions option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,16 @@ func (w *withCreds) Apply(o *internal.DialSettings) {
func WithCredentials(creds *google.Credentials) ClientOption {
return (*withCreds)(creds)
}

// WithUniverseDomain returns a ClientOption that sets the universe domain.
//
// This is an EXPERIMENTAL API and may be changed or removed in the future.
func WithUniverseDomain(ud string) ClientOption {
return withUniverseDomain(ud)
}

type withUniverseDomain string

func (w withUniverseDomain) Apply(o *internal.DialSettings) {
o.UniverseDomain = string(w)
}
2 changes: 2 additions & 0 deletions option/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func TestApply(t *testing.T) {
WithQuotaProject("user-project"),
WithRequestReason("Request Reason"),
WithTelemetryDisabled(),
WithUniverseDomain("universe.com"),
}
var got internal.DialSettings
for _, opt := range opts {
Expand All @@ -91,6 +92,7 @@ func TestApply(t *testing.T) {
QuotaProject: "user-project",
RequestReason: "Request Reason",
TelemetryDisabled: true,
UniverseDomain: "universe.com",
}
if !cmp.Equal(got, want, cmpopts.IgnoreUnexported(grpc.ClientConn{}), cmpopts.IgnoreFields(google.Credentials{}, "universeDomain")) {
t.Errorf(cmp.Diff(got, want, cmpopts.IgnoreUnexported(grpc.ClientConn{}), cmpopts.IgnoreFields(google.Credentials{}, "universeDomain")))
Expand Down