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

Commitb5ff7b8

Browse files
committed
feat: modify config-ssh to set the host suffix
1 parentd312e82 commitb5ff7b8

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,18 @@ 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+
regexMatch:`ProxyCommand .* ssh .* --hostname-suffix testy %h`,
624+
},
625+
},
614626
}
615627
for_,tt:=rangetests {
616628
tt:=tt

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp