Skip to content

Commit eb7efcd

Browse files
authored
chore: use instance uri (GoogleCloudPlatform#5)
1 parent 5b9c264 commit eb7efcd

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

cmd/root.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func NewCommand(opts ...Option) *Command {
8484
}
8585

8686
cmd := &cobra.Command{
87-
Use: "alloydb-auth-proxy instance_connection_name...",
87+
Use: "alloydb-auth-proxy instance_uri...",
8888
Version: versionString,
8989
Short: "alloydb-auth-proxy provides a secure way to authorize connections to AlloyDB.",
9090
Long: `The AlloyDB Auth proxy provides IAM-based authorization and encryption when
@@ -124,7 +124,7 @@ without having to manage any client SSL certificates.`,
124124
func parseConfig(cmd *cobra.Command, conf *proxy.Config, args []string) error {
125125
// If no instance connection names were provided, error.
126126
if len(args) == 0 {
127-
return newBadCommandError("missing instance_connection_name (e.g., project:region:instance)")
127+
return newBadCommandError("missing instance uri (e.g., /projects/$PROJECTS/locations/$LOCTION/clusters/$CLUSTER/instances/$INSTANCES)")
128128
}
129129
// First, validate global config.
130130
if ip := net.ParseIP(conf.Addr); ip == nil {

cmd/root_test.go

+26-26
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestNewCommandArguments(t *testing.T) {
4242
c.Instances = []proxy.InstanceConnConfig{{}}
4343
}
4444
if i := &c.Instances[0]; i.Name == "" {
45-
i.Name = "proj:region:inst"
45+
i.Name = "/projects/proj/locations/region/clusters/clust/instances/inst"
4646
}
4747
return c
4848
}
@@ -53,56 +53,56 @@ func TestNewCommandArguments(t *testing.T) {
5353
}{
5454
{
5555
desc: "basic invocation with defaults",
56-
args: []string{"proj:region:inst"},
56+
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst"},
5757
want: withDefaults(&proxy.Config{
5858
Addr: "127.0.0.1",
59-
Instances: []proxy.InstanceConnConfig{{Name: "proj:region:inst"}},
59+
Instances: []proxy.InstanceConnConfig{{Name: "/projects/proj/locations/region/clusters/clust/instances/inst"}},
6060
}),
6161
},
6262
{
6363
desc: "using the address flag",
64-
args: []string{"--address", "0.0.0.0", "proj:region:inst"},
64+
args: []string{"--address", "0.0.0.0", "/projects/proj/locations/region/clusters/clust/instances/inst"},
6565
want: withDefaults(&proxy.Config{
6666
Addr: "0.0.0.0",
67-
Instances: []proxy.InstanceConnConfig{{Name: "proj:region:inst"}},
67+
Instances: []proxy.InstanceConnConfig{{Name: "/projects/proj/locations/region/clusters/clust/instances/inst"}},
6868
}),
6969
},
7070
{
7171
desc: "using the address (short) flag",
72-
args: []string{"-a", "0.0.0.0", "proj:region:inst"},
72+
args: []string{"-a", "0.0.0.0", "/projects/proj/locations/region/clusters/clust/instances/inst"},
7373
want: withDefaults(&proxy.Config{
7474
Addr: "0.0.0.0",
75-
Instances: []proxy.InstanceConnConfig{{Name: "proj:region:inst"}},
75+
Instances: []proxy.InstanceConnConfig{{Name: "/projects/proj/locations/region/clusters/clust/instances/inst"}},
7676
}),
7777
},
7878
{
7979
desc: "using the address query param",
80-
args: []string{"proj:region:inst?address=0.0.0.0"},
80+
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address=0.0.0.0"},
8181
want: withDefaults(&proxy.Config{
8282
Addr: "127.0.0.1",
8383
Instances: []proxy.InstanceConnConfig{{
8484
Addr: "0.0.0.0",
85-
Name: "proj:region:inst",
85+
Name: "/projects/proj/locations/region/clusters/clust/instances/inst",
8686
}},
8787
}),
8888
},
8989
{
9090
desc: "using the port flag",
91-
args: []string{"--port", "6000", "proj:region:inst"},
91+
args: []string{"--port", "6000", "/projects/proj/locations/region/clusters/clust/instances/inst"},
9292
want: withDefaults(&proxy.Config{
9393
Port: 6000,
9494
}),
9595
},
9696
{
9797
desc: "using the port (short) flag",
98-
args: []string{"-p", "6000", "proj:region:inst"},
98+
args: []string{"-p", "6000", "/projects/proj/locations/region/clusters/clust/instances/inst"},
9999
want: withDefaults(&proxy.Config{
100100
Port: 6000,
101101
}),
102102
},
103103
{
104104
desc: "using the port query param",
105-
args: []string{"proj:region:inst?port=6000"},
105+
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?port=6000"},
106106
want: withDefaults(&proxy.Config{
107107
Instances: []proxy.InstanceConnConfig{{
108108
Port: 6000,
@@ -111,28 +111,28 @@ func TestNewCommandArguments(t *testing.T) {
111111
},
112112
{
113113
desc: "using the token flag",
114-
args: []string{"--token", "MYCOOLTOKEN", "proj:region:inst"},
114+
args: []string{"--token", "MYCOOLTOKEN", "/projects/proj/locations/region/clusters/clust/instances/inst"},
115115
want: withDefaults(&proxy.Config{
116116
Token: "MYCOOLTOKEN",
117117
}),
118118
},
119119
{
120120
desc: "using the token (short) flag",
121-
args: []string{"-t", "MYCOOLTOKEN", "proj:region:inst"},
121+
args: []string{"-t", "MYCOOLTOKEN", "/projects/proj/locations/region/clusters/clust/instances/inst"},
122122
want: withDefaults(&proxy.Config{
123123
Token: "MYCOOLTOKEN",
124124
}),
125125
},
126126
{
127127
desc: "using the credentiale file flag",
128-
args: []string{"--credentials-file", "/path/to/file", "proj:region:inst"},
128+
args: []string{"--credentials-file", "/path/to/file", "/projects/proj/locations/region/clusters/clust/instances/inst"},
129129
want: withDefaults(&proxy.Config{
130130
CredentialsFile: "/path/to/file",
131131
}),
132132
},
133133
{
134134
desc: "using the (short) credentiale file flag",
135-
args: []string{"-c", "/path/to/file", "proj:region:inst"},
135+
args: []string{"-c", "/path/to/file", "/projects/proj/locations/region/clusters/clust/instances/inst"},
136136
want: withDefaults(&proxy.Config{
137137
CredentialsFile: "/path/to/file",
138138
}),
@@ -174,41 +174,41 @@ func TestNewCommandWithErrors(t *testing.T) {
174174
},
175175
{
176176
desc: "when the query string is bogus",
177-
args: []string{"proj:region:inst?%=foo"},
177+
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?%=foo"},
178178
},
179179
{
180180
desc: "when the address query param is empty",
181-
args: []string{"proj:region:inst?address="},
181+
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address="},
182182
},
183183
{
184184
desc: "using the address flag with a bad IP address",
185-
args: []string{"--address", "bogus", "proj:region:inst"},
185+
args: []string{"--address", "bogus", "/projects/proj/locations/region/clusters/clust/instances/inst"},
186186
},
187187
{
188188
desc: "when the address query param is not an IP address",
189-
args: []string{"proj:region:inst?address=世界"},
189+
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address=世界"},
190190
},
191191
{
192192
desc: "when the address query param contains multiple values",
193-
args: []string{"proj:region:inst?address=0.0.0.0&address=1.1.1.1&address=2.2.2.2"},
193+
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"},
194194
},
195195
{
196196
desc: "when the query string is invalid",
197-
args: []string{"proj:region:inst?address=1.1.1.1?foo=2.2.2.2"},
197+
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?address=1.1.1.1?foo=2.2.2.2"},
198198
},
199199
{
200200
desc: "when the port query param contains multiple values",
201-
args: []string{"proj:region:inst?port=1&port=2"},
201+
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?port=1&port=2"},
202202
},
203203
{
204204
desc: "when the port query param is not a number",
205-
args: []string{"proj:region:inst?port=hi"},
205+
args: []string{"/projects/proj/locations/region/clusters/clust/instances/inst?port=hi"},
206206
},
207207
{
208208
desc: "when both token and credentials file is set",
209209
args: []string{
210210
"--token", "my-token",
211-
"--credentials-file", "/path/to/file", "proj:region:inst"},
211+
"--credentials-file", "/path/to/file", "/projects/proj/locations/region/clusters/clust/instances/inst"},
212212
},
213213
}
214214

@@ -256,7 +256,7 @@ func (*spyDialer) Close() error {
256256
}
257257

258258
func TestCommandWithCustomDialer(t *testing.T) {
259-
want := "my-project:my-region:my-cluster:my-instance"
259+
want := "/projects/my-project/locations/my-region/clusters/my-cluster/instances/my-instance"
260260
s := &spyDialer{}
261261
c := NewCommand(WithDialer(s))
262262
// Keep the test output quiet

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/GoogleCloudPlatform/alloydb-auth-proxy
33
go 1.16
44

55
require (
6-
cloud.google.com/go/alloydbconn v0.0.0-0.20220401153611-87e713b37755
6+
cloud.google.com/go/alloydbconn v0.0.0-00010101000000-000000000000
77
github.com/google/go-cmp v0.5.7
88
github.com/lib/pq v1.10.5 // indirect
99
github.com/spf13/cobra v1.2.1

internal/proxy/proxy_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func (fakeDialer) Close() error {
3636

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

4242
tcs := []struct {
4343
desc string

vendor/modules.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# cloud.google.com/go/alloydbconn v0.0.0-0.20220401153611-87e713b37755 => ../alloydb-go-connector
1+
# cloud.google.com/go/alloydbconn v0.0.0-00010101000000-000000000000 => ../alloydb-go-connector
22
## explicit
33
cloud.google.com/go/alloydbconn
44
cloud.google.com/go/alloydbconn/driver/pgxv4

0 commit comments

Comments
 (0)