Skip to content

Commit 588eed5

Browse files
committed
fix importer
1 parent 3798c07 commit 588eed5

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

internal/deploy/ssh.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,36 +71,32 @@ func NewDeployer(host, user, privateKey string) (*Deployer, error) {
7171
// for deployment and auditing with a Keymaster system key.
7272
if privateKey != "" {
7373
signer, err := ssh.ParsePrivateKey([]byte(privateKey))
74-
if err != nil {
75-
return nil, fmt.Errorf("unable to parse private key: %w", err)
76-
}
77-
78-
config := &ssh.ClientConfig{
79-
User: user,
80-
Auth: []ssh.AuthMethod{ssh.PublicKeys(signer)},
81-
HostKeyCallback: hostKeyCallback,
82-
Timeout: 10 * time.Second,
83-
}
84-
client, err = ssh.Dial("tcp", addr, config)
8574
if err == nil {
86-
// Success! We connected with the system key.
87-
sftpClient, sftpErr := sftp.NewClient(client)
88-
if sftpErr != nil {
89-
client.Close()
90-
return nil, fmt.Errorf("failed to create sftp client: %w", sftpErr)
75+
config := &ssh.ClientConfig{
76+
User: user,
77+
Auth: []ssh.AuthMethod{ssh.PublicKeys(signer)},
78+
HostKeyCallback: hostKeyCallback,
79+
Timeout: 10 * time.Second,
80+
}
81+
client, err = ssh.Dial("tcp", addr, config)
82+
if err == nil {
83+
// Success! We connected with the system key.
84+
sftpClient, sftpErr := sftp.NewClient(client)
85+
if sftpErr != nil {
86+
client.Close()
87+
return nil, fmt.Errorf("failed to create sftp client: %w", sftpErr)
88+
}
89+
return &Deployer{client: client, sftp: sftpClient}, nil
9190
}
92-
return &Deployer{client: client, sftp: sftpClient}, nil
91+
// If we provided a key and it failed, we will fall through to try the agent.
9392
}
94-
// If we provided a key and it failed, we return the error immediately
95-
// without falling back to the agent.
96-
return nil, fmt.Errorf("connection with system key failed: %w", err)
9793
}
9894

9995
// If no private key was provided, attempt to use the SSH agent.
10096
// This is used for bootstrapping/importing keys.
10197
agentClient := getSSHAgent()
10298
if agentClient == nil {
103-
return nil, fmt.Errorf("no authentication method available (no system key provided and no ssh agent found)")
99+
return nil, fmt.Errorf("no authentication method available (system key failed and no ssh agent found)")
104100
}
105101

106102
config := &ssh.ClientConfig{

0 commit comments

Comments
 (0)