getSSHAuth gets the ssh.Signer needed to connect via SSH
(sshKeyPath string)
| 273 | |
| 274 | // getSSHAuth gets the ssh.Signer needed to connect via SSH |
| 275 | func getSSHAuth(sshKeyPath string) (ssh.Signer, error) { |
| 276 | f, err := os.Open(sshKeyPath) |
| 277 | if err != nil { |
| 278 | return nil, err |
| 279 | } |
| 280 | defer func() { _ = f.Close() }() |
| 281 | |
| 282 | buf, err := io.ReadAll(f) |
| 283 | if err != nil { |
| 284 | return nil, err |
| 285 | } |
| 286 | signer, err := ssh.ParsePrivateKey(buf) |
| 287 | if err != nil { |
| 288 | fmt.Print("Enter ssh key passphrase: ") |
| 289 | bytePassword, err := term.ReadPassword(int(syscall.Stdin)) |
| 290 | // ReadPassword eats newline, put it back to avoid mangling logs |
| 291 | fmt.Println() |
| 292 | if err != nil { |
| 293 | return nil, err |
| 294 | } |
| 295 | signer, err := sshkeys.ParseEncryptedPrivateKey(buf, bytePassword) |
| 296 | if err != nil { |
| 297 | return nil, err |
| 298 | } |
| 299 | return signer, nil |
| 300 | } |
| 301 | return signer, err |
| 302 | } |
| 303 | |
| 304 | // CopyImageToInstance copies the image to the instance via ssh |
| 305 | func (s *ScalewayClient) CopyImageToInstance(instanceID, path, sshKeyPath string) error { |
no test coverage detected