-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
200 lines (192 loc) · 9.34 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package main
import (
"io"
"log"
"os"
"runtime/debug"
cmd "github.com/DelineaXPM/dsv-cli/commands"
cst "github.com/DelineaXPM/dsv-cli/constants"
"github.com/DelineaXPM/dsv-cli/format"
"github.com/DelineaXPM/dsv-cli/utils"
"github.com/DelineaXPM/dsv-cli/version"
"github.com/mitchellh/cli"
"github.com/spf13/viper"
)
func main() {
defer func() {
if v := recover(); v != nil {
out := format.NewDefaultOutClient()
if viper.GetString(cst.Verbose) == "" {
out.FailS("An unknown error occurred. Use the verbose flag (-v) to see more information.")
} else {
err, ok := v.(error)
if ok {
out.Fail(err)
}
out.FailS(string(debug.Stack()))
}
}
}()
exitStatus, err := runCLI(os.Args)
if err != nil {
format.NewDefaultOutClient().Fail(err)
os.Exit(utils.GetExecStatus(err))
}
os.Exit(exitStatus)
}
func runCLI(args []string) (exitStatus int, err error) {
c := cli.NewCLI(cst.CmdRoot, version.Version)
c.Args = args[1:]
c.Name = cst.CmdRoot
c.Commands = map[string]cli.CommandFactory{
"secret": cmd.GetSecretCmd,
"secret read": cmd.GetSecretReadCmd,
"secret describe": cmd.GetSecretDescribeCmd,
"secret search": cmd.GetSecretSearchCmd,
"secret delete": cmd.GetSecretDeleteCmd,
"secret restore": cmd.GetSecretRestoreCmd,
"secret create": cmd.GetSecretCreateCmd,
"secret update": cmd.GetSecretUpdateCmd,
"secret rollback": cmd.GetSecretRollbackCmd,
"secret edit": cmd.GetSecretEditCmd,
"secret bustcache": cmd.GetSecretBustCacheCmd,
"policy": cmd.GetPolicyCmd,
"policy read": cmd.GetPolicyReadCmd,
"policy search": cmd.GetPolicySearchCmd,
"policy delete": cmd.GetPolicyDeleteCmd,
"policy restore": cmd.GetPolicyRestoreCmd,
"policy create": cmd.GetPolicyCreateCmd,
"policy edit": cmd.GetPolicyEditCmd,
"policy update": cmd.GetPolicyUpdateCmd,
"policy rollback": cmd.GetPolicyRollbackCmd,
"auth": cmd.GetAuthCmd,
"auth clear": cmd.GetAuthClearCmd,
"auth list": cmd.GetAuthListCmd,
"auth change-password": cmd.GetAuthChangePasswordCmd,
"user": cmd.GetUserCmd,
"user read": cmd.GetUserReadCmd,
"user search": cmd.GetUserSearchCmd,
"user delete": cmd.GetUserDeleteCmd,
"user restore": cmd.GetUserRestoreCmd,
"user create": cmd.GetUserCreateCmd,
"user update": cmd.GetUserUpdateCmd,
"whoami": cmd.GetWhoAmICmd,
"eval": cmd.GetEvaluateFlagCmd,
"cli-config": cmd.GetCliConfigCmd,
"init": cmd.GetCliConfigInitCmd,
"cli-config init": cmd.GetCliConfigInitCmd,
"cli-config update": cmd.GetCliConfigUpdateCmd,
"cli-config clear": cmd.GetCliConfigClearCmd,
"cli-config read": cmd.GetCliConfigReadCmd,
"cli-config edit": cmd.GetCliConfigEditCmd,
"cli-config use-profile": cmd.GetCliConfigUseProfileCmd,
"config": cmd.GetConfigCmd,
"config read": cmd.GetConfigReadCmd,
"config update": cmd.GetConfigUpdateCmd,
"config edit": cmd.GetConfigEditCmd,
"config auth-provider": cmd.GetAuthProviderCmd,
"config auth-provider read": cmd.GetAuthProviderReadCmd,
"config auth-provider search": cmd.GetAuthProviderSearchCmd,
"config auth-provider delete": cmd.GetAuthProviderDeleteCmd,
"config auth-provider restore": cmd.GetAuthProviderRestoreCmd,
"config auth-provider create": cmd.GetAuthProviderCreateCmd,
"config auth-provider update": cmd.GetAuthProviderUpdateCmd,
"config auth-provider edit": cmd.GetAuthProviderEditCmd,
"config auth-provider rollback": cmd.GetAuthProviderRollbackCmd,
"role": cmd.GetRoleCmd,
"role read": cmd.GetRoleReadCmd,
"role search": cmd.GetRoleSearchCmd,
"role delete": cmd.GetRoleDeleteCmd,
"role restore": cmd.GetRoleRestoreCmd,
"role create": cmd.GetRoleCreateCmd,
"role update": cmd.GetRoleUpdateCmd,
"client": cmd.GetClientCmd,
"client read": cmd.GetClientReadCmd,
"client delete": cmd.GetClientDeleteCmd,
"client restore": cmd.GetClientRestoreCmd,
"client create": cmd.GetClientCreateCmd,
"client search": cmd.GetClientSearchCmd,
"usage": cmd.GetUsageCmd,
"audit": cmd.GetAuditSearchCmd,
"group": cmd.GetGroupCmd,
"group read": cmd.GetGroupReadCmd,
"group create": cmd.GetGroupCreateCmd,
"group delete": cmd.GetGroupDeleteCmd,
"group restore": cmd.GetGroupRestoreCmd,
"group search": cmd.GetGroupSearchCmd,
"group add-members": cmd.GetAddMembersCmd,
"user groups": cmd.GetMemberGroupsCmd,
"group delete-members": cmd.GetDeleteMembersCmd,
"pki": cmd.GetPkiCmd,
"pki register": cmd.GetPkiRegisterCmd,
"pki sign": cmd.GetPkiSignCmd,
"pki leaf": cmd.GetPkiLeafCmd,
"pki generate-root": cmd.GetPkiGenerateRootCmd,
"pki ssh-cert": cmd.GetPkiSSHCertCmd,
"siem": cmd.GetSiemCmd,
"siem create": cmd.GetSiemCreateCmd,
"siem update": cmd.GetSiemUpdateCmd,
"siem read": cmd.GetSiemReadCmd,
"siem search": cmd.GetSiemSearchCmd,
"siem delete": cmd.GetSiemDeleteCmd,
"home": cmd.GetHomeCmd,
"home read": cmd.GetHomeReadCmd,
"home create": cmd.GetHomeCreateCmd,
"home update": cmd.GetHomeUpdateCmd,
"home delete": cmd.GetHomeDeleteCmd,
"home search": cmd.GetHomeSearchCmd,
"home describe": cmd.GetHomeDescribeCmd,
"home edit": cmd.GetHomeEditCmd,
"home rollback": cmd.GetHomeRollbackCmd,
"home restore": cmd.GetHomeRestoreCmd,
"pool": cmd.GetPoolCmd,
"pool create": cmd.GetPoolCreateCmd,
"pool read": cmd.GetPoolReadCmd,
"pool list": cmd.GetPoolListCmd,
"pool delete": cmd.GetPoolDeleteCmd,
"engine": cmd.GetEngineCmd,
"engine read": cmd.GetEngineReadCmd,
"engine list": cmd.GetEngineListCmd,
"engine create": cmd.GetEngineCreateCmd,
"engine delete": cmd.GetEngineDeleteCmd,
"engine ping": cmd.GetEnginePingCmd,
"crypto": cmd.GetCryptoCmd,
"crypto auto": cmd.GetCryptoCmd,
"crypto key-create": cmd.GetAutoKeyCreateCmd,
"crypto key-read": cmd.GetAutoKeyReadMetadataCmd,
"crypto key-delete": cmd.GetAutoKeyDeleteCmd,
"crypto key-restore": cmd.GetAutoKeyRestoreCmd,
"crypto encrypt": cmd.GetEncryptCmd,
"crypto decrypt": cmd.GetDecryptCmd,
"crypto rotate": cmd.GetEncryptionRotateCmd,
"crypto auto key-create": cmd.GetAutoKeyCreateCmd,
"crypto auto key-read": cmd.GetAutoKeyReadMetadataCmd,
"crypto auto key-delete": cmd.GetAutoKeyDeleteCmd,
"crypto auto key-restore": cmd.GetAutoKeyRestoreCmd,
"crypto auto encrypt": cmd.GetEncryptCmd,
"crypto auto decrypt": cmd.GetDecryptCmd,
"crypto auto rotate": cmd.GetEncryptionRotateCmd,
"crypto manual": cmd.GetCryptoManualCmd,
"crypto manual key-upload": cmd.GetManualKeyUploadCmd,
"crypto manual key-update": cmd.GetManualKeyUpdateCmd,
"crypto manual key-read": cmd.GetManualKeyReadCmd,
"crypto manual key-delete": cmd.GetManualKeyDeleteCmd,
"crypto manual key-restore": cmd.GetManualKeyRestoreCmd,
"crypto manual encrypt": cmd.GetManualKeyEncryptCmd,
"crypto manual decrypt": cmd.GetManualKeyDecryptCmd,
"report": cmd.GetReportCmd,
"report secret": cmd.GetSecretReportCmd,
"report group": cmd.GetGroupReportCmd,
"breakglass": cmd.GetBreakGlassCmd,
"breakglass status": cmd.GetBreakGlassGetStatusCmd,
"breakglass generate": cmd.GetBreakGlassGenerateCmd,
"breakglass apply": cmd.GetBreakGlassApplyCmd,
"byok": cmd.GetBYOKCmd,
"byok update": cmd.GetBYOKUpdateCmd,
}
c.Autocomplete = true
c.AutocompleteInstall = "install"
c.AutocompleteUninstall = "uninstall"
log.SetOutput(io.Discard)
return c.Run()
}