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

fix: create ssh directory if it doesn't already exist when runningcoder config-ssh#17711

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
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
5 changes: 5 additions & 0 deletionscli/configssh.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -440,6 +440,11 @@ func (r *RootCmd) configSSH() *serpent.Command {
}

if !bytes.Equal(configRaw, configModified) {
sshDir := filepath.Dir(sshConfigFile)
if err := os.MkdirAll(sshDir, 0700); err != nil {
return xerrors.Errorf("failed to create directory %q: %w", sshDir, err)
}

err = atomic.WriteFile(sshConfigFile, bytes.NewReader(configModified))
if err != nil {
return xerrors.Errorf("write ssh config failed: %w", err)
Expand Down
41 changes: 41 additions & 0 deletionscli/configssh_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -169,6 +169,47 @@ func TestConfigSSH(t *testing.T) {
<-copyDone
}

func TestConfigSSH_MissingDirectory(t *testing.T) {
t.Parallel()

if runtime.GOOS == "windows" {
t.Skip("See coder/internal#117")
}

client := coderdtest.New(t, nil)
_ = coderdtest.CreateFirstUser(t, client)

// Create a temporary directory but don't create .ssh subdirectory
tmpdir := t.TempDir()
sshConfigPath := filepath.Join(tmpdir, ".ssh", "config")

// Run config-ssh with a non-existent .ssh directory
args := []string{
"config-ssh",
"--ssh-config-file", sshConfigPath,
"--yes", // Skip confirmation prompts
}
inv, root := clitest.New(t, args...)
clitest.SetupConfig(t, client, root)

err := inv.Run()
require.NoError(t, err, "config-ssh should succeed with non-existent directory")

// Verify that the .ssh directory was created
sshDir := filepath.Dir(sshConfigPath)
_, err = os.Stat(sshDir)
require.NoError(t, err, ".ssh directory should exist")

// Verify that the config file was created
_, err = os.Stat(sshConfigPath)
require.NoError(t, err, "config file should exist")

// Check that the directory has proper permissions (0700)
sshDirInfo, err := os.Stat(sshDir)
require.NoError(t, err)
require.Equal(t, os.FileMode(0700), sshDirInfo.Mode().Perm(), "directory should have 0700 permissions")
}

func TestConfigSSH_FileWriteAndOptionsFlow(t *testing.T) {
t.Parallel()

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp