1package config
2
3func LoadBootstrap(configPath, secretsPath string) (*Config, error) {
4 return loadFile(configPath, secretsPath, false)
5}
6
7func LoadCandidate(origin string, data []byte, secretsPath string) (*Config, error) {
8 cfg, problems := loadBytes(origin, data)
9 return withSecrets(cfg, problems, secretsPath, true)
10}
11
12func CheckSecrets(cfg *Config, secretsPath string) (Secrets, error) {
13 vars, problems := readSecrets(secretsPath)
14 var secrets Secrets
15 if len(problems) == 0 {
16 secrets, problems = checkSecrets(secretsPath, vars, cfg, true)
17 }
18 if len(problems) > 0 {
19 sortProblems(problems)
20 return Secrets{}, &Error{Problems: problems}
21 }
22 return secrets, nil
23}
24
25func exactSet(file string, vars map[string]secretLine, req map[string]bool) []Problem {
26 var problems []Problem
27 for name := range req {
28 if _, ok := vars[name]; !ok {
29 problems = append(problems, Problem{File: file, Key: name, Reason: reasonSecretsMissing})
30 }
31 }
32 for name, v := range vars {
33 if !req[name] {
34 problems = append(problems, Problem{File: file, Line: v.line, Key: name, Reason: reasonSecretsUnexpected})
35 }
36 }
37 return problems
38}
39
40func (c *Config) SameSource(o *Config) bool {
41 if c == nil || o == nil {
42 return c == o
43 }
44 return c.Source == o.Source && c.ConfigGit.source() == o.ConfigGit.source()
45}
46
47func (g *ConfigGit) source() [4]string {
48 if g == nil {
49 return [4]string{}
50 }
51 return [4]string{g.Remote, g.Branch, g.AllowedSigners, g.KnownHosts}
52}