From 227d034db85015f286b43091643ee8b42233dbdf Mon Sep 17 00:00:00 2001 From: XZB-1248 <28593573+XZB-1248@users.noreply.github.com> Date: Fri, 28 Jun 2024 23:50:00 +0800 Subject: [PATCH] feat(sftp): add suport for passphrase of private key (#6624 close #6592) Co-authored-by: XZB --- drivers/sftp/meta.go | 1 + drivers/sftp/util.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/sftp/meta.go b/drivers/sftp/meta.go index bdc3d827ff2..9b1665679cd 100644 --- a/drivers/sftp/meta.go +++ b/drivers/sftp/meta.go @@ -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"` } diff --git a/drivers/sftp/util.go b/drivers/sftp/util.go index eaeeaff5814..53f9c379e04 100644 --- a/drivers/sftp/util.go +++ b/drivers/sftp/util.go @@ -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 }