-
Notifications
You must be signed in to change notification settings - Fork 22
/
credhub.go
70 lines (58 loc) · 1.43 KB
/
credhub.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
package test_helpers
import (
"fmt"
"os"
"code.cloudfoundry.org/credhub-cli/credhub"
"code.cloudfoundry.org/credhub-cli/credhub/auth"
)
func NewCredhubClient() (*credhub.CredHub, error) {
uaaCreds := auth.UaaClientCredentials(
os.Getenv("CREDHUB_CLIENT"),
os.Getenv("CREDHUB_SECRET"),
)
chClient, err := credhub.New(
os.Getenv("CREDHUB_SERVER"),
credhub.CaCerts(
os.Getenv("CREDHUB_CA_CERT"),
),
credhub.SkipTLSValidation(true),
credhub.Auth(uaaCreds),
)
return chClient, err
}
func credhubKey(name string) string {
return fmt.Sprintf("%s/%s/%s", BoshCredhubPrefix, os.Getenv("BOSH_DEPLOYMENT"), name)
}
func GetMySQLAdminPassword() (string, error) {
client, err := NewCredhubClient()
if err != nil {
return "", err
}
pw, err := client.GetLatestPassword(credhubKey("cf_mysql_mysql_admin_password"))
if err != nil {
return "", err
}
return string(pw.Value), nil
}
func GetGaleraAgentPassword() (string, error) {
client, err := NewCredhubClient()
if err != nil {
return "", err
}
pw, err := client.GetLatestPassword(credhubKey("cf_mysql_mysql_galera_healthcheck_endpoint_password"))
if err != nil {
return "", err
}
return string(pw.Value), nil
}
func GetProxyPassword() (string, error) {
client, err := NewCredhubClient()
if err != nil {
return "", err
}
pw, err := client.GetLatestPassword(credhubKey("cf_mysql_proxy_api_password"))
if err != nil {
return "", err
}
return string(pw.Value), nil
}