Skip to content

Commit 15d34e3

Browse files
authored
Adds fields to agent.yaml to give Input/OutputPath (#183)
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]>
1 parent d0f0693 commit 15d34e3

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

pkg/agent/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ type Config struct {
3131
// ClusterID is the cluster that the agent is scanning.
3232
ClusterID string `yaml:"cluster_id"`
3333
DataGatherers []dataGatherer `yaml:"data-gatherers"`
34+
// InputPath replaces DataGatherers with input data file
35+
InputPath string `yaml:"input-path"`
36+
// OutputPath replaces Server with output data file
37+
OutputPath string `yaml:"output-path"`
3438
}
3539

3640
type Endpoint struct {

pkg/agent/config_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ func TestValidConfigLoad(t *testing.T) {
1818
kind: dummy
1919
config:
2020
param-1: "bar"
21+
input-path: "/home"
22+
output-path: "/nothome"
2123
`
2224

2325
loadedConfig, err := ParseConfig([]byte(configFileContents))
@@ -37,6 +39,8 @@ func TestValidConfigLoad(t *testing.T) {
3739
},
3840
},
3941
},
42+
InputPath: "/home",
43+
OutputPath: "/nothome",
4044
}
4145

4246
if diff, equal := messagediff.PrettyDiff(expected, loadedConfig); !equal {

pkg/agent/run.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var AuthToken string
2828
// Period is the number of seconds between scans
2929
var Period uint
3030

31-
// Agent will run only once if OneShot is enabled
31+
// OneShot flag causes agent to run once
3232
var OneShot bool
3333

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

139139
func gatherAndOutputData(ctx context.Context, config Config, preflightClient *client.PreflightClient) {
140140
var readings []*api.DataReading
141+
142+
// Input/OutputPath flag overwrites agent.yaml configuration
143+
if InputPath == "" {
144+
InputPath = config.InputPath
145+
}
146+
if OutputPath == "" {
147+
OutputPath = config.OutputPath
148+
}
149+
141150
if InputPath != "" {
142151
log.Println("Reading data from", InputPath)
143152
data, err := ioutil.ReadFile(InputPath)

0 commit comments

Comments
 (0)