Skip to content

Commit 833d26f

Browse files
authored
feat: support username flag. (#45)
* feat: support username flag.
1 parent 7871a8e commit 833d26f

5 files changed

Lines changed: 23 additions & 23 deletions

File tree

DOCS.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pipeline:
1515
ssh:
1616
image: appleboy/drone-ssh
1717
host: foo.com
18-
user: root
18+
username: root
1919
password: 1234
2020
port: 22
2121
script:
@@ -32,7 +32,7 @@ pipeline:
3232
host:
3333
+ - foo.com
3434
+ - bar.com
35-
user: root
35+
username: root
3636
port: 22
3737
script:
3838
- echo hello
@@ -46,7 +46,7 @@ pipeline:
4646
ssh:
4747
image: appleboy/drone-ssh
4848
host: foo.com
49-
user: root
49+
username: root
5050
password: 1234
5151
port: 22
5252
script:
@@ -63,7 +63,7 @@ pipeline:
6363
ssh:
6464
image: appleboy/drone-ssh
6565
host: foo.com
66-
user: root
66+
username: root
6767
password: 1234
6868
port: 22
6969
script:
@@ -82,7 +82,7 @@ host
8282
port
8383
: ssh port of target host
8484

85-
user
85+
username
8686
: account for target host user
8787

8888
password

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Execute from the working directory:
4242
```sh
4343
docker run --rm \
4444
-e PLUGIN_HOST=foo.com \
45-
-e PLUGIN_USER=root \
45+
-e PLUGIN_USERNAME=root \
4646
-e PLUGIN_KEY="$(cat ${HOME}/.ssh/id_rsa)" \
4747
-e PLUGIN_SCRIPT=whoami \
4848
-v $(pwd):$(pwd) \

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ func main() {
3636
EnvVar: "PLUGIN_KEY_PATH,SSH_KEY_PATH",
3737
},
3838
cli.StringFlag{
39-
Name: "user,u",
39+
Name: "username,user,u",
4040
Usage: "connect as user",
41-
EnvVar: "PLUGIN_USER,SSH_USER",
41+
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SSH_USERNAME",
4242
Value: "root",
4343
},
4444
cli.StringFlag{
@@ -118,7 +118,7 @@ func run(c *cli.Context) error {
118118
Config: Config{
119119
Key: c.String("ssh-key"),
120120
KeyPath: c.String("key-path"),
121-
User: c.String("user"),
121+
UserName: c.String("user"),
122122
Password: c.String("password"),
123123
Host: c.StringSlice("host"),
124124
Port: c.Int("port"),

plugin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type (
2323
Config struct {
2424
Key string
2525
KeyPath string
26-
User string
26+
UserName string
2727
Password string
2828
Host []string
2929
Port int
@@ -43,7 +43,7 @@ func (p Plugin) log(host string, message ...interface{}) {
4343

4444
// Exec executes the plugin.
4545
func (p Plugin) Exec() error {
46-
if len(p.Config.Host) == 0 && p.Config.User == "" {
46+
if len(p.Config.Host) == 0 && p.Config.UserName == "" {
4747
return fmt.Errorf(missingHostOrUser)
4848
}
4949

@@ -59,7 +59,7 @@ func (p Plugin) Exec() error {
5959
// Create MakeConfig instance with remote username, server address and path to private key.
6060
ssh := &easyssh.MakeConfig{
6161
Server: host,
62-
User: p.Config.User,
62+
User: p.Config.UserName,
6363
Password: p.Config.Password,
6464
Port: strconv.Itoa(p.Config.Port),
6565
Key: p.Config.Key,

plugin_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func TestMissingHostOrUser(t *testing.T) {
1818
func TestMissingKeyOrPassword(t *testing.T) {
1919
plugin := Plugin{
2020
Config{
21-
Host: []string{"localhost"},
22-
User: "ubuntu",
21+
Host: []string{"localhost"},
22+
UserName: "ubuntu",
2323
},
2424
}
2525

@@ -33,7 +33,7 @@ func TestIncorrectPassword(t *testing.T) {
3333
plugin := Plugin{
3434
Config: Config{
3535
Host: []string{"localhost"},
36-
User: "drone-scp",
36+
UserName: "drone-scp",
3737
Port: 22,
3838
Password: "123456",
3939
Script: []string{"whoami"},
@@ -47,9 +47,9 @@ func TestIncorrectPassword(t *testing.T) {
4747
func TestSSHScriptFromRawKey(t *testing.T) {
4848
plugin := Plugin{
4949
Config: Config{
50-
Host: []string{"localhost"},
51-
User: "drone-scp",
52-
Port: 22,
50+
Host: []string{"localhost"},
51+
UserName: "drone-scp",
52+
Port: 22,
5353
Key: `-----BEGIN RSA PRIVATE KEY-----
5454
MIIEpAIBAAKCAQEA4e2D/qPN08pzTac+a8ZmlP1ziJOXk45CynMPtva0rtK/RB26
5555
VbfAF0hIJji7ltvnYnqCU9oFfvEM33cTn7T96+od8ib/Vz25YU8ZbstqtIskPuwC
@@ -89,11 +89,11 @@ ib4KbP5ovZlrjL++akMQ7V2fHzuQIFWnCkDA5c2ZAqzlM+ZN+HRG7gWur7Bt4XH1
8989
func TestSSHScriptFromKeyFile(t *testing.T) {
9090
plugin := Plugin{
9191
Config: Config{
92-
Host: []string{"localhost", "127.0.0.1"},
93-
User: "drone-scp",
94-
Port: 22,
95-
KeyPath: "./tests/.ssh/id_rsa",
96-
Script: []string{"whoami", "ls -al"},
92+
Host: []string{"localhost", "127.0.0.1"},
93+
UserName: "drone-scp",
94+
Port: 22,
95+
KeyPath: "./tests/.ssh/id_rsa",
96+
Script: []string{"whoami", "ls -al"},
9797
},
9898
}
9999

0 commit comments

Comments
 (0)