Compare commits

..

3 Commits

Author SHA1 Message Date
Bo-Yi Wu ded90faebd feat: update command line. 2017-01-23 14:33:49 +08:00
Bo-Yi Wu c46dd8eadf feat: check missing host or user. 2017-01-23 14:24:27 +08:00
Bo-Yi Wu 18d0ff3a20 fix: [ci skip] tag version 2017-01-23 12:12:07 +08:00
4 changed files with 67 additions and 8 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
# drone-ssh
[![GitHub tag](https://img.shields.io/github/tag/strongloop/express.svg)]() [![GoDoc](https://godoc.org/github.com/appleboy/drone-ssh?status.svg)](https://godoc.org/github.com/appleboy/drone-ssh) [![Build Status](http://drone.wu-boy.com/api/badges/appleboy/drone-ssh/status.svg)](http://drone.wu-boy.com/appleboy/drone-ssh) [![codecov](https://codecov.io/gh/appleboy/drone-ssh/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-ssh) [![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-ssh)](https://goreportcard.com/report/github.com/appleboy/drone-ssh) [![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-ssh.svg)](https://hub.docker.com/r/appleboy/drone-ssh/) [![](https://images.microbadger.com/badges/image/appleboy/drone-ssh.svg)](https://microbadger.com/images/appleboy/drone-ssh "Get your own image badge on microbadger.com")
[![GitHub tag](https://img.shields.io/github/tag/appleboy/drone-ssh.svg)](https://github.com/appleboy/drone-ssh/releases) [![GoDoc](https://godoc.org/github.com/appleboy/drone-ssh?status.svg)](https://godoc.org/github.com/appleboy/drone-ssh) [![Build Status](http://drone.wu-boy.com/api/badges/appleboy/drone-ssh/status.svg)](http://drone.wu-boy.com/appleboy/drone-ssh) [![codecov](https://codecov.io/gh/appleboy/drone-ssh/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-ssh) [![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-ssh)](https://goreportcard.com/report/github.com/appleboy/drone-ssh) [![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-ssh.svg)](https://hub.docker.com/r/appleboy/drone-ssh/) [![](https://images.microbadger.com/badges/image/appleboy/drone-ssh.svg)](https://microbadger.com/images/appleboy/drone-ssh "Get your own image badge on microbadger.com")
Drone plugin to execute commands on a remote host through SSH. For the usage
information and a listing of the available options please take a look at
+45 -5
View File
@@ -1,7 +1,6 @@
package main
import (
"fmt"
"os"
"github.com/joho/godotenv"
@@ -9,14 +8,22 @@ import (
"github.com/urfave/cli"
)
var build = "0" // build number set at compile-time
// Version set at compile-time
var Version = "v1.0.0-dev"
func main() {
app := cli.NewApp()
app.Name = "ssh plugin"
app.Usage = "ssh plugin"
app.Name = "Drone SSH"
app.Usage = "Executing remote ssh commands"
app.Copyright = "Copyright (c) 2017 Bo-Yi Wu"
app.Authors = []cli.Author{
{
Name: "Bo-Yi Wu",
Email: "appleboy.tw@gmail.com",
},
}
app.Action = run
app.Version = fmt.Sprintf("1.0.%s", build)
app.Version = Version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "ssh-key",
@@ -66,6 +73,39 @@ func main() {
},
}
// Override a template
cli.AppHelpTemplate = `
________ _________ _________ ___ ___
\______ \_______ ____ ____ ____ / _____// _____// | \
| | \_ __ \/ _ \ / \_/ __ \ ______ \_____ \ \_____ \/ ~ \
| | \ | \( <_> ) | \ ___/ /_____/ / \/ \ Y /
/_______ /__| \____/|___| /\___ > /_______ /_______ /\___|_ /
\/ \/ \/ \/ \/ \/
version: {{.Version}}
NAME:
{{.Name}} - {{.Usage}}
USAGE:
{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}
{{if len .Authors}}
AUTHOR:
{{range .Authors}}{{ . }}{{end}}
{{end}}{{if .Commands}}
COMMANDS:
{{range .Commands}}{{if not .HideHelp}} {{join .Names ", "}}{{ "\t"}}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
GLOBAL OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}{{if .Copyright }}
COPYRIGHT:
{{.Copyright}}
{{end}}{{if .Version}}
VERSION:
{{.Version}}
{{end}}
REPOSITORY:
Github: https://github.com/appleboy/drone-ssh
`
app.Run(os.Args)
}
+11 -2
View File
@@ -1,6 +1,7 @@
package main
import (
"fmt"
"log"
"net"
"os"
@@ -8,10 +9,14 @@ import (
"strings"
"time"
"fmt"
"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 (
// Config for the plugin.
Config struct {
@@ -33,8 +38,12 @@ type (
// Exec executes the plugin.
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 == "" {
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 {
+10
View File
@@ -6,6 +6,15 @@ import (
"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) {
plugin := Plugin{
Config{
@@ -17,4 +26,5 @@ func TestMissingKeyOrPassword(t *testing.T) {
err := plugin.Exec()
assert.NotNil(t, err)
assert.Equal(t, missingPasswordOrKey, err.Error())
}