-
Notifications
You must be signed in to change notification settings - Fork 127
/
config_sections.go
98 lines (87 loc) · 2.42 KB
/
config_sections.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package evergreen
import (
"context"
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson"
"github.com/mongodb/grip"
)
// In order to add a new config section:
// 1. modify the struct in config.go to add whatever you need to add
// 2. add the struct to the ConfigSections constructor below
// 3. add a copy of the struct you added in 1 to rest/model/admin.go and implement the
// conversion methods. The property name must be exactly the same in the DB/API model
// 4. add it to MockConfig in testutil/config.go for testing, if desired
type ConfigSections struct {
Sections map[string]ConfigSection
}
func NewConfigSections() ConfigSections {
sections := []ConfigSection{
&AmboyConfig{},
&AmboyDBConfig{},
&APIConfig{},
&AuthConfig{},
&BucketsConfig{},
&CedarConfig{},
&CloudProviders{},
&CommitQueueConfig{},
&ContainerPoolsConfig{},
&HostInitConfig{},
&HostJasperConfig{},
&JiraConfig{},
&LoggerConfig{},
&NewRelicConfig{},
&NotifyConfig{},
&PodLifecycleConfig{},
&ProjectCreationConfig{},
&RepoTrackerConfig{},
&RuntimeEnvironmentsConfig{},
&SchedulerConfig{},
&ServiceFlags{},
&SlackConfig{},
&SleepScheduleConfig{},
&SplunkConfig{},
&UIConfig{},
&Settings{},
&JIRANotificationsConfig{},
&TaskLimitsConfig{},
&TriggerConfig{},
&SpawnHostConfig{},
&TracerConfig{},
&GitHubCheckRunConfig{},
}
sectionMap := make(map[string]ConfigSection, len(sections))
for _, section := range sections {
sectionMap[section.SectionId()] = section
}
return ConfigSections{Sections: sectionMap}
}
func (c *ConfigSections) populateSections(ctx context.Context, includeOverrides bool) error {
sectionIDs := make([]string, 0, len(c.Sections))
for sectionID := range c.Sections {
sectionIDs = append(sectionIDs, sectionID)
}
rawSections, err := getSectionsBSON(ctx, sectionIDs, includeOverrides)
if err != nil {
return errors.Wrap(err, "getting raw sections")
}
catcher := grip.NewBasicCatcher()
for _, rawSection := range rawSections {
catcher.Add(c.unmarshallSection(rawSection))
}
return catcher.Resolve()
}
func (c *ConfigSections) unmarshallSection(rawSection bson.Raw) error {
id, err := rawSection.LookupErr("_id")
if err != nil {
return nil
}
idString, ok := id.StringValueOK()
if !ok {
return nil
}
section, ok := c.Sections[idString]
if !ok {
return nil
}
return errors.Wrapf(bson.Unmarshal(rawSection, section), "unmarshalling section '%s'", idString)
}