Skip to content

Commit a8346bd

Browse files
authored
feat: Allow unsetting ssh config options from deployment (#6847)
This allows deleting ssh config options
1 parent 1176256 commit a8346bd

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

cli/configssh.go

+12-3
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(option string) error {
65-
key, _, err := codersdk.ParseSSHConfigOption(option)
65+
key, value, err := codersdk.ParseSSHConfigOption(option)
6666
if err != nil {
6767
return err
6868
}
@@ -77,11 +77,20 @@ func (o *sshConfigOptions) addOption(option string) error {
7777
continue
7878
}
7979
if strings.EqualFold(existingKey, key) {
80-
o.sshOptions[i] = option
80+
if value == "" {
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
return nil
8288
}
8389
}
84-
o.sshOptions = append(o.sshOptions, option)
90+
// Only append the option if it is not empty.
91+
if value != "" {
92+
o.sshOptions = append(o.sshOptions, option)
93+
}
8594
return nil
8695
}
8796

cli/configssh_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ func TestConfigSSH(t *testing.T) {
6666

6767
const hostname = "test-coder."
6868
const expectedKey = "ConnectionAttempts"
69+
const removeKey = "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)