Skip to content

Commit 0a1aaa4

Browse files
committed
Fixed most review comments
1 parent 935de09 commit 0a1aaa4

File tree

7 files changed

+18
-20
lines changed

7 files changed

+18
-20
lines changed

driver/driver.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ type SystemDetails struct {
1010
Extra string
1111
}
1212

13-
type fields struct {
14-
// Supported inspector representations for specific driver
15-
Supported []string
16-
// Selected inspector representations
17-
Selected []string
13+
type driverBase struct {
1814
// Polling interval between retrievals
1915
PollInterval int64
2016
Info *SystemDetails

driver/local.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
// Local : Driver for handling local executions
1313
type Local struct {
14-
fields
15-
Vars []string
14+
driverBase
15+
EnvVars []string
1616
}
1717

1818
func (d *Local) ReadFile(path string) (string, error) {
@@ -43,8 +43,8 @@ func (d *Local) RunCommand(command string) (string, error) {
4343
cmd = exec.Command("cmd", "/C", command)
4444
}
4545
cmd.Env = os.Environ()
46-
if len(d.Vars) != 0 {
47-
for _, v := range d.Vars {
46+
if len(d.EnvVars) != 0 {
47+
for _, v := range d.EnvVars {
4848
cmd.Env = append(cmd.Env, v)
4949
}
5050
}

driver/ssh.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var port = 22
1313

1414
// SSH : Driver for handling ssh executions
1515
type SSH struct {
16-
fields
16+
driverBase
1717
// User e.g root
1818
User string
1919
// Host name/ip e.g 171.23.122.1
@@ -27,7 +27,7 @@ type SSH struct {
2727
// Check known hosts (only disable for tests
2828
CheckKnownHosts bool
2929
// set environmental vars for server e.g []string{"DEBUG=1", "FAKE=echo"}
30-
Vars []string
30+
EnvVars []string
3131
SessionClient *goph.Client
3232
}
3333

@@ -64,7 +64,9 @@ func (d *SSH) Client() (*goph.Client, error) {
6464
Timeout: goph.DefaultTimeout,
6565
Callback: callback,
6666
})
67-
d.SessionClient = client
67+
if err != nil {
68+
d.SessionClient = client
69+
}
6870
return client, err
6971
}
7072
return d.SessionClient, nil
@@ -77,16 +79,16 @@ func (d *SSH) ReadFile(path string) (string, error) {
7779
}
7880

7981
func (d *SSH) RunCommand(command string) (string, error) {
80-
// FIXME: provide refresh interface to somehow refresh d.Client if d.SessionClient somehow gets dropped
82+
// TODO: Ensure clients of all SSH drivers are closed on context end
83+
// i.e d.SessionClient.Close()
8184
log.Debugf("Running remote command %s", command)
8285
client, err := d.Client()
8386
if err != nil {
8487
return ``, err
8588
}
86-
defer client.Close()
87-
if len(d.Vars) != 0 {
89+
if len(d.EnvVars) != 0 {
8890
// add env variable to command
89-
envline := strings.Join(d.Vars, ";")
91+
envline := strings.Join(d.EnvVars, ";")
9092
command = strings.Join([]string{envline, command}, ";")
9193
}
9294
out, err := client.Run(command)

driver/ssh_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func NewSSHForTest() Driver {
1313
KeyFile: "/home/diretnan/.ssh/id_rsa",
1414
KeyPass: "",
1515
CheckKnownHosts: false,
16-
fields: fields{
16+
driverBase: driverBase{
1717
PollInterval: 5,
1818
},
1919
}

driver/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const (
2323

2424
// Web : Driver for handling web executions
2525
type Web struct {
26-
fields
26+
driverBase
2727
// URL e.g https://google.com
2828
URL string
2929
// Method POST/GET

driver/web_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func NewWebForTest() *Web {
88
return &Web{
99
URL: "https://duckduckgo.com",
1010
Method: GET,
11-
fields: fields{
11+
driverBase: driverBase{
1212
PollInterval: 5,
1313
},
1414
}

integration/integration_windows_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestProcessonLocal(t *testing.T) {
3131
func TestCustomonLocal(t *testing.T) {
3232
d := NewLocalForTest()
3333
dfConcrete, _ := d.(*driver.Local)
34-
dfConcrete.Vars = []string{"EXAMPLES=true"}
34+
dfConcrete.EnvVars = []string{"EXAMPLES=true"}
3535
d = dfConcrete
3636
i, _ := inspector.Init(`custom`, &d, `echo %EXAMPLES%`)
3737
i.Execute()

0 commit comments

Comments
 (0)