Skip to content

Commit

Permalink
feat: update plugin functionality in main.go and plugin.go files
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
appleboy committed Jan 7, 2024
1 parent d217773 commit b34fffd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type (
UseInsecureCipher bool
EnvsFormat string
AllEnvs bool
RequireTty bool
}

// Plugin structure
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`
)

Expand All @@ -941,6 +941,7 @@ func TestSudoCommand(t *testing.T) {
`sudo su - -c "whoami"`,
},
CommandTimeout: 10 * time.Second,
RequireTty: true,
},
Writer: &buffer,
}
Expand Down

0 comments on commit b34fffd

Please sign in to comment.