mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-07-02 21:52:51 +08:00
feat(env): pass secret to remote server.
This commit is contained in:
parent
e6d4fa77d1
commit
c279b5c136
12
main.go
12
main.go
@ -115,6 +115,16 @@ func main() {
|
||||
Usage: "proxy connection timeout",
|
||||
EnvVar: "PLUGIN_PROXY_TIMEOUT,PROXY_SSH_TIMEOUT",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "secrets",
|
||||
Usage: "plugin secret",
|
||||
EnvVar: "PLUGIN_SECRETS",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "envs",
|
||||
Usage: "Pass envs",
|
||||
EnvVar: "PLUGIN_ENVS",
|
||||
},
|
||||
}
|
||||
|
||||
// Override a template
|
||||
@ -169,6 +179,8 @@ func run(c *cli.Context) error {
|
||||
Timeout: c.Duration("timeout"),
|
||||
CommandTimeout: c.Int("command.timeout"),
|
||||
Script: c.StringSlice("script"),
|
||||
Secrets: c.StringSlice("secrets"),
|
||||
Envs: c.StringSlice("envs"),
|
||||
Proxy: easyssh.DefaultConfig{
|
||||
Key: c.String("proxy.ssh-key"),
|
||||
KeyPath: c.String("proxy.key-path"),
|
||||
|
12
plugin.go
12
plugin.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -29,6 +30,8 @@ type (
|
||||
Timeout time.Duration
|
||||
CommandTimeout int
|
||||
Script []string
|
||||
Secrets []string
|
||||
Envs []string
|
||||
Proxy easyssh.DefaultConfig
|
||||
}
|
||||
|
||||
@ -86,6 +89,15 @@ func (p Plugin) Exec() error {
|
||||
},
|
||||
}
|
||||
|
||||
env := []string{}
|
||||
for _, key := range p.Config.Envs {
|
||||
val := os.Getenv(key)
|
||||
val = strings.Replace(val, " ", "", -1)
|
||||
env = append(env, key+"="+val)
|
||||
}
|
||||
|
||||
p.Config.Script = append(env, p.Config.Script...)
|
||||
|
||||
p.log(host, "commands: ", strings.Join(p.Config.Script, "\n"))
|
||||
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream(strings.Join(p.Config.Script, "\n"), p.Config.CommandTimeout)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user