mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
SSH登录支持Passphrase
This commit is contained in:
@@ -6,5 +6,6 @@ type Credentials struct {
|
||||
Username string
|
||||
Password string
|
||||
PrivateKey string
|
||||
Passphrase string
|
||||
Method string
|
||||
}
|
||||
|
||||
@@ -59,7 +59,13 @@ func (this *BaseInstaller) Login(credentials *Credentials) error {
|
||||
methods = append(methods, authMethod)
|
||||
}
|
||||
} else if credentials.Method == "privateKey" {
|
||||
signer, err := ssh.ParsePrivateKey([]byte(credentials.PrivateKey))
|
||||
var signer ssh.Signer
|
||||
var err error
|
||||
if len(credentials.Passphrase) > 0 {
|
||||
signer, err = ssh.ParsePrivateKeyWithPassphrase([]byte(credentials.PrivateKey), []byte(credentials.Passphrase))
|
||||
} else {
|
||||
signer, err = ssh.ParsePrivateKey([]byte(credentials.PrivateKey))
|
||||
}
|
||||
if err != nil {
|
||||
return errors.New("parse private key: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func TestDNSNodeInstaller_Install(t *testing.T) {
|
||||
var installer InstallerInterface = &DNSNodeInstaller{}
|
||||
var installer InstallerInterface = &NSNodeInstaller{}
|
||||
err := installer.Login(&Credentials{
|
||||
Host: "192.168.2.30",
|
||||
Port: 22,
|
||||
|
||||
@@ -185,6 +185,7 @@ func (this *NodeQueue) InstallNode(nodeId int64, installStatus *models.NodeInsta
|
||||
Username: grant.Username,
|
||||
Password: grant.Password,
|
||||
PrivateKey: grant.PrivateKey,
|
||||
Passphrase: grant.Passphrase,
|
||||
Method: grant.Method,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -274,6 +275,7 @@ func (this *NodeQueue) StartNode(nodeId int64) error {
|
||||
Username: grant.Username,
|
||||
Password: grant.Password,
|
||||
PrivateKey: grant.PrivateKey,
|
||||
Passphrase: grant.Passphrase,
|
||||
Method: grant.Method,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -379,6 +381,7 @@ func (this *NodeQueue) StopNode(nodeId int64) error {
|
||||
Username: grant.Username,
|
||||
Password: grant.Password,
|
||||
PrivateKey: grant.PrivateKey,
|
||||
Passphrase: grant.Passphrase,
|
||||
Method: grant.Method,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -185,6 +185,7 @@ func (this *NSNodeQueue) InstallNode(nodeId int64, installStatus *models.NodeIns
|
||||
Username: grant.Username,
|
||||
Password: grant.Password,
|
||||
PrivateKey: grant.PrivateKey,
|
||||
Passphrase: grant.Passphrase,
|
||||
Method: grant.Method,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -274,6 +275,7 @@ func (this *NSNodeQueue) StartNode(nodeId int64) error {
|
||||
Username: grant.Username,
|
||||
Password: grant.Password,
|
||||
PrivateKey: grant.PrivateKey,
|
||||
Passphrase: grant.Passphrase,
|
||||
Method: grant.Method,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -379,6 +381,7 @@ func (this *NSNodeQueue) StopNode(nodeId int64) error {
|
||||
Username: grant.Username,
|
||||
Password: grant.Password,
|
||||
PrivateKey: grant.PrivateKey,
|
||||
Passphrase: grant.Passphrase,
|
||||
Method: grant.Method,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user