mirror of
https://github.com/appleboy/drone-ssh.git
synced 2026-06-16 14:49:25 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ded90faebd | |||
| c46dd8eadf | |||
| 18d0ff3a20 |
@@ -2,7 +2,7 @@
|
||||
|
||||
# drone-ssh
|
||||
|
||||
[]() [](https://godoc.org/github.com/appleboy/drone-ssh) [](http://drone.wu-boy.com/appleboy/drone-ssh) [](https://codecov.io/gh/appleboy/drone-ssh) [](https://goreportcard.com/report/github.com/appleboy/drone-ssh) [](https://hub.docker.com/r/appleboy/drone-ssh/) [](https://microbadger.com/images/appleboy/drone-ssh "Get your own image badge on microbadger.com")
|
||||
[](https://github.com/appleboy/drone-ssh/releases) [](https://godoc.org/github.com/appleboy/drone-ssh) [](http://drone.wu-boy.com/appleboy/drone-ssh) [](https://codecov.io/gh/appleboy/drone-ssh) [](https://goreportcard.com/report/github.com/appleboy/drone-ssh) [](https://hub.docker.com/r/appleboy/drone-ssh/) [](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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user