-
Notifications
You must be signed in to change notification settings - Fork 0
/
secrets_generate.go
104 lines (87 loc) · 2 KB
/
secrets_generate.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package generate
import (
"fmt"
"github.com/Coinmaxify/Coinmaxify/command"
"github.com/spf13/cobra"
"github.com/Coinmaxify/Coinmaxify/secrets"
)
func GetCommand() *cobra.Command {
secretsGenerateCmd := &cobra.Command{
Use: "generate",
Short: "Initializes the secrets manager configuration in the provided directory. Used for Hashicorp Vault",
Run: runCommand,
}
setFlags(secretsGenerateCmd)
setRequiredFlags(secretsGenerateCmd)
return secretsGenerateCmd
}
func setFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(
¶ms.dir,
dirFlag,
defaultConfigFileName,
fmt.Sprintf(
"the directory for the secrets manager configuration file Default: %s",
defaultConfigFileName,
),
)
cmd.Flags().StringVar(
¶ms.token,
tokenFlag,
"",
"the access token for the service",
)
cmd.Flags().StringVar(
¶ms.serverURL,
serverURLFlag,
"",
"the server URL for the service",
)
cmd.Flags().StringVar(
¶ms.serviceType,
typeFlag,
string(secrets.HashicorpVault),
fmt.Sprintf(
"the type of the secrets manager. Default: %s",
secrets.HashicorpVault,
),
)
cmd.Flags().StringVar(
¶ms.name,
nameFlag,
defaultNodeName,
fmt.Sprintf(
"the name of the node for on-service record keeping. Default: %s",
defaultNodeName,
),
)
cmd.Flags().StringVar(
¶ms.namespace,
namespaceFlag,
defaultNamespace,
fmt.Sprintf(
"the namespace for the service. Default %s",
defaultNamespace,
),
)
cmd.Flags().StringVar(
¶ms.extra,
extraFlag,
"",
"Specifies the extra fields map in string format 'key1=val1,key2=val2'",
)
}
func setRequiredFlags(cmd *cobra.Command) {
for _, requiredFlag := range params.getRequiredFlags() {
_ = cmd.MarkFlagRequired(requiredFlag)
}
}
func runCommand(cmd *cobra.Command, _ []string) {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()
if err := params.writeSecretsConfig(); err != nil {
outputter.SetError(err)
return
}
outputter.SetCommandResult(params.getResult())
}