This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
funcs.go
124 lines (105 loc) · 4.35 KB
/
funcs.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package v1beta2
import (
"github.com/caos/orbos/internal/operator/boom/api/v1beta2/monitoring"
"github.com/caos/orbos/internal/operator/boom/api/v1beta2/reconciling"
"github.com/caos/orbos/internal/secret"
"github.com/caos/orbos/internal/tree"
"github.com/pkg/errors"
"strings"
)
func ParseToolset(desiredTree *tree.Tree) (*Toolset, map[string]*secret.Secret, error) {
desiredKind := &Toolset{}
if err := desiredTree.Original.Decode(desiredKind); err != nil {
return nil, nil, errors.Wrap(err, "parsing desired state failed")
}
desiredTree.Parsed = desiredKind
return desiredKind, GetSecretsMap(desiredKind), nil
}
func GetSecretsMap(desiredKind *Toolset) map[string]*secret.Secret {
ret := make(map[string]*secret.Secret, 0)
if desiredKind.Spec.Monitoring == nil {
desiredKind.Spec.Monitoring = &monitoring.Monitoring{}
}
grafanaSpec := desiredKind.Spec.Monitoring
grafanaSpec.InitSecrets()
ret["grafana.admin.username"] = grafanaSpec.Admin.Username
ret["grafana.admin.password"] = grafanaSpec.Admin.Password
ret["grafana.sso.oauth.clientid"] = grafanaSpec.Auth.GenericOAuth.ClientID
ret["grafana.sso.oauth.clientsecret"] = grafanaSpec.Auth.GenericOAuth.ClientSecret
ret["grafana.sso.google.clientid"] = grafanaSpec.Auth.Google.ClientID
ret["grafana.sso.google.clientsecret"] = grafanaSpec.Auth.Google.ClientSecret
ret["grafana.sso.github.clientid"] = grafanaSpec.Auth.Github.ClientID
ret["grafana.sso.github.clientsecret"] = grafanaSpec.Auth.Github.ClientSecret
ret["grafana.sso.gitlab.clientid"] = grafanaSpec.Auth.Gitlab.ClientID
ret["grafana.sso.gitlab.clientsecret"] = grafanaSpec.Auth.Gitlab.ClientSecret
if desiredKind.Spec.Reconciling == nil {
desiredKind.Spec.Reconciling = &reconciling.Reconciling{}
}
argocdSpec := desiredKind.Spec.Reconciling
argocdSpec.InitSecrets()
ret["argocd.sso.google.clientid"] = argocdSpec.Auth.GoogleConnector.Config.ClientID
ret["argocd.sso.google.clientsecret"] = argocdSpec.Auth.GoogleConnector.Config.ClientSecret
ret["argocd.sso.google.serviceaccountjson"] = argocdSpec.Auth.GoogleConnector.Config.ServiceAccountJSON
ret["argocd.sso.gitlab.clientid"] = argocdSpec.Auth.GitlabConnector.Config.ClientID
ret["argocd.sso.gitlab.clientsecret"] = argocdSpec.Auth.GitlabConnector.Config.ClientSecret
ret["argocd.sso.github.clientid"] = argocdSpec.Auth.GithubConnector.Config.ClientID
ret["argocd.sso.github.clientsecret"] = argocdSpec.Auth.GithubConnector.Config.ClientSecret
ret["argocd.sso.oidc.clientid"] = argocdSpec.Auth.OIDC.ClientID
ret["argocd.sso.oidc.clientsecret"] = argocdSpec.Auth.OIDC.ClientSecret
if argocdSpec.Credentials != nil {
for _, value := range argocdSpec.Credentials {
base := strings.Join([]string{"argocd", "credential", value.Name}, ".")
key := strings.Join([]string{base, "username"}, ".")
if value.Username == nil {
value.Username = &secret.Secret{}
}
ret[key] = value.Username
key = strings.Join([]string{base, "password"}, ".")
if value.Password == nil {
value.Password = &secret.Secret{}
}
ret[key] = value.Password
key = strings.Join([]string{base, "certificate"}, ".")
if value.Certificate == nil {
value.Certificate = &secret.Secret{}
}
ret[key] = value.Certificate
}
}
if argocdSpec.Repositories != nil {
for _, value := range argocdSpec.Repositories {
base := strings.Join([]string{"argocd", "repository", value.Name}, ".")
key := strings.Join([]string{base, "username"}, ".")
if value.Username == nil {
value.Username = &secret.Secret{}
}
ret[key] = value.Username
key = strings.Join([]string{base, "password"}, ".")
if value.Password == nil {
value.Password = &secret.Secret{}
}
ret[key] = value.Password
key = strings.Join([]string{base, "certificate"}, ".")
if value.Certificate == nil {
value.Certificate = &secret.Secret{}
}
ret[key] = value.Certificate
}
}
if argocdSpec.CustomImage != nil && argocdSpec.CustomImage.GopassStores != nil {
for _, value := range argocdSpec.CustomImage.GopassStores {
base := strings.Join([]string{"argocd", "gopass", value.StoreName}, ".")
key := strings.Join([]string{base, "ssh"}, ".")
if value.SSHKey == nil {
value.SSHKey = &secret.Secret{}
}
ret[key] = value.SSHKey
key = strings.Join([]string{base, "gpg"}, ".")
if value.GPGKey == nil {
value.GPGKey = &secret.Secret{}
}
ret[key] = value.GPGKey
}
}
return ret
}