mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-07-05 22:02:49 +08:00
parent
7871a8e9f5
commit
833d26f473
10
DOCS.md
10
DOCS.md
@ -15,7 +15,7 @@ pipeline:
|
||||
ssh:
|
||||
image: appleboy/drone-ssh
|
||||
host: foo.com
|
||||
user: root
|
||||
username: root
|
||||
password: 1234
|
||||
port: 22
|
||||
script:
|
||||
@ -32,7 +32,7 @@ pipeline:
|
||||
host:
|
||||
+ - foo.com
|
||||
+ - bar.com
|
||||
user: root
|
||||
username: root
|
||||
port: 22
|
||||
script:
|
||||
- echo hello
|
||||
@ -46,7 +46,7 @@ pipeline:
|
||||
ssh:
|
||||
image: appleboy/drone-ssh
|
||||
host: foo.com
|
||||
user: root
|
||||
username: root
|
||||
password: 1234
|
||||
port: 22
|
||||
script:
|
||||
@ -63,7 +63,7 @@ pipeline:
|
||||
ssh:
|
||||
image: appleboy/drone-ssh
|
||||
host: foo.com
|
||||
user: root
|
||||
username: root
|
||||
password: 1234
|
||||
port: 22
|
||||
script:
|
||||
@ -82,7 +82,7 @@ host
|
||||
port
|
||||
: ssh port of target host
|
||||
|
||||
user
|
||||
username
|
||||
: account for target host user
|
||||
|
||||
password
|
||||
|
@ -42,7 +42,7 @@ Execute from the working directory:
|
||||
```sh
|
||||
docker run --rm \
|
||||
-e PLUGIN_HOST=foo.com \
|
||||
-e PLUGIN_USER=root \
|
||||
-e PLUGIN_USERNAME=root \
|
||||
-e PLUGIN_KEY="$(cat ${HOME}/.ssh/id_rsa)" \
|
||||
-e PLUGIN_SCRIPT=whoami \
|
||||
-v $(pwd):$(pwd) \
|
||||
|
6
main.go
6
main.go
@ -36,9 +36,9 @@ func main() {
|
||||
EnvVar: "PLUGIN_KEY_PATH,SSH_KEY_PATH",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "user,u",
|
||||
Name: "username,user,u",
|
||||
Usage: "connect as user",
|
||||
EnvVar: "PLUGIN_USER,SSH_USER",
|
||||
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SSH_USERNAME",
|
||||
Value: "root",
|
||||
},
|
||||
cli.StringFlag{
|
||||
@ -118,7 +118,7 @@ func run(c *cli.Context) error {
|
||||
Config: Config{
|
||||
Key: c.String("ssh-key"),
|
||||
KeyPath: c.String("key-path"),
|
||||
User: c.String("user"),
|
||||
UserName: c.String("user"),
|
||||
Password: c.String("password"),
|
||||
Host: c.StringSlice("host"),
|
||||
Port: c.Int("port"),
|
||||
|
@ -23,7 +23,7 @@ type (
|
||||
Config struct {
|
||||
Key string
|
||||
KeyPath string
|
||||
User string
|
||||
UserName string
|
||||
Password string
|
||||
Host []string
|
||||
Port int
|
||||
@ -43,7 +43,7 @@ func (p Plugin) log(host string, message ...interface{}) {
|
||||
|
||||
// Exec executes the plugin.
|
||||
func (p Plugin) Exec() error {
|
||||
if len(p.Config.Host) == 0 && p.Config.User == "" {
|
||||
if len(p.Config.Host) == 0 && p.Config.UserName == "" {
|
||||
return fmt.Errorf(missingHostOrUser)
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ func (p Plugin) Exec() error {
|
||||
// Create MakeConfig instance with remote username, server address and path to private key.
|
||||
ssh := &easyssh.MakeConfig{
|
||||
Server: host,
|
||||
User: p.Config.User,
|
||||
User: p.Config.UserName,
|
||||
Password: p.Config.Password,
|
||||
Port: strconv.Itoa(p.Config.Port),
|
||||
Key: p.Config.Key,
|
||||
|
@ -18,8 +18,8 @@ func TestMissingHostOrUser(t *testing.T) {
|
||||
func TestMissingKeyOrPassword(t *testing.T) {
|
||||
plugin := Plugin{
|
||||
Config{
|
||||
Host: []string{"localhost"},
|
||||
User: "ubuntu",
|
||||
Host: []string{"localhost"},
|
||||
UserName: "ubuntu",
|
||||
},
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ func TestIncorrectPassword(t *testing.T) {
|
||||
plugin := Plugin{
|
||||
Config: Config{
|
||||
Host: []string{"localhost"},
|
||||
User: "drone-scp",
|
||||
UserName: "drone-scp",
|
||||
Port: 22,
|
||||
Password: "123456",
|
||||
Script: []string{"whoami"},
|
||||
@ -47,9 +47,9 @@ func TestIncorrectPassword(t *testing.T) {
|
||||
func TestSSHScriptFromRawKey(t *testing.T) {
|
||||
plugin := Plugin{
|
||||
Config: Config{
|
||||
Host: []string{"localhost"},
|
||||
User: "drone-scp",
|
||||
Port: 22,
|
||||
Host: []string{"localhost"},
|
||||
UserName: "drone-scp",
|
||||
Port: 22,
|
||||
Key: `-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpAIBAAKCAQEA4e2D/qPN08pzTac+a8ZmlP1ziJOXk45CynMPtva0rtK/RB26
|
||||
VbfAF0hIJji7ltvnYnqCU9oFfvEM33cTn7T96+od8ib/Vz25YU8ZbstqtIskPuwC
|
||||
@ -89,11 +89,11 @@ ib4KbP5ovZlrjL++akMQ7V2fHzuQIFWnCkDA5c2ZAqzlM+ZN+HRG7gWur7Bt4XH1
|
||||
func TestSSHScriptFromKeyFile(t *testing.T) {
|
||||
plugin := Plugin{
|
||||
Config: Config{
|
||||
Host: []string{"localhost", "127.0.0.1"},
|
||||
User: "drone-scp",
|
||||
Port: 22,
|
||||
KeyPath: "./tests/.ssh/id_rsa",
|
||||
Script: []string{"whoami", "ls -al"},
|
||||
Host: []string{"localhost", "127.0.0.1"},
|
||||
UserName: "drone-scp",
|
||||
Port: 22,
|
||||
KeyPath: "./tests/.ssh/id_rsa",
|
||||
Script: []string{"whoami", "ls -al"},
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user