Skip to content

feat: add custom coder bin path for ProxyCommand #8425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add custom coder bin path for ProxyCommand
  • Loading branch information
Emyrk committed Jul 11, 2023
commit 252f4f3892d2d45a7f21dc4792dfecf9f9c7d816
21 changes: 18 additions & 3 deletions cli/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func (r *RootCmd) configSSH() *clibase.Cmd {
dryRun bool
skipProxyCommand bool
forceUnixSeparators bool
coderCliPath string
)
client := new(codersdk.Client)
cmd := &clibase.Cmd{
Expand Down Expand Up @@ -233,10 +234,16 @@ func (r *RootCmd) configSSH() *clibase.Cmd {
// that it's possible to capture the diff.
out = inv.Stderr
}
coderBinary, err := currentBinPath(out)
if err != nil {
return err

var err error
coderBinary := coderCliPath
if coderBinary == "" {
coderBinary, err = currentBinPath(out)
if err != nil {
return err
}
}

escapedCoderBinary, err := sshConfigExecEscape(coderBinary, forceUnixSeparators)
if err != nil {
return xerrors.Errorf("escape coder binary for ssh failed: %w", err)
Expand Down Expand Up @@ -501,6 +508,14 @@ func (r *RootCmd) configSSH() *clibase.Cmd {
Description: "Specifies the path to an SSH config.",
Value: clibase.StringOf(&sshConfigFile),
},
{
Flag: "coder-cli-path",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just using binary-path (without prefix)? I feel like cli terminology isn't something we expose the users to in association with the coder command, and may cause a disconnect.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I was trying to make clear in the flag was this was the coder binary path, not anything else like the ssh binary.

Is coder-binary-path too long?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, not too long IMO, your reasoning makes sense 👍🏻

Env: "CODER_SSH_CONFIG_CLI_PATH",
Default: "",
Description: "Optional to specify the path for the coder cli uses in ProxyCommand. " +
"By default, the coder cli used is the same cli being invoked with 'config ssh'.",
Value: clibase.StringOf(&coderCliPath),
},
{
Flag: "ssh-option",
FlagShorthand: "o",
Expand Down
41 changes: 31 additions & 10 deletions cli/configssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,20 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
ssh string
}
type wantConfig struct {
ssh string
ssh string
regexMatch string
}
type match struct {
match, write string
}
tests := []struct {
name string
args []string
matches []match
writeConfig writeConfig
wantConfig wantConfig
wantErr bool
name string
args []string
matches []match
writeConfig writeConfig
wantConfig wantConfig
wantErr bool
echoResponse *echo.Responses
}{
{
name: "Config file is created",
Expand Down Expand Up @@ -579,6 +581,20 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
},
wantErr: true,
},
{
name: "Custom CLI Path",
args: []string{
"-y", "--coder-cli-path", "/foo/bar/coder",
},
wantErr: false,
echoResponse: &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: echo.ProvisionApplyWithAgent(""),
},
wantConfig: wantConfig{
regexMatch: "ProxyCommand /foo/bar/coder",
},
},
}
for _, tt := range tests {
tt := tt
Expand All @@ -588,7 +604,7 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
var (
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user = coderdtest.CreateFirstUser(t, client)
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, tt.echoResponse)
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
project = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, project.ID)
Expand Down Expand Up @@ -627,9 +643,14 @@ func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {

<-done

if tt.wantConfig.ssh != "" {
if tt.wantConfig.ssh != "" || tt.wantConfig.regexMatch != "" {
got := sshConfigFileRead(t, sshConfigName)
assert.Equal(t, tt.wantConfig.ssh, got)
if tt.wantConfig.ssh != "" {
assert.Equal(t, tt.wantConfig.ssh, got)
}
if tt.wantConfig.regexMatch != "" {
assert.Regexp(t, tt.wantConfig.regexMatch, got, "regex match")
}
}
})
}
Expand Down