-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_config.go
62 lines (54 loc) · 1021 Bytes
/
cmd_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
package main
import (
"os"
"github.com/urfave/cli"
"gopkg.in/yaml.v2"
)
func configCommand(kmsFlags []cli.Flag) cli.Command {
return cli.Command{
Name: "config",
Usage: "Create .kms-vault.yaml",
Flags: append([]cli.Flag{
cli.BoolFlag{
Name: "w",
Usage: "Write to .kms-vault.yaml.",
},
}, kmsFlags...),
Action: configAction,
}
}
type VaultConfig struct {
Project string
Location string
KeyRing string
Key string
}
func configAction(c *cli.Context) error {
val, err := yaml.Marshal(VaultConfig{
Project: c.String("project"),
Location: c.String("location"),
KeyRing: c.String("keyring"),
Key: c.String("key"),
})
if err != nil {
return err
}
output := os.Stdout
if c.Bool("w") {
err := checkOverwrite(vaultConfigFilename)
if err != nil {
return err
}
fp, err := os.Create(vaultConfigFilename)
if err != nil {
return err
}
defer fp.Close()
output = fp
}
_, err = output.Write(val)
if err != nil {
return err
}
return nil
}