-
Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathconfig.go
65 lines (53 loc) · 2.01 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package task
import "fmt"
type Config struct {
// Enabled determines if flux tasks are enabled
Enabled bool `toml:"enabled"`
// TaskRunInfluxDB is the name of the influxdb instance finished
// task runs and logs are written to.
// Leaving it blank will write to Kapacitor's default influxdb instance.
// Setting it to 'none' will disable task logging.
TaskRunInfluxDB string `toml:"task-run-influxdb"`
// TaskRunBucket is the bucket (or influxdb 1.x database) to use for saving
// task runs and logs
TaskRunBucket string `toml:"task-run-bucket"`
// TaskRunOrg is the org to use for saving task runs and logs
// task runs and logs.
// This is ignored if TaskRunInfluxDB is a 1.x database
// Only one of TaskRunOrg and TaskRunOrgID should be set
TaskRunOrg string `toml:"task-run-org"`
// TaskRunOrgID is the org to use for saving task runs and logs
// task runs and logs.
// This is ignored if TaskRunInfluxDB is a 1.x database
// Only one of TaskRunOrg and TaskRunOrgID should be set
TaskRunOrgID string `toml:"task-run-orgid"`
// TaskRunMeasurement is the measurement used for saving task runs
// and logs.
// The defaults is "runs"
TaskRunMeasurement string `toml:"task-run-measurement"`
// Secrets is the kapacitor provider for secrets as described at
// https://docs.influxdata.com/influxdb/v2.0/security/secrets/
Secrets map[string]string `toml:"secrets"`
// DefaultInfluxDB is the default influxdb instance that task scripts with interact with.
// This defaults to the kapacitor's default influxdb if left blank.
DefaultInfluxDB string `toml:"default-influxdb"`
}
const DefaultTaskRunBucket = "kapacitor_fluxtask_logs"
func NewConfig() Config {
return Config{
TaskRunMeasurement: "runs",
TaskRunBucket: DefaultTaskRunBucket,
}
}
func (c Config) Validate() error {
if !c.Enabled {
return nil
}
if c.TaskRunInfluxDB == "none" {
return nil
}
if len(c.TaskRunOrgID) > 0 && len(c.TaskRunOrg) > 0 {
return fmt.Errorf("only one of task-run-org and task-run-orgid should be set")
}
return nil
}