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
148 lines (124 loc) · 5.07 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package v1beta2
import (
"github.com/caos/orbos/internal/secret"
"github.com/caos/orbos/internal/tree"
"github.com/pkg/errors"
"strings"
)
func ParseToolset(desiredTree *tree.Tree) (*Toolset, error) {
desiredKind := &Toolset{}
if err := desiredTree.Original.Decode(desiredKind); err != nil {
return nil, errors.Wrap(err, "parsing desired state failed")
}
return desiredKind, nil
}
func SecretsFunc(desiredTree *tree.Tree) (secrets map[string]*secret.Secret, err error) {
defer func() {
err = errors.Wrapf(err, "building %s failed", desiredTree.Common.Kind)
}()
desiredKind, err := ParseToolset(desiredTree)
if err != nil {
return nil, errors.Wrap(err, "parsing desired state failed")
}
desiredTree.Parsed = desiredKind
return getSecretsMap(desiredKind), nil
}
func RewriteFunc(desiredTree *tree.Tree, newMasterkey string) (secrets map[string]*secret.Secret, err error) {
defer func() {
err = errors.Wrapf(err, "building %s failed", desiredTree.Common.Kind)
}()
desiredKind, err := ParseToolset(desiredTree)
if err != nil {
return nil, errors.Wrap(err, "parsing desired state failed")
}
desiredTree.Parsed = desiredKind
secret.Masterkey = newMasterkey
return getSecretsMap(desiredKind), nil
}
func getSecretsMap(desiredKind *Toolset) map[string]*secret.Secret {
ret := make(map[string]*secret.Secret, 0)
if desiredKind.Spec.Monitoring != nil {
grafana := desiredKind.Spec.Monitoring
if grafana.Admin != nil {
ret["grafana.admin.username"] = grafana.Admin.Username
ret["grafana.admin.password"] = grafana.Admin.Password
}
if grafana.Auth != nil {
if grafana.Auth.GenericOAuth != nil {
ret["grafana.sso.oauth.clientid"] = secret.InitIfNil(grafana.Auth.GenericOAuth.ClientID)
ret["grafana.sso.oauth.clientsecret"] = secret.InitIfNil(grafana.Auth.GenericOAuth.ClientSecret)
}
if grafana.Auth.Google != nil {
ret["grafana.sso.google.clientid"] = secret.InitIfNil(grafana.Auth.Google.ClientID)
ret["grafana.sso.google.clientsecret"] = secret.InitIfNil(grafana.Auth.Google.ClientSecret)
}
if grafana.Auth.Github != nil {
ret["grafana.sso.github.clientid"] = secret.InitIfNil(grafana.Auth.Github.ClientID)
ret["grafana.sso.github.clientsecret"] = secret.InitIfNil(grafana.Auth.Github.ClientSecret)
}
if grafana.Auth.Gitlab != nil {
ret["grafana.sso.gitlab.clientid"] = secret.InitIfNil(grafana.Auth.Gitlab.ClientID)
ret["grafana.sso.gitlab.clientsecret"] = secret.InitIfNil(grafana.Auth.Gitlab.ClientSecret)
}
}
}
if desiredKind.Spec.Reconciling != nil {
argocd := desiredKind.Spec.Reconciling
if argocd.Auth != nil {
auth := argocd.Auth
if auth.GoogleConnector != nil {
ret["argocd.sso.google.clientid"] = secret.InitIfNil(argocd.Auth.GoogleConnector.Config.ClientID)
ret["argocd.sso.google.clientsecret"] = secret.InitIfNil(argocd.Auth.GoogleConnector.Config.ClientSecret)
ret["argocd.sso.google.serviceaccountjson"] = secret.InitIfNil(argocd.Auth.GoogleConnector.Config.ServiceAccountJSON)
}
if auth.GitlabConnector != nil {
ret["argocd.sso.gitlab.clientid"] = secret.InitIfNil(argocd.Auth.GitlabConnector.Config.ClientID)
ret["argocd.sso.gitlab.clientsecret"] = secret.InitIfNil(argocd.Auth.GitlabConnector.Config.ClientSecret)
}
if auth.OIDC != nil {
ret["argocd.sso.oidc.clientid"] = secret.InitIfNil(argocd.Auth.OIDC.ClientID)
ret["argocd.sso.oidc.clientsecret"] = secret.InitIfNil(argocd.Auth.OIDC.ClientSecret)
}
}
if argocd.Credentials != nil {
for _, value := range argocd.Credentials {
base := strings.Join([]string{"argocd", "credential", value.Name}, ".")
key := strings.Join([]string{base, "username"}, ".")
value.Username = secret.InitIfNil(value.Username)
ret[key] = value.Username
key = strings.Join([]string{base, "password"}, ".")
value.Password = secret.InitIfNil(value.Password)
ret[key] = value.Password
key = strings.Join([]string{base, "certificate"}, ".")
value.Certificate = secret.InitIfNil(value.Certificate)
ret[key] = value.Certificate
}
}
if argocd.Repositories != nil {
for _, value := range argocd.Repositories {
base := strings.Join([]string{"argocd", "repository", value.Name}, ".")
key := strings.Join([]string{base, "username"}, ".")
value.Username = secret.InitIfNil(value.Username)
ret[key] = value.Username
key = strings.Join([]string{base, "password"}, ".")
value.Password = secret.InitIfNil(value.Password)
ret[key] = value.Password
key = strings.Join([]string{base, "certificate"}, ".")
value.Certificate = secret.InitIfNil(value.Certificate)
ret[key] = value.Certificate
}
}
if argocd.CustomImage != nil && argocd.CustomImage.GopassStores != nil {
for _, value := range argocd.CustomImage.GopassStores {
base := strings.Join([]string{"argocd", "gopass", value.StoreName}, ".")
key := strings.Join([]string{base, "ssh"}, ".")
value.SSHKey = secret.InitIfNil(value.SSHKey)
ret[key] = value.SSHKey
key = strings.Join([]string{base, "gpg"}, ".")
value.GPGKey = secret.InitIfNil(value.GPGKey)
ret[key] = value.GPGKey
}
}
}
return ret
}