Skip to content

Commit

Permalink
feat(sftp): add suport for passphrase of private key (#6624 close #6592)
Browse files Browse the repository at this point in the history
Co-authored-by: XZB <i@1248.ink>
  • Loading branch information
XZB-1248 and XZB authored Jun 28, 2024
1 parent 453d7da commit 227d034
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions drivers/sftp/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Addition struct {
Username string `json:"username" required:"true"`
PrivateKey string `json:"private_key" type:"text"`
Password string `json:"password"`
Passphrase string `json:"passphrase"`
driver.RootPath
IgnoreSymlinkError bool `json:"ignore_symlink_error" default:"false" info:"Ignore symlink error"`
}
Expand Down
10 changes: 8 additions & 2 deletions drivers/sftp/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import (

func (d *SFTP) initClient() error {
var auth ssh.AuthMethod
if d.PrivateKey != "" {
signer, err := ssh.ParsePrivateKey([]byte(d.PrivateKey))
if len(d.PrivateKey) > 0 {
var err error
var signer ssh.Signer
if len(d.Passphrase) > 0 {
signer, err = ssh.ParsePrivateKeyWithPassphrase([]byte(d.PrivateKey), []byte(d.Passphrase))
} else {
signer, err = ssh.ParsePrivateKey([]byte(d.PrivateKey))
}
if err != nil {
return err
}
Expand Down

0 comments on commit 227d034

Please sign in to comment.