Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit59c5bc9

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 parent2424873 commit59c5bc9

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
typesshConfigOptionsstruct {
48-
waitEnumstring
48+
waitEnumstring
49+
// Deprecated: moving away from prefix to hostnameSuffix
4950
userHostPrefixstring
51+
hostnameSuffixstring
5052
sshOptions []string
5153
disableAutostartbool
5254
header []string
@@ -97,7 +99,11 @@ func (o sshConfigOptions) equal(other sshConfigOptions) bool {
9799
if!slicesSortedEqual(o.header,other.header) {
98100
returnfalse
99101
}
100-
returno.waitEnum==other.waitEnum&&o.userHostPrefix==other.userHostPrefix&&o.disableAutostart==other.disableAutostart&&o.headerCommand==other.headerCommand
102+
returno.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
ifo.userHostPrefix!="" {
120126
list=append(list,fmt.Sprintf("ssh-host-prefix: %s",o.userHostPrefix))
121127
}
128+
ifo.hostnameSuffix!="" {
129+
list=append(list,fmt.Sprintf("hostname-suffix: %s",o.hostnameSuffix))
130+
}
122131
ifo.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+
ifsshConfigOpts.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
ifo.userHostPrefix!="" {
569588
_,_=fmt.Fprintf(&ow,"# :%s=%s\n","ssh-host-prefix",o.userHostPrefix)
570589
}
590+
ifo.hostnameSuffix!="" {
591+
_,_=fmt.Fprintf(&ow,"# :%s=%s\n","hostname-suffix",o.hostnameSuffix)
592+
}
571593
ifo.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 aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp