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
|
package main
import (
"errors"
"os"
"gopkg.in/yaml.v3"
)
type C2ECConfig struct {
Server C2ECServerConfig `yaml:"c2ec"`
Database C2ECDatabseConfig `yaml:"db"`
Providers []C2ECProviderConfig `yaml:"providers"`
}
type C2ECServerConfig struct {
IsProd bool `yaml:"prod"`
Host string `yaml:"host"`
Port int `yaml:"port"`
UseUnixDomainSocket bool `yaml:"unix-domain-socket"`
UnixSocketPath string `yaml:"unix-socket-path"`
StrictAttestors bool `yaml:"fail-on-missing-attestors"`
CreditAccount string `yaml:"credit-account"`
WireGateway C2ECWireGatewayConfig `yaml:"wire-gateway"`
}
type C2ECWireGatewayConfig struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
}
type C2ECDatabseConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Database string `yaml:"database"`
}
type C2ECProviderConfig struct {
Name string `yaml:"name"`
CredentialsPassword string `yaml:"credentials-password"`
}
func Parse(path string) (*C2ECConfig, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
stat, err := f.Stat()
if err != nil {
return nil, err
}
content := make([]byte, stat.Size())
_, err = f.Read(content)
if err != nil {
return nil, err
}
cfg := new(C2ECConfig)
err = yaml.Unmarshal(content, cfg)
if err != nil {
return nil, err
}
return cfg, nil
}
func ConfigForProvider(name string) (*C2ECProviderConfig, error) {
for _, provider := range CONFIG.Providers {
if provider.Name == name {
return &provider, nil
}
}
return nil, errors.New("no such provider")
}
|