Skip to content

Commit b34fffd

Browse files
committed
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 <[email protected]>
1 parent d217773 commit b34fffd

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ func main() {
220220
Usage: "pass all environment variable to shell script",
221221
EnvVars: []string{"PLUGIN_ALLENVS", "INPUT_ALLENVS"},
222222
},
223+
&cli.BoolFlag{
224+
Name: "request-pty",
225+
Usage: "request a pseudo-terminal from the server",
226+
EnvVars: []string{"PLUGIN_REQUEST_PTY", "INPUT_REQUEST_PTY"},
227+
},
223228
}
224229

225230
// Override a template
@@ -288,6 +293,7 @@ func run(c *cli.Context) error {
288293
Ciphers: c.StringSlice("ciphers"),
289294
UseInsecureCipher: c.Bool("useInsecureCipher"),
290295
AllEnvs: c.Bool("allenvs"),
296+
RequireTty: c.Bool("request-pty"),
291297
Proxy: easyssh.DefaultConfig{
292298
Key: c.String("proxy.ssh-key"),
293299
KeyPath: c.String("proxy.key-path"),

plugin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type (
4444
UseInsecureCipher bool
4545
EnvsFormat string
4646
AllEnvs bool
47+
RequireTty bool
4748
}
4849

4950
// Plugin structure
@@ -85,6 +86,7 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
8586
Ciphers: p.Config.Ciphers,
8687
Fingerprint: p.Config.Fingerprint,
8788
UseInsecureCipher: p.Config.UseInsecureCipher,
89+
RequestPty: p.Config.RequireTty,
8890
Proxy: easyssh.DefaultConfig{
8991
Server: p.Config.Proxy.Server,
9092
User: p.Config.Proxy.User,

plugin_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,9 +925,9 @@ func TestSudoCommand(t *testing.T) {
925925
buffer bytes.Buffer
926926
expected = `
927927
======CMD======
928-
whoami
928+
sudo su - -c "whoami"
929929
======END======
930-
out: drone-scp
930+
out: root
931931
`
932932
)
933933

@@ -941,6 +941,7 @@ func TestSudoCommand(t *testing.T) {
941941
`sudo su - -c "whoami"`,
942942
},
943943
CommandTimeout: 10 * time.Second,
944+
RequireTty: true,
944945
},
945946
Writer: &buffer,
946947
}

0 commit comments

Comments
 (0)