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
/
config.go
64 lines (55 loc) · 1.94 KB
/
config.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
package config
import (
"github.com/caos/orbos/internal/operator/boom/api/v1beta2/reconciling"
"github.com/caos/orbos/internal/operator/boom/application/applications/argocd/config/auth"
"github.com/caos/orbos/internal/operator/boom/application/applications/argocd/config/credential"
"github.com/caos/orbos/internal/operator/boom/application/applications/argocd/config/plugin"
"github.com/caos/orbos/internal/operator/boom/application/applications/argocd/config/repository"
"github.com/caos/orbos/mntr"
"gopkg.in/yaml.v3"
)
type Config struct {
Repositories string `yaml:"repositories,omitempty"`
Credentials string `yaml:"repository.credentials,omitempty"`
Connectors string `yaml:"connectors,omitempty"`
OIDC string `yaml:"oidc,omitempty"`
ConfigManagementPlugins string `yaml:"configManagementPlugins,omitempty"`
}
func GetFromSpec(monitor mntr.Monitor, spec *reconciling.Reconciling) *Config {
conf := &Config{}
dexconfig := auth.GetDexConfigFromSpec(monitor, spec)
data, err := yaml.Marshal(dexconfig)
if err == nil {
conf.Connectors = string(data)
}
repos := repository.GetFromSpec(monitor, spec)
data2, err := yaml.Marshal(repos)
if err == nil {
conf.Repositories = string(data2)
}
creds := credential.GetFromSpec(monitor, spec)
data3, err := yaml.Marshal(creds)
if err == nil {
conf.Credentials = string(data3)
}
oidc, err := auth.GetOIDC(spec.Auth)
if err == nil && oidc != "" {
conf.OIDC = oidc
}
if spec.CustomImage != nil {
plugins := make([]*plugin.Plugin, 0)
init := &plugin.Command{
Command: []string{"gopass", "sync"},
}
generate := &plugin.Command{
Command: []string{"sh", "-c"},
Args: []string{"kustomize build && ./secrets.yaml.sh "},
}
plugins = append(plugins, plugin.New("getSecrets", init, generate))
pluginsYaml, err := yaml.Marshal(plugins)
if err == nil {
conf.ConfigManagementPlugins = string(pluginsYaml)
}
}
return conf
}