-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.go
71 lines (58 loc) · 1.72 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
66
67
68
69
70
71
package main
import (
"errors"
"regexp"
"github.com/ZipRecruiter/cloudwatching/pkg/exportcloudwatch"
)
type exportConfig struct {
Namespace, Name string
Dimensions, Statistics []string
DimensionsMatch, DimensionsNoMatch map[string]string
StatDefault string
}
type configuration struct {
Region string
Debug bool
ExportConfigs []exportConfig
exportConfigs []exportcloudwatch.ExportConfig
}
func (c *configuration) Validate() error {
c.exportConfigs = make([]exportcloudwatch.ExportConfig, len(c.ExportConfigs))
for i, raw := range c.ExportConfigs {
c.exportConfigs[i] = exportcloudwatch.ExportConfig{
Namespace: raw.Namespace,
Name: raw.Name,
Dimensions: raw.Dimensions,
Statistics: raw.Statistics,
DimensionsMatch: make(map[string]*regexp.Regexp, len(raw.DimensionsMatch)),
DimensionsNoMatch: make(map[string]*regexp.Regexp, len(raw.DimensionsNoMatch)),
}
if raw.StatDefault == "Prior" {
c.exportConfigs[i].StatDefault = exportcloudwatch.Prior
} else if raw.StatDefault == "Zero" {
c.exportConfigs[i].StatDefault = exportcloudwatch.Zero
} else if raw.StatDefault == "NaN" {
c.exportConfigs[i].StatDefault = exportcloudwatch.NaN
} else if raw.StatDefault != "" {
return errors.New("StatDefault must be one of Prior, Zero, or NaN")
}
for k, v := range raw.DimensionsMatch {
re, err := regexp.Compile(v)
if err != nil {
return err
}
c.exportConfigs[i].DimensionsMatch[k] = re
}
for k, v := range raw.DimensionsNoMatch {
re, err := regexp.Compile(v)
if err != nil {
return err
}
c.exportConfigs[i].DimensionsNoMatch[k] = re
}
if err := c.exportConfigs[i].Validate(); err != nil {
return err
}
}
return nil
}