mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
feat: add hostname-suffix option to config-ssh (#17270)
Adds `hostname-suffix` as a Config SSH option that we get from Coderd, and also accept via a CLI flag. It doesn't actually do anything with this value --- that's for PRs up the stack, since we need the `coder ssh` command to be updated to understand the suffix first.
This commit is contained in:
@ -45,8 +45,10 @@ const (
|
||||
// sshConfigOptions represents options that can be stored and read
|
||||
// from the coder config in ~/.ssh/coder.
|
||||
type sshConfigOptions struct {
|
||||
waitEnum string
|
||||
waitEnum string
|
||||
// Deprecated: moving away from prefix to hostnameSuffix
|
||||
userHostPrefix string
|
||||
hostnameSuffix string
|
||||
sshOptions []string
|
||||
disableAutostart bool
|
||||
header []string
|
||||
@ -97,7 +99,11 @@ func (o sshConfigOptions) equal(other sshConfigOptions) bool {
|
||||
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
|
||||
return o.waitEnum == other.waitEnum &&
|
||||
o.userHostPrefix == other.userHostPrefix &&
|
||||
o.disableAutostart == other.disableAutostart &&
|
||||
o.headerCommand == other.headerCommand &&
|
||||
o.hostnameSuffix == other.hostnameSuffix
|
||||
}
|
||||
|
||||
// slicesSortedEqual compares two slices without side-effects or regard to order.
|
||||
@ -119,6 +125,9 @@ func (o sshConfigOptions) asList() (list []string) {
|
||||
if o.userHostPrefix != "" {
|
||||
list = append(list, fmt.Sprintf("ssh-host-prefix: %s", o.userHostPrefix))
|
||||
}
|
||||
if o.hostnameSuffix != "" {
|
||||
list = append(list, fmt.Sprintf("hostname-suffix: %s", o.hostnameSuffix))
|
||||
}
|
||||
if o.disableAutostart {
|
||||
list = append(list, fmt.Sprintf("disable-autostart: %v", o.disableAutostart))
|
||||
}
|
||||
@ -314,6 +323,10 @@ func (r *RootCmd) configSSH() *serpent.Command {
|
||||
// Override with user flag.
|
||||
coderdConfig.HostnamePrefix = sshConfigOpts.userHostPrefix
|
||||
}
|
||||
if sshConfigOpts.hostnameSuffix != "" {
|
||||
// Override with user flag.
|
||||
coderdConfig.HostnameSuffix = sshConfigOpts.hostnameSuffix
|
||||
}
|
||||
|
||||
// Write agent configuration.
|
||||
defaultOptions := []string{
|
||||
@ -518,6 +531,12 @@ func (r *RootCmd) configSSH() *serpent.Command {
|
||||
Description: "Override the default host prefix.",
|
||||
Value: serpent.StringOf(&sshConfigOpts.userHostPrefix),
|
||||
},
|
||||
{
|
||||
Flag: "hostname-suffix",
|
||||
Env: "CODER_CONFIGSSH_HOSTNAME_SUFFIX",
|
||||
Description: "Override the default hostname suffix.",
|
||||
Value: serpent.StringOf(&sshConfigOpts.hostnameSuffix),
|
||||
},
|
||||
{
|
||||
Flag: "wait",
|
||||
Env: "CODER_CONFIGSSH_WAIT", // Not to be mixed with CODER_SSH_WAIT.
|
||||
@ -568,6 +587,9 @@ func sshConfigWriteSectionHeader(w io.Writer, addNewline bool, o sshConfigOption
|
||||
if o.userHostPrefix != "" {
|
||||
_, _ = fmt.Fprintf(&ow, "# :%s=%s\n", "ssh-host-prefix", o.userHostPrefix)
|
||||
}
|
||||
if o.hostnameSuffix != "" {
|
||||
_, _ = fmt.Fprintf(&ow, "# :%s=%s\n", "hostname-suffix", o.hostnameSuffix)
|
||||
}
|
||||
if o.disableAutostart {
|
||||
_, _ = fmt.Fprintf(&ow, "# :%s=%v\n", "disable-autostart", o.disableAutostart)
|
||||
}
|
||||
@ -607,6 +629,8 @@ func sshConfigParseLastOptions(r io.Reader) (o sshConfigOptions) {
|
||||
o.waitEnum = parts[1]
|
||||
case "ssh-host-prefix":
|
||||
o.userHostPrefix = parts[1]
|
||||
case "hostname-suffix":
|
||||
o.hostnameSuffix = parts[1]
|
||||
case "ssh-option":
|
||||
o.sshOptions = append(o.sshOptions, parts[1])
|
||||
case "disable-autostart":
|
||||
|
@ -432,6 +432,7 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
|
||||
"# Last config-ssh options:",
|
||||
"# :wait=yes",
|
||||
"# :ssh-host-prefix=coder-test.",
|
||||
"# :hostname-suffix=coder-suffix",
|
||||
"# :header=X-Test-Header=foo",
|
||||
"# :header=X-Test-Header2=bar",
|
||||
"# :header-command=printf h1=v1 h2=\"v2\" h3='v3'",
|
||||
@ -447,6 +448,7 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
|
||||
"--yes",
|
||||
"--wait=yes",
|
||||
"--ssh-host-prefix", "coder-test.",
|
||||
"--hostname-suffix", "coder-suffix",
|
||||
"--header", "X-Test-Header=foo",
|
||||
"--header", "X-Test-Header2=bar",
|
||||
"--header-command", "printf h1=v1 h2=\"v2\" h3='v3'",
|
||||
|
3
cli/testdata/coder_config-ssh_--help.golden
vendored
3
cli/testdata/coder_config-ssh_--help.golden
vendored
@ -33,6 +33,9 @@ OPTIONS:
|
||||
unix-like shell. This flag forces the use of unix file paths (the
|
||||
forward slash '/').
|
||||
|
||||
--hostname-suffix string, $CODER_CONFIGSSH_HOSTNAME_SUFFIX
|
||||
Override the default hostname suffix.
|
||||
|
||||
--ssh-config-file string, $CODER_SSH_CONFIG_FILE (default: ~/.ssh/config)
|
||||
Specifies the path to an SSH config.
|
||||
|
||||
|
9
docs/reference/cli/config-ssh.md
generated
9
docs/reference/cli/config-ssh.md
generated
@ -79,6 +79,15 @@ Specifies whether or not to keep options from previous run of config-ssh.
|
||||
|
||||
Override the default host prefix.
|
||||
|
||||
### --hostname-suffix
|
||||
|
||||
| | |
|
||||
|-------------|-----------------------------------------------|
|
||||
| Type | <code>string</code> |
|
||||
| Environment | <code>$CODER_CONFIGSSH_HOSTNAME_SUFFIX</code> |
|
||||
|
||||
Override the default hostname suffix.
|
||||
|
||||
### --wait
|
||||
|
||||
| | |
|
||||
|
Reference in New Issue
Block a user