mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-07-02 21:52:51 +08:00
fix: lint error.
This commit is contained in:
parent
31f65b5b86
commit
1f12571813
16
plugin.go
16
plugin.go
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -12,6 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// Config for the plugin.
|
||||||
Config struct {
|
Config struct {
|
||||||
Key string
|
Key string
|
||||||
User string
|
User string
|
||||||
@ -23,14 +23,16 @@ type (
|
|||||||
Script []string
|
Script []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Plugin structure
|
||||||
Plugin struct {
|
Plugin struct {
|
||||||
Config Config
|
Config Config
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Exec executes the plugin.
|
||||||
func (p Plugin) Exec() error {
|
func (p Plugin) Exec() error {
|
||||||
if p.Config.Key == "" && p.Config.Password == "" {
|
if p.Config.Key == "" && p.Config.Password == "" {
|
||||||
return fmt.Errorf("Error: Can't connect without a private SSH key or password.")
|
return errors.New("Error: can't connect without a private SSH key or password")
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, host := range p.Config.Host {
|
for i, host := range p.Config.Host {
|
||||||
@ -46,7 +48,7 @@ func (p Plugin) Exec() error {
|
|||||||
signer, err := ssh.ParsePrivateKey([]byte(p.Config.Key))
|
signer, err := ssh.ParsePrivateKey([]byte(p.Config.Key))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error: Failed to parse private key. %s", err)
|
return errors.New("Error: Failed to parse private key. %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
auths = append(auths, ssh.PublicKeys(signer))
|
auths = append(auths, ssh.PublicKeys(signer))
|
||||||
@ -63,17 +65,17 @@ func (p Plugin) Exec() error {
|
|||||||
Auth: auths,
|
Auth: auths,
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("+ ssh %s@%s -p %d\n", p.Config.User, addr, p.Config.Port)
|
log.Printf("+ ssh %s@%s -p %d\n", p.Config.User, addr, p.Config.Port)
|
||||||
client, err := ssh.Dial("tcp", addr, config)
|
client, err := ssh.Dial("tcp", addr, config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error: Failed to dial to server. %s", err)
|
return errors.New("Error: Failed to dial to server. %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
session, err := client.NewSession()
|
session, err := client.NewSession()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error: Failed to start a SSH session. %s", err)
|
return errors.New("Error: Failed to start a SSH session. %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
@ -86,7 +88,7 @@ func (p Plugin) Exec() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p.Config.Sleep != 0 && i != len(p.Config.Host)-1 {
|
if p.Config.Sleep != 0 && i != len(p.Config.Host)-1 {
|
||||||
fmt.Printf("+ sleep %d\n", p.Config.Sleep)
|
log.Printf("+ sleep %d\n", p.Config.Sleep)
|
||||||
time.Sleep(time.Duration(p.Config.Sleep) * time.Second)
|
time.Sleep(time.Duration(p.Config.Sleep) * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user