- Notifications
You must be signed in to change notification settings - Fork928
feat(cli): support header and header-command in config-ssh#10413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
42a7512
9a9ff38
57355fb
1220039
a785392
c5e0ec1
7fc1849
ed5e82b
1c585c4
bcdb129
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -19,6 +19,7 @@ import ( | ||
"github.com/cli/safeexec" | ||
"github.com/pkg/diff" | ||
"github.com/pkg/diff/write" | ||
"golang.org/x/exp/constraints" | ||
"golang.org/x/exp/slices" | ||
"golang.org/x/sync/errgroup" | ||
"golang.org/x/xerrors" | ||
@@ -51,6 +52,8 @@ type sshConfigOptions struct { | ||
userHostPrefix string | ||
sshOptions []string | ||
disableAutostart bool | ||
header []string | ||
headerCommand string | ||
} | ||
// addOptions expects options in the form of "option=value" or "option value". | ||
@@ -100,15 +103,25 @@ func (o *sshConfigOptions) addOption(option string) error { | ||
} | ||
func (o sshConfigOptions) equal(other sshConfigOptions) bool { | ||
if !slicesSortedEqual(o.sshOptions, other.sshOptions) { | ||
return false | ||
} | ||
if !slicesSortedEqual(o.header, other.header) { | ||
return false | ||
} | ||
return o.waitEnum == other.waitEnum && o.userHostPrefix == other.userHostPrefix && o.disableAutostart == other.disableAutostart && o.headerCommand == other.headerCommand | ||
} | ||
// slicesSortedEqual compares two slices without side-effects or regard to order. | ||
func slicesSortedEqual[S ~[]E, E constraints.Ordered](a, b S) bool { | ||
if len(a) != len(b) { | ||
return false | ||
} | ||
a = slices.Clone(a) | ||
slices.Sort(a) | ||
b = slices.Clone(b) | ||
slices.Sort(b) | ||
Comment on lines +120 to +123 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nit: curious, can we replace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
It's actually just a simple copy, so I think it's fine. | ||
return slices.Equal(a, b) | ||
} | ||
func (o sshConfigOptions) asList() (list []string) { | ||
@@ -124,6 +137,13 @@ func (o sshConfigOptions) asList() (list []string) { | ||
for _, opt := range o.sshOptions { | ||
list = append(list, fmt.Sprintf("ssh-option: %s", opt)) | ||
} | ||
for _, h := range o.header { | ||
list = append(list, fmt.Sprintf("header: %s", h)) | ||
} | ||
if o.headerCommand != "" { | ||
list = append(list, fmt.Sprintf("header-command: %s", o.headerCommand)) | ||
} | ||
return list | ||
} | ||
@@ -230,6 +250,8 @@ func (r *RootCmd) configSSH() *clibase.Cmd { | ||
// specifies skip-proxy-command, then wait cannot be applied. | ||
return xerrors.Errorf("cannot specify both --skip-proxy-command and --wait") | ||
} | ||
sshConfigOpts.header = r.header | ||
sshConfigOpts.headerCommand = r.headerCommand | ||
recvWorkspaceConfigs := sshPrepareWorkspaceConfigs(inv.Context(), client) | ||
@@ -393,6 +415,14 @@ func (r *RootCmd) configSSH() *clibase.Cmd { | ||
} | ||
if !skipProxyCommand { | ||
rootFlags := fmt.Sprintf("--global-config %s", escapedGlobalConfig) | ||
for _, h := range sshConfigOpts.header { | ||
rootFlags += fmt.Sprintf(" --header %q", h) | ||
} | ||
if sshConfigOpts.headerCommand != "" { | ||
rootFlags += fmt.Sprintf(" --header-command %q", sshConfigOpts.headerCommand) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Review: We shouldn't need to do special escaping here like we do for the coder binary, that's because we're simply passing a string argument to coder. | ||
} | ||
flags := "" | ||
if sshConfigOpts.waitEnum != "auto" { | ||
flags += " --wait=" + sshConfigOpts.waitEnum | ||
@@ -401,8 +431,8 @@ func (r *RootCmd) configSSH() *clibase.Cmd { | ||
flags += " --disable-autostart=true" | ||
} | ||
defaultOptions = append(defaultOptions, fmt.Sprintf( | ||
"ProxyCommand %s %s ssh --stdio%s %s", | ||
escapedCoderBinary,rootFlags, flags, workspaceHostname, | ||
)) | ||
} | ||
@@ -623,6 +653,12 @@ func sshConfigWriteSectionHeader(w io.Writer, addNewline bool, o sshConfigOption | ||
for _, opt := range o.sshOptions { | ||
_, _ = fmt.Fprintf(&ow, "# :%s=%s\n", "ssh-option", opt) | ||
} | ||
for _, h := range o.header { | ||
_, _ = fmt.Fprintf(&ow, "# :%s=%s\n", "header", h) | ||
} | ||
if o.headerCommand != "" { | ||
_, _ = fmt.Fprintf(&ow, "# :%s=%s\n", "header-command", o.headerCommand) | ||
} | ||
if ow.Len() > 0 { | ||
_, _ = fmt.Fprint(w, sshConfigOptionsHeader) | ||
_, _ = fmt.Fprint(w, ow.String()) | ||
@@ -654,6 +690,10 @@ func sshConfigParseLastOptions(r io.Reader) (o sshConfigOptions) { | ||
o.sshOptions = append(o.sshOptions, parts[1]) | ||
case "disable-autostart": | ||
o.disableAutostart, _ = strconv.ParseBool(parts[1]) | ||
case "header": | ||
o.header = append(o.header, parts[1]) | ||
case "header-command": | ||
o.headerCommand = parts[1] | ||
default: | ||
// Unknown option, ignore. | ||
} | ||