Skip to content

Commit

Permalink
Adds fields to agent.yaml to give Input/OutputPath (#183)
Browse files Browse the repository at this point in the history
As an alternative they are now also part of the config

Signed-off-by: Jamie Leppard <[email protected]>

Co-authored-by: Jamie Leppard <[email protected]>
  • Loading branch information
JammyL and JammyL authored Jul 7, 2020
1 parent d0f0693 commit 15d34e3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type Config struct {
// ClusterID is the cluster that the agent is scanning.
ClusterID string `yaml:"cluster_id"`
DataGatherers []dataGatherer `yaml:"data-gatherers"`
// InputPath replaces DataGatherers with input data file
InputPath string `yaml:"input-path"`
// OutputPath replaces Server with output data file
OutputPath string `yaml:"output-path"`
}

type Endpoint struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/agent/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func TestValidConfigLoad(t *testing.T) {
kind: dummy
config:
param-1: "bar"
input-path: "/home"
output-path: "/nothome"
`

loadedConfig, err := ParseConfig([]byte(configFileContents))
Expand All @@ -37,6 +39,8 @@ func TestValidConfigLoad(t *testing.T) {
},
},
},
InputPath: "/home",
OutputPath: "/nothome",
}

if diff, equal := messagediff.PrettyDiff(expected, loadedConfig); !equal {
Expand Down
11 changes: 10 additions & 1 deletion pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var AuthToken string
// Period is the number of seconds between scans
var Period uint

// Agent will run only once if OneShot is enabled
// OneShot flag causes agent to run once
var OneShot bool

// CredentialsPath is where the agent will try to loads the credentials. (Experimental)
Expand Down Expand Up @@ -138,6 +138,15 @@ func getConfiguration(ctx context.Context) (Config, *client.PreflightClient) {

func gatherAndOutputData(ctx context.Context, config Config, preflightClient *client.PreflightClient) {
var readings []*api.DataReading

// Input/OutputPath flag overwrites agent.yaml configuration
if InputPath == "" {
InputPath = config.InputPath
}
if OutputPath == "" {
OutputPath = config.OutputPath
}

if InputPath != "" {
log.Println("Reading data from", InputPath)
data, err := ioutil.ReadFile(InputPath)
Expand Down

0 comments on commit 15d34e3

Please sign in to comment.