mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
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.
This commit is contained in:
+26
-2
@@ -45,8 +45,10 @@ const (
|
||||
// sshConfigOptions represents options that can be stored and read
|
||||
// from the coder config in ~/.ssh/coder.
|
||||
type sshConfigOptions struct {
|
||||
waitEnum string
|
||||
waitEnum string
|
||||
// Deprecated: moving away from prefix to hostnameSuffix
|
||||
userHostPrefix string
|
||||
hostnameSuffix string
|
||||
sshOptions []string
|
||||
disableAutostart bool
|
||||
header []string
|
||||
@@ -97,7 +99,11 @@ func (o sshConfigOptions) equal(other sshConfigOptions) bool {
|
||||
if !slicesSortedEqual(o.header, other.header) {
|
||||
return false
|
||||
}
|
||||
return o.waitEnum == other.waitEnum && o.userHostPrefix == other.userHostPrefix && o.disableAutostart == other.disableAutostart && o.headerCommand == other.headerCommand
|
||||
return o.waitEnum == other.waitEnum &&
|
||||
o.userHostPrefix == other.userHostPrefix &&
|
||||
o.disableAutostart == other.disableAutostart &&
|
||||
o.headerCommand == other.headerCommand &&
|
||||
o.hostnameSuffix == other.hostnameSuffix
|
||||
}
|
||||
|
||||
// slicesSortedEqual compares two slices without side-effects or regard to order.
|
||||
@@ -119,6 +125,9 @@ func (o sshConfigOptions) asList() (list []string) {
|
||||
if o.userHostPrefix != "" {
|
||||
list = append(list, fmt.Sprintf("ssh-host-prefix: %s", o.userHostPrefix))
|
||||
}
|
||||
if o.hostnameSuffix != "" {
|
||||
list = append(list, fmt.Sprintf("hostname-suffix: %s", o.hostnameSuffix))
|
||||
}
|
||||
if o.disableAutostart {
|
||||
list = append(list, fmt.Sprintf("disable-autostart: %v", o.disableAutostart))
|
||||
}
|
||||
@@ -314,6 +323,10 @@ func (r *RootCmd) configSSH() *serpent.Command {
|
||||
// Override with user flag.
|
||||
coderdConfig.HostnamePrefix = sshConfigOpts.userHostPrefix
|
||||
}
|
||||
if sshConfigOpts.hostnameSuffix != "" {
|
||||
// Override with user flag.
|
||||
coderdConfig.HostnameSuffix = sshConfigOpts.hostnameSuffix
|
||||
}
|
||||
|
||||
// Write agent configuration.
|
||||
defaultOptions := []string{
|
||||
@@ -518,6 +531,12 @@ func (r *RootCmd) configSSH() *serpent.Command {
|
||||
Description: "Override the default host prefix.",
|
||||
Value: serpent.StringOf(&sshConfigOpts.userHostPrefix),
|
||||
},
|
||||
{
|
||||
Flag: "hostname-suffix",
|
||||
Env: "CODER_CONFIGSSH_HOSTNAME_SUFFIX",
|
||||
Description: "Override the default hostname suffix.",
|
||||
Value: serpent.StringOf(&sshConfigOpts.hostnameSuffix),
|
||||
},
|
||||
{
|
||||
Flag: "wait",
|
||||
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
|
||||
if o.userHostPrefix != "" {
|
||||
_, _ = fmt.Fprintf(&ow, "# :%s=%s\n", "ssh-host-prefix", o.userHostPrefix)
|
||||
}
|
||||
if o.hostnameSuffix != "" {
|
||||
_, _ = fmt.Fprintf(&ow, "# :%s=%s\n", "hostname-suffix", o.hostnameSuffix)
|
||||
}
|
||||
if o.disableAutostart {
|
||||
_, _ = fmt.Fprintf(&ow, "# :%s=%v\n", "disable-autostart", o.disableAutostart)
|
||||
}
|
||||
@@ -607,6 +629,8 @@ func sshConfigParseLastOptions(r io.Reader) (o sshConfigOptions) {
|
||||
o.waitEnum = parts[1]
|
||||
case "ssh-host-prefix":
|
||||
o.userHostPrefix = parts[1]
|
||||
case "hostname-suffix":
|
||||
o.hostnameSuffix = parts[1]
|
||||
case "ssh-option":
|
||||
o.sshOptions = append(o.sshOptions, parts[1])
|
||||
case "disable-autostart":
|
||||
|
||||
Reference in New Issue
Block a user