forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_amboy_db.go
42 lines (34 loc) · 1.02 KB
/
config_amboy_db.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
package evergreen
import (
"context"
"github.com/mongodb/anser/bsonutil"
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson"
)
// AmboyDBConfig configures Amboy's database connection.
type AmboyDBConfig struct {
URL string `bson:"url" json:"url" yaml:"url"`
Database string `bson:"database" json:"database" yaml:"database"`
}
func (c *AmboyDBConfig) SectionId() string { return "amboy_db" }
var (
amboyDBURLKey = bsonutil.MustHaveTag(AmboyDBConfig{}, "URL")
amboyDBDatabaseKey = bsonutil.MustHaveTag(AmboyDBConfig{}, "Database")
)
func (c *AmboyDBConfig) Get(ctx context.Context) error {
return getConfigSection(ctx, c)
}
func (c *AmboyDBConfig) Set(ctx context.Context) error {
return errors.Wrapf(setConfigSection(ctx, c.SectionId(), bson.M{
"$set": bson.M{
amboyDBURLKey: c.URL,
amboyDBDatabaseKey: c.Database,
}}), "updating config section '%s'", c.SectionId(),
)
}
func (c *AmboyDBConfig) ValidateAndDefault() error {
if c.Database == "" {
c.Database = defaultAmboyDBName
}
return nil
}