-
Notifications
You must be signed in to change notification settings - Fork 15
/
vault_config.go
61 lines (51 loc) · 1.26 KB
/
vault_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
package cmd
import (
"context"
"encoding/json"
"os"
"github.com/cybozu-go/cke"
"github.com/cybozu-go/well"
"github.com/spf13/cobra"
)
// vaultConfigCmd represents the "vault config" command
var vaultConfigCmd = &cobra.Command{
Use: "config FILE|-",
Short: "store parameters to connect Vault",
Long: `Load parameters to connect Vault from a FILE or stdin,
and stores it in etcd.
The parameters are given by a JSON object having these fields:
endpoint: Vault URL.
ca-cert: PEM encoded CA certificate to verify server certificate.
role-id: AppRole ID to login to Vault.
secret-id: AppRole secret to login to Vault.
If the argument is "-", the JSON is read from stdin.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
f := os.Stdin
if args[0] != "-" {
var err error
f, err = os.Open(args[0])
if err != nil {
return err
}
defer f.Close()
}
cfg := new(cke.VaultConfig)
err := json.NewDecoder(f).Decode(cfg)
if err != nil {
return err
}
err = cfg.Validate()
if err != nil {
return err
}
well.Go(func(ctx context.Context) error {
return storage.PutVaultConfig(ctx, cfg)
})
well.Stop()
return well.Wait()
},
}
func init() {
vaultCmd.AddCommand(vaultConfigCmd)
}