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", Usage: "pass all environment variable to shell script",
EnvVars: []string{"PLUGIN_ALLENVS", "INPUT_ALLENVS"}, 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 // Override a template
@ -288,6 +293,7 @@ func run(c *cli.Context) error {
Ciphers: c.StringSlice("ciphers"), Ciphers: c.StringSlice("ciphers"),
UseInsecureCipher: c.Bool("useInsecureCipher"), UseInsecureCipher: c.Bool("useInsecureCipher"),
AllEnvs: c.Bool("allenvs"), AllEnvs: c.Bool("allenvs"),
RequireTty: c.Bool("request-pty"),
Proxy: easyssh.DefaultConfig{ Proxy: easyssh.DefaultConfig{
Key: c.String("proxy.ssh-key"), Key: c.String("proxy.ssh-key"),
KeyPath: c.String("proxy.key-path"), KeyPath: c.String("proxy.key-path"),

View File

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

View File

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