forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_data_pipes.go
72 lines (60 loc) · 2.37 KB
/
config_data_pipes.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
package evergreen
import (
"github.com/mongodb/anser/bsonutil"
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
// DataPipesConfig represents the admin config section for the Data-Pipes
// results service. See `https://github.com/10gen/data-pipes` for more
// information.
type DataPipesConfig struct {
Host string `bson:"host" json:"host" yaml:"host"`
Region string `bson:"region" json:"region" yaml:"region"`
AWSAccessKey string `bson:"aws_access_key" json:"aws_access_key" yaml:"aws_access_key"`
AWSSecretKey string `bson:"aws_secret_key" json:"aws_secret_key" yaml:"aws_secret_key"`
AWSToken string `bson:"aws_token" json:"aws_token" yaml:"aws_token"`
}
var (
dataPipesConfigHostKey = bsonutil.MustHaveTag(DataPipesConfig{}, "Host")
dataPipesConfigRegionKey = bsonutil.MustHaveTag(DataPipesConfig{}, "Region")
dataPipesConfigAWSAccessKeyKey = bsonutil.MustHaveTag(DataPipesConfig{}, "AWSAccessKey")
dataPipesConfigAWSSecretKeyKey = bsonutil.MustHaveTag(DataPipesConfig{}, "AWSSecretKey")
dataPipesConfigAWSTokenKey = bsonutil.MustHaveTag(DataPipesConfig{}, "AWSToken")
)
func (*DataPipesConfig) SectionId() string { return "data_pipes" }
func (c *DataPipesConfig) Get(env Environment) error {
ctx, cancel := env.Context()
defer cancel()
coll := env.DB().Collection(ConfigCollection)
res := coll.FindOne(ctx, byId(c.SectionId()))
if err := res.Err(); err != nil {
if err == mongo.ErrNoDocuments {
*c = DataPipesConfig{}
return nil
}
return errors.Wrapf(err, "retrieving section %s", c.SectionId())
}
if err := res.Decode(c); err != nil {
return errors.Wrap(err, "decoding result")
}
return nil
}
func (c *DataPipesConfig) Set() error {
env := GetEnvironment()
ctx, cancel := env.Context()
defer cancel()
coll := env.DB().Collection(ConfigCollection)
_, err := coll.UpdateOne(ctx, byId(c.SectionId()), bson.M{
"$set": bson.M{
dataPipesConfigHostKey: c.Host,
dataPipesConfigRegionKey: c.Region,
dataPipesConfigAWSAccessKeyKey: c.AWSAccessKey,
dataPipesConfigAWSSecretKeyKey: c.AWSSecretKey,
dataPipesConfigAWSTokenKey: c.AWSToken,
},
}, options.Update().SetUpsert(true))
return errors.Wrapf(err, "updating section %s", c.SectionId())
}
func (c *DataPipesConfig) ValidateAndDefault() error { return nil }