mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-07-02 21:52:51 +08:00
feat: check missing host or user.
This commit is contained in:
parent
18d0ff3a20
commit
c46dd8eadf
11
plugin.go
11
plugin.go
@ -12,6 +12,11 @@ import (
|
|||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
missingHostOrUser = "Error: missing server host or user"
|
||||||
|
missingPasswordOrKey = "Error: can't connect without a private SSH key or password"
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Config for the plugin.
|
// Config for the plugin.
|
||||||
Config struct {
|
Config struct {
|
||||||
@ -33,8 +38,12 @@ type (
|
|||||||
|
|
||||||
// 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 == "" {
|
||||||
|
return fmt.Errorf(missingHostOrUser)
|
||||||
|
}
|
||||||
|
|
||||||
if p.Config.Key == "" && p.Config.Password == "" {
|
if p.Config.Key == "" && p.Config.Password == "" {
|
||||||
return fmt.Errorf("Error: can't connect without a private SSH key or password")
|
return fmt.Errorf(missingPasswordOrKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, host := range p.Config.Host {
|
for i, host := range p.Config.Host {
|
||||||
|
@ -6,6 +6,15 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestMissingHostOrUser(t *testing.T) {
|
||||||
|
plugin := Plugin{}
|
||||||
|
|
||||||
|
err := plugin.Exec()
|
||||||
|
|
||||||
|
assert.NotNil(t, err)
|
||||||
|
assert.Equal(t, missingHostOrUser, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
func TestMissingKeyOrPassword(t *testing.T) {
|
func TestMissingKeyOrPassword(t *testing.T) {
|
||||||
plugin := Plugin{
|
plugin := Plugin{
|
||||||
Config{
|
Config{
|
||||||
@ -17,4 +26,5 @@ func TestMissingKeyOrPassword(t *testing.T) {
|
|||||||
err := plugin.Exec()
|
err := plugin.Exec()
|
||||||
|
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
assert.Equal(t, missingPasswordOrKey, err.Error())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user