/
config_general_secrets.go
66 lines (59 loc) · 1.83 KB
/
config_general_secrets.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
package chainlink
import (
"fmt"
"net/url"
"strings"
"github.com/pkg/errors"
)
func (g *generalConfig) DatabaseURL() url.URL {
if g.secrets.Database.URL == nil {
return url.URL{}
}
return *g.secrets.Database.URL.URL()
}
func (g *generalConfig) DatabaseBackupURL() *url.URL {
return g.secrets.Database.BackupURL.URL()
}
func (g *generalConfig) ExplorerAccessKey() string {
if g.secrets.Explorer.AccessKey == nil {
return ""
}
return string(*g.secrets.Explorer.AccessKey)
}
func (g *generalConfig) ExplorerSecret() string {
if g.secrets.Explorer.Secret == nil {
return ""
}
return string(*g.secrets.Explorer.Secret)
}
func (g *generalConfig) PyroscopeAuthToken() string {
if g.secrets.Pyroscope.AuthToken == nil {
return ""
}
return string(*g.secrets.Pyroscope.AuthToken)
}
func (g *generalConfig) MercuryCredentials(url string) (username, password string, err error) {
if g.secrets.Mercury.Credentials == nil {
return "", "", errors.New("no Mercury credentials were specified in the config")
}
for _, creds := range g.secrets.Mercury.Credentials {
if creds.URL != nil && creds.URL.URL().String() == url {
if creds.Username == nil {
return "", "", errors.Errorf("no Mercury username specified for server URL: %q", url)
}
if creds.Password == nil {
return "", "", errors.Errorf("no Mercury password specified for server URL: %q", url)
}
return string(*creds.Username), string(*creds.Password), nil
}
}
msg := fmt.Sprintf("no Mercury credentials specified for server URL: %q", url)
if len(g.secrets.Mercury.Credentials) > 0 {
urls := make([]string, len(g.secrets.Mercury.Credentials))
for i, creds := range g.secrets.Mercury.Credentials {
urls[i] = creds.URL.String()
}
msg += fmt.Sprintf(" (credentials available for these urls: %s)", strings.Join(urls, ","))
}
return "", "", errors.New(msg)
}