diff --git a/easyssh/easyssh.go b/easyssh/easyssh.go index 92c219f..b0f4eab 100644 --- a/easyssh/easyssh.go +++ b/easyssh/easyssh.go @@ -12,6 +12,7 @@ import ( "net" "os" "path/filepath" + "time" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/agent" @@ -31,6 +32,7 @@ type MakeConfig struct { KeyPath string Port string Password string + Timeout time.Duration } // returns ssh.Signer from user you running app home path + cutted key path. @@ -76,8 +78,9 @@ func (ssh_conf *MakeConfig) connect() (*ssh.Session, error) { } config := &ssh.ClientConfig{ - User: ssh_conf.User, - Auth: auths, + Timeout: ssh_conf.Timeout, + User: ssh_conf.User, + Auth: auths, } client, err := ssh.Dial("tcp", ssh_conf.Server+":"+ssh_conf.Port, config) diff --git a/main.go b/main.go index d770422..f9874c1 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,11 @@ func main() { Usage: "Password for password-based authentication", EnvVar: "PLUGIN_PASSWORD,SCP_PASSWORD", }, + cli.DurationFlag{ + Name: "timeout,t", + Usage: "connection timeout", + EnvVar: "PLUGIN_TIMEOUT,SCP_TIMEOUT", + }, cli.StringFlag{ Name: "key, k", Usage: "ssh private key", @@ -191,6 +196,7 @@ func run(c *cli.Context) error { Port: c.String("port"), Username: c.String("username"), Password: c.String("password"), + Timeout: c.Duration("timeout"), Key: c.String("key"), KeyPath: c.String("key-path"), Target: c.StringSlice("target"), diff --git a/plugin.go b/plugin.go index e186d2f..de0f1de 100644 --- a/plugin.go +++ b/plugin.go @@ -10,6 +10,7 @@ import ( "path/filepath" "strings" "sync" + "time" "github.com/appleboy/com/random" "github.com/appleboy/drone-scp/easyssh" @@ -42,6 +43,7 @@ type ( Password string Key string KeyPath string + Timeout time.Duration Target []string Source []string Remove bool @@ -121,6 +123,7 @@ func (p Plugin) Exec() error { Port: p.Config.Port, Key: p.Config.Key, KeyPath: p.Config.KeyPath, + Timeout: p.Config.Timeout, } // Call Scp method with file you want to upload to remote server.