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

Commit9eeb506

Browse files
authored
feat: modify config-ssh to set the host suffix (#17280)
Wires up `config-ssh` command to use a hostname suffix if configured.part of:#16828e.g. `coder config-ssh --hostname-suffix spiketest` gives:```# ------------START-CODER-----------# This section is managed by coder. DO NOT EDIT.## You should not hand-edit this section unless you are removing it, all# changes will be lost when running "coder config-ssh".## Last config-ssh options:# :hostname-suffix=spiketest#Host coder.* *.spiketest ConnectTimeout=0 StrictHostKeyChecking=no UserKnownHostsFile=/dev/null LogLevel ERROR ProxyCommand /home/coder/repos/coder/build/coder_config_ssh --global-config /home/coder/.config/coderv2 ssh --stdio --ssh-host-prefix coder. --hostname-suffix spiketest %h# ------------END-CODER------------```
1 parent114ba45 commit9eeb506

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

‎cli/configssh.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,15 @@ func (r *RootCmd) configSSH() *serpent.Command {
356356
ifsshConfigOpts.disableAutostart {
357357
flags+=" --disable-autostart=true"
358358
}
359+
ifcoderdConfig.HostnamePrefix!="" {
360+
flags+=" --ssh-host-prefix "+coderdConfig.HostnamePrefix
361+
}
362+
ifcoderdConfig.HostnameSuffix!="" {
363+
flags+=" --hostname-suffix "+coderdConfig.HostnameSuffix
364+
}
359365
defaultOptions=append(defaultOptions,fmt.Sprintf(
360-
"ProxyCommand %s %s ssh --stdio%s--ssh-host-prefix %s%%h",
361-
escapedCoderBinary,rootFlags,flags,coderdConfig.HostnamePrefix,
366+
"ProxyCommand %s %s ssh --stdio%s %%h",
367+
escapedCoderBinary,rootFlags,flags,
362368
))
363369
}
364370

@@ -391,7 +397,7 @@ func (r *RootCmd) configSSH() *serpent.Command {
391397
}
392398

393399
hostBlock:= []string{
394-
"Host "+coderdConfig.HostnamePrefix+"*",
400+
sshConfigHostLinePatterns(coderdConfig),
395401
}
396402
// Prefix with '\t'
397403
for_,v:=rangeconfigOptions.sshOptions {
@@ -837,3 +843,19 @@ func diffBytes(name string, b1, b2 []byte, color bool) ([]byte, error) {
837843
}
838844
returnb,nil
839845
}
846+
847+
funcsshConfigHostLinePatterns(config codersdk.SSHConfigResponse)string {
848+
builder:= strings.Builder{}
849+
// by inspection, WriteString always returns nil error
850+
_,_=builder.WriteString("Host")
851+
ifconfig.HostnamePrefix!="" {
852+
_,_=builder.WriteString(" ")
853+
_,_=builder.WriteString(config.HostnamePrefix)
854+
_,_=builder.WriteString("*")
855+
}
856+
ifconfig.HostnameSuffix!="" {
857+
_,_=builder.WriteString(" *.")
858+
_,_=builder.WriteString(config.HostnameSuffix)
859+
}
860+
returnbuilder.String()
861+
}

‎cli/configssh_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,33 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
611611
regexMatch:"RemoteForward 2222 192.168.11.1:2222.*\n.*RemoteForward 2223 192.168.11.1:2223",
612612
},
613613
},
614+
{
615+
name:"Hostname Suffix",
616+
args: []string{
617+
"--yes",
618+
"--hostname-suffix","testy",
619+
},
620+
wantErr:false,
621+
hasAgent:true,
622+
wantConfig:wantConfig{
623+
ssh: []string{"Host coder.* *.testy"},
624+
regexMatch:`ProxyCommand .* ssh .* --hostname-suffix testy %h`,
625+
},
626+
},
627+
{
628+
name:"Hostname Prefix and Suffix",
629+
args: []string{
630+
"--yes",
631+
"--ssh-host-prefix","presto.",
632+
"--hostname-suffix","testy",
633+
},
634+
wantErr:false,
635+
hasAgent:true,
636+
wantConfig:wantConfig{
637+
ssh: []string{"Host presto.* *.testy"},
638+
regexMatch:`ProxyCommand .* ssh .* --ssh-host-prefix presto\. --hostname-suffix testy %h`,
639+
},
640+
},
614641
}
615642
for_,tt:=rangetests {
616643
tt:=tt

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp