Skip to content

Commit

Permalink
Fixed most review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
deven96 committed Mar 17, 2022
1 parent 935de09 commit 0a1aaa4
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
6 changes: 1 addition & 5 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ type SystemDetails struct {
Extra string
}

type fields struct {
// Supported inspector representations for specific driver
Supported []string
// Selected inspector representations
Selected []string
type driverBase struct {
// Polling interval between retrievals
PollInterval int64
Info *SystemDetails
Expand Down
8 changes: 4 additions & 4 deletions driver/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

// Local : Driver for handling local executions
type Local struct {
fields
Vars []string
driverBase
EnvVars []string
}

func (d *Local) ReadFile(path string) (string, error) {
Expand Down Expand Up @@ -43,8 +43,8 @@ func (d *Local) RunCommand(command string) (string, error) {
cmd = exec.Command("cmd", "/C", command)
}
cmd.Env = os.Environ()
if len(d.Vars) != 0 {
for _, v := range d.Vars {
if len(d.EnvVars) != 0 {
for _, v := range d.EnvVars {
cmd.Env = append(cmd.Env, v)
}
}
Expand Down
16 changes: 9 additions & 7 deletions driver/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var port = 22

// SSH : Driver for handling ssh executions
type SSH struct {
fields
driverBase
// User e.g root
User string
// Host name/ip e.g 171.23.122.1
Expand All @@ -27,7 +27,7 @@ type SSH struct {
// Check known hosts (only disable for tests
CheckKnownHosts bool
// set environmental vars for server e.g []string{"DEBUG=1", "FAKE=echo"}
Vars []string
EnvVars []string
SessionClient *goph.Client
}

Expand Down Expand Up @@ -64,7 +64,9 @@ func (d *SSH) Client() (*goph.Client, error) {
Timeout: goph.DefaultTimeout,
Callback: callback,
})
d.SessionClient = client
if err != nil {
d.SessionClient = client
}
return client, err
}
return d.SessionClient, nil
Expand All @@ -77,16 +79,16 @@ func (d *SSH) ReadFile(path string) (string, error) {
}

func (d *SSH) RunCommand(command string) (string, error) {
// FIXME: provide refresh interface to somehow refresh d.Client if d.SessionClient somehow gets dropped
// TODO: Ensure clients of all SSH drivers are closed on context end
// i.e d.SessionClient.Close()
log.Debugf("Running remote command %s", command)
client, err := d.Client()
if err != nil {
return ``, err
}
defer client.Close()
if len(d.Vars) != 0 {
if len(d.EnvVars) != 0 {
// add env variable to command
envline := strings.Join(d.Vars, ";")
envline := strings.Join(d.EnvVars, ";")
command = strings.Join([]string{envline, command}, ";")
}
out, err := client.Run(command)
Expand Down
2 changes: 1 addition & 1 deletion driver/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewSSHForTest() Driver {
KeyFile: "/home/diretnan/.ssh/id_rsa",
KeyPass: "",
CheckKnownHosts: false,
fields: fields{
driverBase: driverBase{
PollInterval: 5,
},
}
Expand Down
2 changes: 1 addition & 1 deletion driver/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (

// Web : Driver for handling web executions
type Web struct {
fields
driverBase
// URL e.g https://google.com
URL string
// Method POST/GET
Expand Down
2 changes: 1 addition & 1 deletion driver/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func NewWebForTest() *Web {
return &Web{
URL: "https://duckduckgo.com",
Method: GET,
fields: fields{
driverBase: driverBase{
PollInterval: 5,
},
}
Expand Down
2 changes: 1 addition & 1 deletion integration/integration_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestProcessonLocal(t *testing.T) {
func TestCustomonLocal(t *testing.T) {
d := NewLocalForTest()
dfConcrete, _ := d.(*driver.Local)
dfConcrete.Vars = []string{"EXAMPLES=true"}
dfConcrete.EnvVars = []string{"EXAMPLES=true"}
d = dfConcrete
i, _ := inspector.Init(`custom`, &d, `echo %EXAMPLES%`)
i.Execute()
Expand Down

0 comments on commit 0a1aaa4

Please sign in to comment.