Skip to content

Commit 7d011f8

Browse files
feat: add TPC support (#2116)
1 parent 35d1a80 commit 7d011f8

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

cmd/root.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ the Proxy will then pick-up automatically.`)
487487
"Enables health check endpoints /startup, /liveness, and /readiness on localhost.")
488488
localFlags.StringVar(&c.conf.APIEndpointURL, "sqladmin-api-endpoint", "",
489489
"API endpoint for all Cloud SQL Admin API requests. (default: https://sqladmin.googleapis.com)")
490+
localFlags.StringVar(&c.conf.UniverseDomain, "universe-domain", "",
491+
"Universe Domain for TPC environments. (default: googleapis.com)")
490492
localFlags.StringVar(&c.conf.QuotaProject, "quota-project", "",
491493
`Specifies the project to use for Cloud SQL Admin API quota tracking.
492494
The IAM principal must have the "serviceusage.services.use" permission
@@ -787,6 +789,9 @@ and re-try with just --auto-iam-authn`)
787789
conf.UserAgent = userAgent
788790
}
789791

792+
if userHasSetLocal(cmd, "sqladmin-api-endpoint") && userHasSetLocal(cmd, "universe-domain") {
793+
return newBadCommandError("cannot specify --sqladmin-api-endpoint and --universe-domain at the same time")
794+
}
790795
if userHasSetLocal(cmd, "sqladmin-api-endpoint") && conf.APIEndpointURL != "" {
791796
_, err := url.Parse(conf.APIEndpointURL)
792797
if err != nil {

cmd/root_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ func TestNewCommandArguments(t *testing.T) {
264264
APIEndpointURL: "https://test.googleapis.com/",
265265
}),
266266
},
267+
{
268+
desc: "using the universe domain flag",
269+
args: []string{"--universe-domain", "test-universe.test", "proj:region:inst"},
270+
want: withDefaults(&proxy.Config{
271+
UniverseDomain: "test-universe.test",
272+
}),
273+
},
267274
{
268275
desc: "using the unix socket flag",
269276
args: []string{"--unix-socket", "/path/to/dir/", "proj:region:inst"},
@@ -1189,6 +1196,12 @@ func TestNewCommandWithErrors(t *testing.T) {
11891196
"--fuse", "myfusedir",
11901197
},
11911198
},
1199+
{
1200+
desc: "using both --sqladmin-api-endpoint and --universe-domain",
1201+
args: []string{
1202+
"--sqladmin-api-endpoint", "https://sqladmin.googleapis.com",
1203+
"--universe-domain", "test-universe.test", "proj:region:inst"},
1204+
},
11921205
}
11931206

11941207
for _, tc := range tcs {

internal/proxy/proxy.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ type Config struct {
144144
// the proxy will use the main public api: https://sqladmin.googleapis.com/
145145
APIEndpointURL string
146146

147+
// UniverseDomain is the universe domain for the TPC environment. When left
148+
// blank, the proxy will use the Google Default Universe (GDU): googleapis.com
149+
UniverseDomain string
150+
147151
// UnixSocket is the directory where Unix sockets will be created,
148152
// connected to any Instances. If set, takes precedence over Addr and Port.
149153
UnixSocket string
@@ -408,6 +412,10 @@ func (c *Config) DialerOptions(l cloudsql.Logger) ([]cloudsqlconn.Option, error)
408412
opts = append(opts, cloudsqlconn.WithAdminAPIEndpoint(c.APIEndpointURL))
409413
}
410414

415+
if c.UniverseDomain != "" {
416+
opts = append(opts, cloudsqlconn.WithUniverseDomain(c.UniverseDomain))
417+
}
418+
411419
if c.IAMAuthN {
412420
opts = append(opts, cloudsqlconn.WithIAMAuthN())
413421
}

0 commit comments

Comments
 (0)