Skip to content

Commit 59c5bc9

Browse files
authored
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.
1 parent 2424873 commit 59c5bc9

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

cli/configssh.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ const (
4545
// sshConfigOptions represents options that can be stored and read
4646
// from the coder config in ~/.ssh/coder.
4747
type sshConfigOptions struct {
48-
waitEnum string
48+
waitEnum string
49+
// Deprecated: moving away from prefix to hostnameSuffix
4950
userHostPrefix string
51+
hostnameSuffix string
5052
sshOptions []string
5153
disableAutostart bool
5254
header []string
@@ -97,7 +99,11 @@ func (o sshConfigOptions) equal(other sshConfigOptions) bool {
9799
if !slicesSortedEqual(o.header, other.header) {
98100
return false
99101
}
100-
return o.waitEnum == other.waitEnum && o.userHostPrefix == other.userHostPrefix && o.disableAutostart == other.disableAutostart && o.headerCommand == other.headerCommand
102+
return o.waitEnum == other.waitEnum &&
103+
o.userHostPrefix == other.userHostPrefix &&
104+
o.disableAutostart == other.disableAutostart &&
105+
o.headerCommand == other.headerCommand &&
106+
o.hostnameSuffix == other.hostnameSuffix
101107
}
102108

103109
// slicesSortedEqual compares two slices without side-effects or regard to order.
@@ -119,6 +125,9 @@ func (o sshConfigOptions) asList() (list []string) {
119125
if o.userHostPrefix != "" {
120126
list = append(list, fmt.Sprintf("ssh-host-prefix: %s", o.userHostPrefix))
121127
}
128+
if o.hostnameSuffix != "" {
129+
list = append(list, fmt.Sprintf("hostname-suffix: %s", o.hostnameSuffix))
130+
}
122131
if o.disableAutostart {
123132
list = append(list, fmt.Sprintf("disable-autostart: %v", o.disableAutostart))
124133
}
@@ -314,6 +323,10 @@ func (r *RootCmd) configSSH() *serpent.Command {
314323
// Override with user flag.
315324
coderdConfig.HostnamePrefix = sshConfigOpts.userHostPrefix
316325
}
326+
if sshConfigOpts.hostnameSuffix != "" {
327+
// Override with user flag.
328+
coderdConfig.HostnameSuffix = sshConfigOpts.hostnameSuffix
329+
}
317330

318331
// Write agent configuration.
319332
defaultOptions := []string{
@@ -518,6 +531,12 @@ func (r *RootCmd) configSSH() *serpent.Command {
518531
Description: "Override the default host prefix.",
519532
Value: serpent.StringOf(&sshConfigOpts.userHostPrefix),
520533
},
534+
{
535+
Flag: "hostname-suffix",
536+
Env: "CODER_CONFIGSSH_HOSTNAME_SUFFIX",
537+
Description: "Override the default hostname suffix.",
538+
Value: serpent.StringOf(&sshConfigOpts.hostnameSuffix),
539+
},
521540
{
522541
Flag: "wait",
523542
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
568587
if o.userHostPrefix != "" {
569588
_, _ = fmt.Fprintf(&ow, "# :%s=%s\n", "ssh-host-prefix", o.userHostPrefix)
570589
}
590+
if o.hostnameSuffix != "" {
591+
_, _ = fmt.Fprintf(&ow, "# :%s=%s\n", "hostname-suffix", o.hostnameSuffix)
592+
}
571593
if o.disableAutostart {
572594
_, _ = fmt.Fprintf(&ow, "# :%s=%v\n", "disable-autostart", o.disableAutostart)
573595
}
@@ -607,6 +629,8 @@ func sshConfigParseLastOptions(r io.Reader) (o sshConfigOptions) {
607629
o.waitEnum = parts[1]
608630
case "ssh-host-prefix":
609631
o.userHostPrefix = parts[1]
632+
case "hostname-suffix":
633+
o.hostnameSuffix = parts[1]
610634
case "ssh-option":
611635
o.sshOptions = append(o.sshOptions, parts[1])
612636
case "disable-autostart":

cli/configssh_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
432432
"# Last config-ssh options:",
433433
"# :wait=yes",
434434
"# :ssh-host-prefix=coder-test.",
435+
"# :hostname-suffix=coder-suffix",
435436
"# :header=X-Test-Header=foo",
436437
"# :header=X-Test-Header2=bar",
437438
"# :header-command=printf h1=v1 h2=\"v2\" h3='v3'",
@@ -447,6 +448,7 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
447448
"--yes",
448449
"--wait=yes",
449450
"--ssh-host-prefix", "coder-test.",
451+
"--hostname-suffix", "coder-suffix",
450452
"--header", "X-Test-Header=foo",
451453
"--header", "X-Test-Header2=bar",
452454
"--header-command", "printf h1=v1 h2=\"v2\" h3='v3'",

cli/testdata/coder_config-ssh_--help.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ OPTIONS:
3333
unix-like shell. This flag forces the use of unix file paths (the
3434
forward slash '/').
3535

36+
--hostname-suffix string, $CODER_CONFIGSSH_HOSTNAME_SUFFIX
37+
Override the default hostname suffix.
38+
3639
--ssh-config-file string, $CODER_SSH_CONFIG_FILE (default: ~/.ssh/config)
3740
Specifies the path to an SSH config.
3841

docs/reference/cli/config-ssh.md

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy