Skip to content

Commit

Permalink
fix(ssh-args): space inside quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorres committed May 23, 2024
1 parent 4fb2872 commit fd3069c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 8 additions & 4 deletions pkg/options/options_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ var _ = Describe("Test parsing SSHArgs", func() {
[]string{"arg1", "arg2", "arg3"},
),
Entry("not split by whitespace inside quotes",
"arg1 arg2 ProxyCommand=\"cmd\"",
[]string{"arg1", "arg2", "ProxyCommand=\"cmd\""},
"arg1 arg2 ProxyCommand=\\\"arg1 arg2\\\"",
[]string{"arg1", "arg2", "ProxyCommand=\"arg1 arg2\""},
),
Entry("not split by comma",
"arg1,arg2 ProxyCommand=\"cmd\"",
[]string{"arg1,arg2", "ProxyCommand=\"cmd\""},
"arg1,arg2",
[]string{"arg1,arg2"},
),
Entry("real world example",
"ssh -i ~/yandex -o ProxyCommand=\\\"ssh -W %h:%p -i ~/yandex [email protected]\\\"",
[]string{"ssh", "-i", "~/yandex", "-o", "ProxyCommand=\"ssh -W %h:%p -i ~/yandex [email protected]\""},
),
)
})
8 changes: 5 additions & 3 deletions pkg/options/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ func (o *RestartOptions) DefineFlags(fs *pflag.FlagSet) {
fs.StringVar(&rawSSHUnparsedArgs, "ssh-args", "",
`This argument will be used when ssh-ing to the nodes. It may be used to override
the ssh command itself, ssh username or any additional arguments.
E.g.:
--ssh-args=pssh,-A,-J,<some jump host>,--yc-profile,<YC profile name>`)
Double quotes are can be escaped with backward slash '\'.
Examples:
1) --ssh-args "pssh -A -J <some jump host> --yc-profile <YC profile name>"
2) --ssh-args "ssh -o ProxyCommand=\"...\""`)

fs.StringSliceVar(&o.Hosts, "hosts", o.Hosts,
`Restart only specified hosts. You can specify a list of host FQDNs or a list of node ids,
Expand Down Expand Up @@ -275,7 +277,7 @@ func parseSSHArgs(rawArgs string) []string {
continue
}

if unicode.IsSpace(rawRunes[i]) {
if unicode.IsSpace(rawRunes[i]) && !isInsideQuotes {
if len(curArg) > 0 {
args = append(args, string(curArg))
}
Expand Down

0 comments on commit fd3069c

Please sign in to comment.