Skip to content

Commit

Permalink
feat: add TPC support (#2116)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwotherspoon authored Mar 11, 2024
1 parent 35d1a80 commit 7d011f8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ the Proxy will then pick-up automatically.`)
"Enables health check endpoints /startup, /liveness, and /readiness on localhost.")
localFlags.StringVar(&c.conf.APIEndpointURL, "sqladmin-api-endpoint", "",
"API endpoint for all Cloud SQL Admin API requests. (default: https://sqladmin.googleapis.com)")
localFlags.StringVar(&c.conf.UniverseDomain, "universe-domain", "",
"Universe Domain for TPC environments. (default: googleapis.com)")
localFlags.StringVar(&c.conf.QuotaProject, "quota-project", "",
`Specifies the project to use for Cloud SQL Admin API quota tracking.
The IAM principal must have the "serviceusage.services.use" permission
Expand Down Expand Up @@ -787,6 +789,9 @@ and re-try with just --auto-iam-authn`)
conf.UserAgent = userAgent
}

if userHasSetLocal(cmd, "sqladmin-api-endpoint") && userHasSetLocal(cmd, "universe-domain") {
return newBadCommandError("cannot specify --sqladmin-api-endpoint and --universe-domain at the same time")
}
if userHasSetLocal(cmd, "sqladmin-api-endpoint") && conf.APIEndpointURL != "" {
_, err := url.Parse(conf.APIEndpointURL)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ func TestNewCommandArguments(t *testing.T) {
APIEndpointURL: "https://test.googleapis.com/",
}),
},
{
desc: "using the universe domain flag",
args: []string{"--universe-domain", "test-universe.test", "proj:region:inst"},
want: withDefaults(&proxy.Config{
UniverseDomain: "test-universe.test",
}),
},
{
desc: "using the unix socket flag",
args: []string{"--unix-socket", "/path/to/dir/", "proj:region:inst"},
Expand Down Expand Up @@ -1189,6 +1196,12 @@ func TestNewCommandWithErrors(t *testing.T) {
"--fuse", "myfusedir",
},
},
{
desc: "using both --sqladmin-api-endpoint and --universe-domain",
args: []string{
"--sqladmin-api-endpoint", "https://sqladmin.googleapis.com",
"--universe-domain", "test-universe.test", "proj:region:inst"},
},
}

for _, tc := range tcs {
Expand Down
8 changes: 8 additions & 0 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ type Config struct {
// the proxy will use the main public api: https://sqladmin.googleapis.com/
APIEndpointURL string

// UniverseDomain is the universe domain for the TPC environment. When left
// blank, the proxy will use the Google Default Universe (GDU): googleapis.com
UniverseDomain string

// UnixSocket is the directory where Unix sockets will be created,
// connected to any Instances. If set, takes precedence over Addr and Port.
UnixSocket string
Expand Down Expand Up @@ -408,6 +412,10 @@ func (c *Config) DialerOptions(l cloudsql.Logger) ([]cloudsqlconn.Option, error)
opts = append(opts, cloudsqlconn.WithAdminAPIEndpoint(c.APIEndpointURL))
}

if c.UniverseDomain != "" {
opts = append(opts, cloudsqlconn.WithUniverseDomain(c.UniverseDomain))
}

if c.IAMAuthN {
opts = append(opts, cloudsqlconn.WithIAMAuthN())
}
Expand Down

0 comments on commit 7d011f8

Please sign in to comment.