mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-05-12 18:42:48 +08:00
feat: support username flag.
This commit is contained in:
parent
7871a8e9f5
commit
9ec4e989c8
6
main.go
6
main.go
@ -36,9 +36,9 @@ func main() {
|
|||||||
EnvVar: "PLUGIN_KEY_PATH,SSH_KEY_PATH",
|
EnvVar: "PLUGIN_KEY_PATH,SSH_KEY_PATH",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "user,u",
|
Name: "username,user,u",
|
||||||
Usage: "connect as user",
|
Usage: "connect as user",
|
||||||
EnvVar: "PLUGIN_USER,SSH_USER",
|
EnvVar: "PLUGIN_USERNAME,PLUGIN_USER,SSH_USERNAME",
|
||||||
Value: "root",
|
Value: "root",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
@ -118,7 +118,7 @@ func run(c *cli.Context) error {
|
|||||||
Config: Config{
|
Config: Config{
|
||||||
Key: c.String("ssh-key"),
|
Key: c.String("ssh-key"),
|
||||||
KeyPath: c.String("key-path"),
|
KeyPath: c.String("key-path"),
|
||||||
User: c.String("user"),
|
UserName: c.String("user"),
|
||||||
Password: c.String("password"),
|
Password: c.String("password"),
|
||||||
Host: c.StringSlice("host"),
|
Host: c.StringSlice("host"),
|
||||||
Port: c.Int("port"),
|
Port: c.Int("port"),
|
||||||
|
@ -23,7 +23,7 @@ type (
|
|||||||
Config struct {
|
Config struct {
|
||||||
Key string
|
Key string
|
||||||
KeyPath string
|
KeyPath string
|
||||||
User string
|
UserName string
|
||||||
Password string
|
Password string
|
||||||
Host []string
|
Host []string
|
||||||
Port int
|
Port int
|
||||||
@ -43,7 +43,7 @@ func (p Plugin) log(host string, message ...interface{}) {
|
|||||||
|
|
||||||
// Exec executes the plugin.
|
// Exec executes the plugin.
|
||||||
func (p Plugin) Exec() error {
|
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)
|
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.
|
// Create MakeConfig instance with remote username, server address and path to private key.
|
||||||
ssh := &easyssh.MakeConfig{
|
ssh := &easyssh.MakeConfig{
|
||||||
Server: host,
|
Server: host,
|
||||||
User: p.Config.User,
|
User: p.Config.UserName,
|
||||||
Password: p.Config.Password,
|
Password: p.Config.Password,
|
||||||
Port: strconv.Itoa(p.Config.Port),
|
Port: strconv.Itoa(p.Config.Port),
|
||||||
Key: p.Config.Key,
|
Key: p.Config.Key,
|
||||||
|
@ -6,20 +6,20 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMissingHostOrUser(t *testing.T) {
|
func TestMissingHostOrUserName(t *testing.T) {
|
||||||
plugin := Plugin{}
|
plugin := Plugin{}
|
||||||
|
|
||||||
err := plugin.Exec()
|
err := plugin.Exec()
|
||||||
|
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
assert.Equal(t, missingHostOrUser, err.Error())
|
assert.Equal(t, missingHostOrUserName, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMissingKeyOrPassword(t *testing.T) {
|
func TestMissingKeyOrPassword(t *testing.T) {
|
||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Config{
|
Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
User: "ubuntu",
|
UserName: "ubuntu",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ func TestIncorrectPassword(t *testing.T) {
|
|||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
User: "drone-scp",
|
UserName: "drone-scp",
|
||||||
Port: 22,
|
Port: 22,
|
||||||
Password: "123456",
|
Password: "123456",
|
||||||
Script: []string{"whoami"},
|
Script: []string{"whoami"},
|
||||||
@ -48,7 +48,7 @@ func TestSSHScriptFromRawKey(t *testing.T) {
|
|||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost"},
|
Host: []string{"localhost"},
|
||||||
User: "drone-scp",
|
UserName: "drone-scp",
|
||||||
Port: 22,
|
Port: 22,
|
||||||
Key: `-----BEGIN RSA PRIVATE KEY-----
|
Key: `-----BEGIN RSA PRIVATE KEY-----
|
||||||
MIIEpAIBAAKCAQEA4e2D/qPN08pzTac+a8ZmlP1ziJOXk45CynMPtva0rtK/RB26
|
MIIEpAIBAAKCAQEA4e2D/qPN08pzTac+a8ZmlP1ziJOXk45CynMPtva0rtK/RB26
|
||||||
@ -90,7 +90,7 @@ func TestSSHScriptFromKeyFile(t *testing.T) {
|
|||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Config: Config{
|
Config: Config{
|
||||||
Host: []string{"localhost", "127.0.0.1"},
|
Host: []string{"localhost", "127.0.0.1"},
|
||||||
User: "drone-scp",
|
UserName: "drone-scp",
|
||||||
Port: 22,
|
Port: 22,
|
||||||
KeyPath: "./tests/.ssh/id_rsa",
|
KeyPath: "./tests/.ssh/id_rsa",
|
||||||
Script: []string{"whoami", "ls -al"},
|
Script: []string{"whoami", "ls -al"},
|
||||||
|
Loading…
Reference in New Issue
Block a user