-
Notifications
You must be signed in to change notification settings - Fork 2
/
runner.go
75 lines (59 loc) · 1.3 KB
/
runner.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
package main
import (
"errors"
"os"
"go.uber.org/zap"
)
var (
ErrProjectNotFound = errors.New("project is required")
ErrUnsupportedProvider = errors.New("unsupported provider")
ErrUnsupportedParser = errors.New("unsupported parser")
)
func Run(options *Options) error {
provider, ok := providers[options.Provider]
if !ok {
return ErrUnsupportedProvider
}
if provider.Name() == "gcp" && options.Project == "" {
return ErrProjectNotFound
}
parser, ok := parsers[options.Parser]
if !ok {
return ErrUnsupportedParser
}
template := templates[options.Parser]
if options.Template != "" {
template = options.Template
}
logger.Info("using options", zap.Any("values", options))
params := map[string]string{
AssumeRoleKey: options.AssumeRole,
}
if err := provider.Init(params); err != nil {
return err
}
data, err := provider.ListSecrets(options.Project, options.Filter)
if err != nil {
return err
}
logger.Info("secrets found", zap.Int("len", len(data)))
output := os.Stdin
if options.Output != "" {
output, err = os.Create(options.Output)
if err != nil {
return err
}
}
w, err := NewWriter(output, template)
if err != nil {
return err
}
for _, v := range data {
e := parser.Parse(v)
err := w.Write(e...)
if err != nil {
return err
}
}
return nil
}