- Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathconfig.go
71 lines (58 loc) · 1.78 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
/*
2021 © Postgres.ai
*/
// Package runci provides tools to run and check migrations in CI.
package runci
import (
"os"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
"gitlab.com/postgres-ai/database-lab/v3/internal/platform"
"gitlab.com/postgres-ai/database-lab/v3/internal/runci/source"
"gitlab.com/postgres-ai/database-lab/v3/pkg/util"
)
const (
configFilename="ci_checker.yml"
)
// Config contains a runner configuration.
typeConfigstruct {
AppApp`yaml:"app"`
DLEDLE`yaml:"dle"`
Platform platform.Config`yaml:"platform"`
Source source.Config`yaml:"source"`
RunnerRunner`yaml:"runner"`
}
// App defines a general configuration of the application.
typeAppstruct {
Hoststring`yaml:"host"`
Portuint`yaml:"port"`
VerificationTokenstring`yaml:"verificationToken"`
Debugbool`yaml:"debug"`
}
// DLE describes the configuration of the Database Lab Engine server.
typeDLEstruct {
VerificationTokenstring`yaml:"verificationToken"`
URLstring`yaml:"url"`
DBNamestring`yaml:"dbName"`
Containerstring`yaml:"container"`
}
// Runner defines runner configuration.
typeRunnerstruct {
Imagestring`yaml:"image"`
}
// LoadConfiguration loads configuration of DB Migration Checker.
funcLoadConfiguration() (*Config, error) {
configPath, err:=util.GetConfigPath(configFilename)
iferr!=nil {
returnnil, errors.Wrap(err, "failed to get config path")
}
b, err:=os.ReadFile(configPath)
iferr!=nil {
returnnil, errors.Errorf("error loading %s config file", configPath)
}
cfg:=&Config{}
iferr:=yaml.Unmarshal(b, cfg); err!=nil {
returnnil, errors.WithMessagef(err, "error parsing %s config", configPath)
}
returncfg, nil
}