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

Commita8346bd

Browse files
authored
feat: Allow unsetting ssh config options from deployment (#6847)
This allows deleting ssh config options
1 parent1176256 commita8346bd

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

‎cli/configssh.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (o *sshConfigOptions) addOptions(options ...string) error {
6262
}
6363

6464
func (o*sshConfigOptions)addOption(optionstring)error {
65-
key,_,err:=codersdk.ParseSSHConfigOption(option)
65+
key,value,err:=codersdk.ParseSSHConfigOption(option)
6666
iferr!=nil {
6767
returnerr
6868
}
@@ -77,11 +77,20 @@ func (o *sshConfigOptions) addOption(option string) error {
7777
continue
7878
}
7979
ifstrings.EqualFold(existingKey,key) {
80-
o.sshOptions[i]=option
80+
ifvalue=="" {
81+
// Delete existing option.
82+
o.sshOptions=append(o.sshOptions[:i],o.sshOptions[i+1:]...)
83+
}else {
84+
// Override existing option.
85+
o.sshOptions[i]=option
86+
}
8187
returnnil
8288
}
8389
}
84-
o.sshOptions=append(o.sshOptions,option)
90+
// Only append the option if it is not empty.
91+
ifvalue!="" {
92+
o.sshOptions=append(o.sshOptions,option)
93+
}
8594
returnnil
8695
}
8796

‎cli/configssh_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ func TestConfigSSH(t *testing.T) {
6666

6767
consthostname="test-coder."
6868
constexpectedKey="ConnectionAttempts"
69+
constremoveKey="ConnectionTimeout"
6970
client:=coderdtest.New(t,&coderdtest.Options{
7071
IncludeProvisionerDaemon:true,
7172
ConfigSSH: codersdk.SSHConfigResponse{
7273
HostnamePrefix:hostname,
7374
SSHConfigOptions:map[string]string{
7475
// Something we can test for
7576
expectedKey:"3",
77+
removeKey:"",
7678
},
7779
},
7880
})
@@ -176,6 +178,7 @@ func TestConfigSSH(t *testing.T) {
176178
fileContents,err:=os.ReadFile(sshConfigFile)
177179
require.NoError(t,err,"read ssh config file")
178180
require.Contains(t,string(fileContents),expectedKey,"ssh config file contains expected key")
181+
require.NotContains(t,string(fileContents),removeKey,"ssh config file should not have removed key")
179182

180183
home:=filepath.Dir(filepath.Dir(sshConfigFile))
181184
// #nosec

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp