mirror of
https://github.com/appleboy/drone-scp.git
synced 2026-06-04 18:23:59 +08:00
feat: Add timeout flag. (#26)
This commit is contained in:
+5
-2
@@ -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)
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user