Skip to content

Commit

Permalink
chore: use instance uri (GoogleCloudPlatform#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtisvg authored Apr 18, 2022
1 parent 5b9c264 commit eb7efcd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewCommand(opts ...Option) *Command {
}

cmd := &cobra.Command{
Use: "alloydb-auth-proxy instance_connection_name...",
Use: "alloydb-auth-proxy instance_uri...",
Version: versionString,
Short: "alloydb-auth-proxy provides a secure way to authorize connections to AlloyDB.",
Long: `The AlloyDB Auth proxy provides IAM-based authorization and encryption when
Expand Down Expand Up @@ -124,7 +124,7 @@ without having to manage any client SSL certificates.`,
func parseConfig(cmd *cobra.Command, conf *proxy.Config, args []string) error {
// If no instance connection names were provided, error.
if len(args) == 0 {
return newBadCommandError("missing instance_connection_name (e.g., project:region:instance)")
return newBadCommandError("missing instance uri (e.g., /projects/$PROJECTS/locations/$LOCTION/clusters/$CLUSTER/instances/$INSTANCES)")
}
// First, validate global config.
if ip := net.ParseIP(conf.Addr); ip == nil {
Expand Down
52 changes: 26 additions & 26 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestNewCommandArguments(t *testing.T) {
c.Instances = []proxy.InstanceConnConfig{{}}
}
if i := &c.Instances[0]; i.Name == "" {
i.Name = "proj:region:inst"
i.Name = "/projects/proj/locations/region/clusters/clust/instances/inst"
}
return c
}
Expand All @@ -53,56 +53,56 @@ func TestNewCommandArguments(t *testing.T) {
}{
{
desc: "basic invocation with defaults",
args: []string{"proj:region:inst"},
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst"},
want: withDefaults(&proxy.Config{
Addr: "127.0.0.1",
Instances: []proxy.InstanceConnConfig{{Name: "proj:region:inst"}},
Instances: []proxy.InstanceConnConfig{{Name: "/projects/proj/locations/region/clusters/clust/instances/inst"}},
}),
},
{
desc: "using the address flag",
args: []string{"--address", "0.0.0.0", "proj:region:inst"},
args: []string{"--address", "0.0.0.0", "/projects/proj/locations/region/clusters/clust/instances/inst"},
want: withDefaults(&proxy.Config{
Addr: "0.0.0.0",
Instances: []proxy.InstanceConnConfig{{Name: "proj:region:inst"}},
Instances: []proxy.InstanceConnConfig{{Name: "/projects/proj/locations/region/clusters/clust/instances/inst"}},
}),
},
{
desc: "using the address (short) flag",
args: []string{"-a", "0.0.0.0", "proj:region:inst"},
args: []string{"-a", "0.0.0.0", "/projects/proj/locations/region/clusters/clust/instances/inst"},
want: withDefaults(&proxy.Config{
Addr: "0.0.0.0",
Instances: []proxy.InstanceConnConfig{{Name: "proj:region:inst"}},
Instances: []proxy.InstanceConnConfig{{Name: "/projects/proj/locations/region/clusters/clust/instances/inst"}},
}),
},
{
desc: "using the address query param",
args: []string{"proj:region:inst?address=0.0.0.0"},
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address=0.0.0.0"},
want: withDefaults(&proxy.Config{
Addr: "127.0.0.1",
Instances: []proxy.InstanceConnConfig{{
Addr: "0.0.0.0",
Name: "proj:region:inst",
Name: "/projects/proj/locations/region/clusters/clust/instances/inst",
}},
}),
},
{
desc: "using the port flag",
args: []string{"--port", "6000", "proj:region:inst"},
args: []string{"--port", "6000", "/projects/proj/locations/region/clusters/clust/instances/inst"},
want: withDefaults(&proxy.Config{
Port: 6000,
}),
},
{
desc: "using the port (short) flag",
args: []string{"-p", "6000", "proj:region:inst"},
args: []string{"-p", "6000", "/projects/proj/locations/region/clusters/clust/instances/inst"},
want: withDefaults(&proxy.Config{
Port: 6000,
}),
},
{
desc: "using the port query param",
args: []string{"proj:region:inst?port=6000"},
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?port=6000"},
want: withDefaults(&proxy.Config{
Instances: []proxy.InstanceConnConfig{{
Port: 6000,
Expand All @@ -111,28 +111,28 @@ func TestNewCommandArguments(t *testing.T) {
},
{
desc: "using the token flag",
args: []string{"--token", "MYCOOLTOKEN", "proj:region:inst"},
args: []string{"--token", "MYCOOLTOKEN", "/projects/proj/locations/region/clusters/clust/instances/inst"},
want: withDefaults(&proxy.Config{
Token: "MYCOOLTOKEN",
}),
},
{
desc: "using the token (short) flag",
args: []string{"-t", "MYCOOLTOKEN", "proj:region:inst"},
args: []string{"-t", "MYCOOLTOKEN", "/projects/proj/locations/region/clusters/clust/instances/inst"},
want: withDefaults(&proxy.Config{
Token: "MYCOOLTOKEN",
}),
},
{
desc: "using the credentiale file flag",
args: []string{"--credentials-file", "/path/to/file", "proj:region:inst"},
args: []string{"--credentials-file", "/path/to/file", "/projects/proj/locations/region/clusters/clust/instances/inst"},
want: withDefaults(&proxy.Config{
CredentialsFile: "/path/to/file",
}),
},
{
desc: "using the (short) credentiale file flag",
args: []string{"-c", "/path/to/file", "proj:region:inst"},
args: []string{"-c", "/path/to/file", "/projects/proj/locations/region/clusters/clust/instances/inst"},
want: withDefaults(&proxy.Config{
CredentialsFile: "/path/to/file",
}),
Expand Down Expand Up @@ -174,41 +174,41 @@ func TestNewCommandWithErrors(t *testing.T) {
},
{
desc: "when the query string is bogus",
args: []string{"proj:region:inst?%=foo"},
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?%=foo"},
},
{
desc: "when the address query param is empty",
args: []string{"proj:region:inst?address="},
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address="},
},
{
desc: "using the address flag with a bad IP address",
args: []string{"--address", "bogus", "proj:region:inst"},
args: []string{"--address", "bogus", "/projects/proj/locations/region/clusters/clust/instances/inst"},
},
{
desc: "when the address query param is not an IP address",
args: []string{"proj:region:inst?address=世界"},
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address=世界"},
},
{
desc: "when the address query param contains multiple values",
args: []string{"proj:region:inst?address=0.0.0.0&address=1.1.1.1&address=2.2.2.2"},
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address=0.0.0.0&address=1.1.1.1&address=2.2.2.2"},
},
{
desc: "when the query string is invalid",
args: []string{"proj:region:inst?address=1.1.1.1?foo=2.2.2.2"},
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address=1.1.1.1?foo=2.2.2.2"},
},
{
desc: "when the port query param contains multiple values",
args: []string{"proj:region:inst?port=1&port=2"},
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?port=1&port=2"},
},
{
desc: "when the port query param is not a number",
args: []string{"proj:region:inst?port=hi"},
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?port=hi"},
},
{
desc: "when both token and credentials file is set",
args: []string{
"--token", "my-token",
"--credentials-file", "/path/to/file", "proj:region:inst"},
"--credentials-file", "/path/to/file", "/projects/proj/locations/region/clusters/clust/instances/inst"},
},
}

Expand Down Expand Up @@ -256,7 +256,7 @@ func (*spyDialer) Close() error {
}

func TestCommandWithCustomDialer(t *testing.T) {
want := "my-project:my-region:my-cluster:my-instance"
want := "/projects/my-project/locations/my-region/clusters/my-cluster/instances/my-instance"
s := &spyDialer{}
c := NewCommand(WithDialer(s))
// Keep the test output quiet
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/GoogleCloudPlatform/alloydb-auth-proxy
go 1.16

require (
cloud.google.com/go/alloydbconn v0.0.0-0.20220401153611-87e713b37755
cloud.google.com/go/alloydbconn v0.0.0-00010101000000-000000000000
github.com/google/go-cmp v0.5.7
github.com/lib/pq v1.10.5 // indirect
github.com/spf13/cobra v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions internal/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (fakeDialer) Close() error {

func TestClientInitialization(t *testing.T) {
ctx := context.Background()
cluster1 := "proj:region:cluster:instance1"
cluster2 := "proj:region:cluster:instance2"
cluster1 := "/projects/proj/locations/region/clusters/clust/instances/inst1"
cluster2 := "/projects/proj/locations/region/clusters/clust/instances/inst2"

tcs := []struct {
desc string
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cloud.google.com/go/alloydbconn v0.0.0-0.20220401153611-87e713b37755 => ../alloydb-go-connector
# cloud.google.com/go/alloydbconn v0.0.0-00010101000000-000000000000 => ../alloydb-go-connector
## explicit
cloud.google.com/go/alloydbconn
cloud.google.com/go/alloydbconn/driver/pgxv4
Expand Down

0 comments on commit eb7efcd

Please sign in to comment.