forked from Agilicus/kustomize-sops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkustomize-sops.go
43 lines (32 loc) · 836 Bytes
/
kustomize-sops.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
// +build plugin
package main
import (
"go.mozilla.org/sops/decrypt"
"gopkg.in/yaml.v2"
"log"
"path/filepath"
)
type plugin struct{}
var KVSource plugin
func (p plugin) Get(root string, args []string) (map[string]string, error) {
secret := make(map[string]string)
secret_file := filepath.Join(root, "secrets.enc.yaml")
v, err := decrypt.File(secret_file, "yaml")
if err != nil {
log.Fatalf("error: cannot decode file %s :: %v", secret_file, err)
}
err = yaml.Unmarshal([]byte(v), &secret)
if err != nil {
log.Fatalf("error: cannot unmarshal secrets.enc.yaml as yaml in %s :: %v", root, err)
}
r := make(map[string]string)
for _, k := range args {
v, ok := secret[k]
if ok {
r[k] = v
} else {
log.Fatalf("error: key <%s> not present in secrets.enc.yaml in %s\n", k, root)
}
}
return r, nil
}