-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
80 lines (64 loc) · 1.88 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
72
73
74
75
76
77
78
79
80
package main
import (
"flag"
"fmt"
"go.uber.org/zap"
)
var (
logger, _ = zap.NewProduction()
providers = map[string]SecretProvider{
"gcp": &GCPSecretManager{},
"aws": &AWSSecretManager{},
}
templates = map[string]string{
"plaintext": `export {{ .Name | ToUpper }}="{{ .Data }}"`,
"json": `export {{ .Name | ToUpper }}_{{ .ContentKey | ToUpper }}="{{ .ContentValue }}"`,
}
parsers = map[string]ContentParser{
"plaintext": &NoParser{},
"json": &JSONContentParser{},
}
tmplLoop = `{{ range . }}
%s
{{- end -}}
`
)
const (
AssumeRoleKey = "assume-role"
)
// Options represents the command line options
type Options struct {
Provider string
AssumeRole string
Project string
Filter string
Parser string
Template string
Output string
}
func (o *Options) String() string {
return fmt.Sprintf(
"provider: %s, project: %s, filter: %s, parser: %s, template: %s, output: %s",
o.Provider, o.Project, o.Filter, o.Parser, o.Template, o.Output,
)
}
func main() {
options := &Options{}
flag.StringVar(&options.Provider, "provider", "gcp", "name of the provider that manages the secrets")
flag.StringVar(&options.AssumeRole, "assume-role", "", "role to assume when using aws provider")
flag.StringVar(&options.Project, "project", "", "gcp project that contains the secrets")
flag.StringVar(&options.Filter, "filter", "", "regex to filter secrets by name")
flag.StringVar(&options.Parser, "data-parser", "plaintext", "parse secret based on data type")
flag.StringVar(&options.Template, "template", "", "template to render secret data")
flag.StringVar(&options.Output, "output", "", "path to write output file to")
v := flag.Bool("version", false, "show the current secrets-init version")
flag.Parse()
if *v {
GetHumanVersion()
return
}
err := Run(options)
if err != nil {
logger.Fatal("error getting the secrets", zap.Error(err))
}
}