-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (63 loc) · 1.92 KB
/
main.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
package main
import (
"context"
"encoding/json"
"errors"
"flag"
"io/ioutil"
"log"
"path/filepath"
"swisscom/cmd/checker"
. "swisscom/config"
"swisscom/pkg/secrets"
"gopkg.in/yaml.v2"
"k8s.io/client-go/util/homedir"
)
var (
errNotModified = errors.New("not modified")
)
var config_path = flag.String("c", "config/config.yaml", "Path to a config.yaml file")
var cfg *Config
var kubeconfig *string
func main() {
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()
content, err := ioutil.ReadFile(*config_path)
if err != nil {
log.Fatalf("Problem reading configuration file: %v", err)
}
err = yaml.Unmarshal(content, &cfg)
if err != nil {
log.Fatalf("Error parsing configuration file: %v", err)
}
if cfg.K8sCreateSecret == false && cfg.VaultCrearteSecret == false {
panic("k8s_create_secret and vault_create_secret are both equal false, you need to enable at least one")
}
secretFromAWS, currentVerId, err := checker.GetSecretAWS(*cfg)
if err != nil {
log.Fatalf("Error getting secret from AWS: %v", err)
}
secForK8S := make(map[string]string)
err = json.Unmarshal([]byte(secretFromAWS), &secForK8S)
if err != nil {
log.Fatalf("Error unmarshal JSON: %v", err)
}
secForVault := make(map[string]interface{})
err = json.Unmarshal([]byte(secretFromAWS), &secForVault)
if err != nil {
log.Fatalf("Error unmarshal JSON: %v", err)
}
if cfg.VaultCrearteSecret {
secrets.CreateVaultSecret(secForVault, cfg)
}
if cfg.K8sCreateSecret {
secrets.CreateSecretK8s(secForK8S, cfg.SecretNamespace, cfg.KubeSecretName, kubeconfig)
}
ctx, cancel := context.WithCancel(context.Background())
go checker.ScanLoop(ctx, cfg, currentVerId, secForK8S, kubeconfig)
checker.HandleSignals(cancel)
}