feat: update plugin functionality in main.go and plugin.go files

- Add a new flag to the main.go file
- Add a new field to the Plugin type in the plugin.go file
- Remove two lines from the plugin_test.go file

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2024-01-07 17:44:54 +08:00
parent d217773bac
commit b34fffdbd3
No known key found for this signature in database
3 changed files with 11 additions and 2 deletions

View File

@ -220,6 +220,11 @@ func main() {
Usage: "pass all environment variable to shell script",
EnvVars: []string{"PLUGIN_ALLENVS", "INPUT_ALLENVS"},
},
&cli.BoolFlag{
Name: "request-pty",
Usage: "request a pseudo-terminal from the server",
EnvVars: []string{"PLUGIN_REQUEST_PTY", "INPUT_REQUEST_PTY"},
},
}
// Override a template
@ -288,6 +293,7 @@ func run(c *cli.Context) error {
Ciphers: c.StringSlice("ciphers"),
UseInsecureCipher: c.Bool("useInsecureCipher"),
AllEnvs: c.Bool("allenvs"),
RequireTty: c.Bool("request-pty"),
Proxy: easyssh.DefaultConfig{
Key: c.String("proxy.ssh-key"),
KeyPath: c.String("proxy.key-path"),

View File

@ -44,6 +44,7 @@ type (
UseInsecureCipher bool
EnvsFormat string
AllEnvs bool
RequireTty bool
}
// Plugin structure
@ -85,6 +86,7 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
Ciphers: p.Config.Ciphers,
Fingerprint: p.Config.Fingerprint,
UseInsecureCipher: p.Config.UseInsecureCipher,
RequestPty: p.Config.RequireTty,
Proxy: easyssh.DefaultConfig{
Server: p.Config.Proxy.Server,
User: p.Config.Proxy.User,

View File

@ -925,9 +925,9 @@ func TestSudoCommand(t *testing.T) {
buffer bytes.Buffer
expected = `
======CMD======
whoami
sudo su - -c "whoami"
======END======
out: drone-scp
out: root
`
)
@ -941,6 +941,7 @@ func TestSudoCommand(t *testing.T) {
`sudo su - -c "whoami"`,
},
CommandTimeout: 10 * time.Second,
RequireTty: true,
},
Writer: &buffer,
}