mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add --ssh-host-prefix flag for "coder ssh" (#16088)
This adds a flag matching `--ssh-host-prefix` from `coder config-ssh` to `coder ssh`. By trimming a custom prefix from the argument, we can set up wildcard-based `Host` entries in SSH config for the IDE plugins (and eventually `coder config-ssh`). We also replace `--` in the argument with `/`, so ownership can be specified in wildcard-based SSH hosts like `<owner>--<workspace>`. Replaces #16087. Part of https://github.com/coder/coder/issues/14986. Related to https://github.com/coder/coder/pull/16078 and https://github.com/coder/coder/pull/16080.
This commit is contained in:
+12
-1
@@ -61,6 +61,7 @@ var (
|
||||
func (r *RootCmd) ssh() *serpent.Command {
|
||||
var (
|
||||
stdio bool
|
||||
hostPrefix string
|
||||
forwardAgent bool
|
||||
forwardGPG bool
|
||||
identityAgent string
|
||||
@@ -195,7 +196,11 @@ func (r *RootCmd) ssh() *serpent.Command {
|
||||
parsedEnv = append(parsedEnv, [2]string{k, v})
|
||||
}
|
||||
|
||||
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, inv.Args[0])
|
||||
namedWorkspace := strings.TrimPrefix(inv.Args[0], hostPrefix)
|
||||
// Support "--" as a delimiter between owner and workspace name
|
||||
namedWorkspace = strings.Replace(namedWorkspace, "--", "/", 1)
|
||||
|
||||
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, namedWorkspace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -509,6 +514,12 @@ func (r *RootCmd) ssh() *serpent.Command {
|
||||
Description: "Specifies whether to emit SSH output over stdin/stdout.",
|
||||
Value: serpent.BoolOf(&stdio),
|
||||
},
|
||||
{
|
||||
Flag: "ssh-host-prefix",
|
||||
Env: "CODER_SSH_SSH_HOST_PREFIX",
|
||||
Description: "Strip this prefix from the provided hostname to determine the workspace name. This is useful when used as part of an OpenSSH proxy command.",
|
||||
Value: serpent.StringOf(&hostPrefix),
|
||||
},
|
||||
{
|
||||
Flag: "forward-agent",
|
||||
FlagShorthand: "A",
|
||||
|
||||
Reference in New Issue
Block a user