Skip to content

Commit

Permalink
feat: parse unix-socket-path cli argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
hessjcg committed Jan 25, 2023
1 parent 97c8432 commit d15e7f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,23 @@ func parseConfig(cmd *Command, conf *proxy.Config, args []string) error {
a, aok := q["address"]
p, pok := q["port"]
u, uok := q["unix-socket"]
up, upok := q["unix-socket-path"]

if aok && uok {
return newBadCommandError("cannot specify both address and unix-socket query params")
}
if pok && uok {
return newBadCommandError("cannot specify both port and unix-socket query params")
}
if aok && upok {
return newBadCommandError("cannot specify both address and unix-socket-path query params")
}
if pok && upok {
return newBadCommandError("cannot specify both port and unix-socket-path query params")
}
if uok && upok {
return newBadCommandError("cannot specify both unix-socket-path and unix-socket query params")
}

if aok {
if len(a) != 1 {
Expand Down Expand Up @@ -585,6 +595,13 @@ func parseConfig(cmd *Command, conf *proxy.Config, args []string) error {
ic.UnixSocket = u[0]
}

if upok {
if len(up) != 1 {
return newBadCommandError(fmt.Sprintf("unix-socket-path query param should be only one value: %q", a))
}
ic.UnixSocketPath = up[0]
}

ic.IAMAuthN, err = parseBoolOpt(q, "auto-iam-authn")
if err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ func TestNewCommandArguments(t *testing.T) {
}},
}),
},
{
desc: "using the unix socket path query param",
args: []string{"proj:region:inst?unix-socket-path=/path/to/dir/"},
want: withDefaults(&proxy.Config{
Instances: []proxy.InstanceConnConfig{{
UnixSocketPath: "/path/to/dir/",
}},
}),
},
{
desc: "using the iam authn login flag",
args: []string{"--auto-iam-authn", "proj:region:inst"},
Expand Down

0 comments on commit d15e7f2

Please sign in to comment.