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
/
admin.go
76 lines (63 loc) · 1.91 KB
/
admin.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
package admin
import (
"github.com/caos/orbos/internal/operator/boom/api/v1beta2/monitoring/admin"
"github.com/caos/orbos/internal/operator/boom/application/applications/grafana/helm"
"github.com/caos/orbos/internal/operator/boom/application/applications/grafana/info"
"github.com/caos/orbos/internal/operator/boom/application/resources"
"github.com/caos/orbos/internal/operator/boom/labels"
helper2 "github.com/caos/orbos/internal/utils/helper"
"strings"
)
func getSecretName() string {
return strings.Join([]string{"grafana", "admin"}, "-")
}
func getUserKey() string {
return "username"
}
func getPasswordKey() string {
return "password"
}
func GetSecrets(adminSpec *admin.Admin) []interface{} {
namespace := "caos-system"
secrets := make([]interface{}, 0)
if !helper2.IsExistentClientSecret(adminSpec.ExistingSecret) {
if adminSpec.Username.Value == "" && adminSpec.Password.Value == "" {
return secrets
}
data := make(map[string]string, 0)
if adminSpec.Username.Value != "" {
key := getUserKey()
data[key] = adminSpec.Username.Value
}
if adminSpec.Password.Value != "" {
key := getPasswordKey()
data[key] = adminSpec.Password.Value
}
conf := &resources.SecretConfig{
Name: getSecretName(),
Namespace: namespace,
Labels: labels.GetAllApplicationLabels(info.GetName()),
Data: data,
}
secretRes := resources.NewSecret(conf)
secrets = append(secrets, secretRes)
}
return secrets
}
func GetConfig(adminSpec *admin.Admin) *helm.Admin {
if helper2.IsExistentClientSecret(adminSpec.ExistingSecret) {
return &helm.Admin{
ExistingSecret: adminSpec.ExistingSecret.Name,
UserKey: adminSpec.ExistingSecret.IDKey,
PasswordKey: adminSpec.ExistingSecret.SecretKey,
}
}
if len(GetSecrets(adminSpec)) == 0 {
return nil
}
return &helm.Admin{
ExistingSecret: getSecretName(),
UserKey: getUserKey(),
PasswordKey: getPasswordKey(),
}
}