]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/vault/_vault
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / vault / _vault
1 #compdef vault
2
3 typeset -a main_args
4 main_args=(
5     '(-version)-version[Prints the Vault version]'
6     '(-help)-help[Prints Vault Help]'
7 )
8
9 typeset -a general_args
10 general_args=(
11     '(-help)-help[Prints Help]'
12     '(-address)-address=-[The address of the Vault server. Overrides the VAULT_ADDR environment variable if set.]:address:'
13     '(-ca-cert)-ca-cert=-[Path to a PEM encoded CA cert file to use to verify the Vault server SSL certificate. Overrides the VAULT_CACERT environment variable if set.]:file:_files -g "*.pem"'
14     '(-ca-path)-ca-path=-[Path to a directory of PEM encoded CA cert files to verify the Vault server SSL certificate. If both -ca-cert and -ca-path are specified, -ca-path is used.Overrides the VAULT_CAPATH environment variable if set.]:directory:_directories'
15     '(-client-cert)-client-cert=-[Path to a PEM encoded client certificate for TLS authentication to the Vault server. Must also specify -client-key. Overrides the VAULT_CLIENT_CERT environment variable if set.]:file:_files -g "*.pem"'
16     '(-client-key)-client-key=-[Path to an unencrypted PEM encoded private key matching the client certificate from -client-cert. Overrides the VAULT_CLIENT_KEY environment variable if set.]:file:_files -g "*.pem"'
17     '(-tls-skip-verify)-tls-skip-verify[Do not verify TLS certificate. This is highly not recommended. Verification will also be skipped if VAULT_SKIP_VERIFY is set.]'
18 )
19
20 typeset -a audit_enable_args
21 audit_enable_args=(
22     '(-description)-description=-[A human-friendly description for the backend. This shows up only when querying the enabled backends.]:description:'
23     '(-id)-id=-[Specify a unique ID for this audit backend. This is purely for referencing this audit backend. By default this will be the backend type.]:id:'
24 )
25
26 typeset -a auth_args
27 auth_args=(
28     '(-method)-method=-[Outputs help for the authentication method with the given name for the remote server. If this authentication method is not available, exit with code 1.]:method:(cert ldap github userpass app-id)'
29     '(-method-help)-method-help[If set, the help for the selected method will be shown.]'
30     '(-methods)-methods[List the available auth methods.]'
31     '(-no-verify)-no-verify[Do not verify the token after creation; avoids a use count]'
32 )
33
34 typeset -a auth_enable_args
35 auth_enable_args=(
36     '(-description)-description=-[Human-friendly description of the purpose for the auth provider. This shows up in the auth-list command.]:description:'
37     '(-path)-path=-[Mount point for the auth provider. This defaults to the type of the mount. This will make the auth provider available at "/auth/<path>"]:path:'
38 )
39
40 typeset -a init_args
41 init_args=(
42     '(-key-shares)-key-shares=-[(default: 5) The number of key shares to split the master key into.]:keyshares:'
43     '(-key-threshold)-key-threshold=-[(default: 3) The number of key shares required to reconstruct the master key.]:keythreshold:'
44     '(-pgp-keys)-pgp-keys[If provided, must be a comma-separated list of files on disk containing binary- or base64-format public PGP keys. The number of files must match "key-shares". The output unseal keys will encrypted and hex-encoded, in order, with the given public keys. If you want to use them with the "vault unseal" command, you will need to hex decode and decrypt; this will be the plaintext unseal key.]:pgpkeys:_files'
45 )
46
47 typeset -a mount_tune_args
48 mount_tune_args=(
49     '(-default-lease-ttl)-default-lease-ttl=-[Default lease time-to-live for this backend. If not specified, uses the system default, or the previously set value. Set to "system" to explicitly set it to use the system default.]:defaultleasettl:'
50     '(-max-lease-ttl)-max-lease-ttl=-[Max lease time-to-live for this backend. If not specified, uses the system default, or the previously set value. Set to "system" to explicitly set it to use the system default.]:maxleasettl:'
51 )
52
53 typeset -a mount_args
54 mount_args=(
55     $mount_tune_args
56     '(-path)-path=-[Mount point for the logical backend. This defaults to the type of the mount.]:path:'
57     '(-description)-description=-[Human-friendly description of the purpose for the mount. This shows up in the mounts command.]:description:'
58 )
59
60 typeset -a rekey_args
61 rekey_args=(
62     $init_args
63     '(-init)-init[Initialize the rekey operation by setting the desired number of shares and the key threshold. This can only be done if no rekey is already initiated.]:init:'
64     '(-cancel)-cancel[Reset the rekey process by throwing away prior keys and the rekey configuration.]:cancel:'
65     '(-status)-status[Prints the status of the current rekey operation. This can be used to see the status without attempting to provide an unseal key.]:status:'
66 )
67
68 typeset -a ssh_args
69 ssh_args=(
70     '(-role)-role[Role to be used to create the key. ]:role:'
71     '(-no-exec)-no-exec[Shows the credentials but does not establish connection.]:noexec:'
72     '(-mount-point)-mount-point[Mount point of SSH backend. If the backend is mounted at "ssh", which is the default as well, this parameter can be skipped.]:mountpoint:'
73     '(-format)-format[If no-exec option is enabled, then the credentials will be printed out and SSH connection will not be established. The format of the output can be "json" or "table". JSON output is useful when writing scripts. Default is "table".]:format:(json table)'
74 )
75
76 typeset -a token_create_args
77 token_create_args=(
78     '(-id)-id=-[The token value that clients will use to authenticate with vault. If not provided this defaults to a 36 character UUID. A root token is required to specify the ID of a token.]:id:'
79     '(-display-name)-display-name=-[A display name to associate with this token. This is a non-security sensitive value used to help identify created secrets, i.e. prefixes.]:displayname:'
80     '(-ttl)-ttl=-[TTL to associate with the token. This option enables the tokens to be renewable.]:ttl:'
81     '*-metadata=-[Metadata to associate with the token. This shows up in the audit log. This can be specified multiple times.]:metadata:'
82     '(-orphan)-orphan[If specified, the token will have no parent. Only root tokens can create orphan tokens. This prevents the new token from being revoked with your token.]:orphan:'
83     '(-no-default-policy)-no-default-policy[If specified, the token will not have the "default" policy included in its policy set.]:nodefaultpolicy:'
84     '*-policy=-[Policy to associate with this token. This can be specified multiple times.]:policy:__vault_policies'
85     '(-use-limit)-use-limit=-[The number of times this token can be used until it is automatically revoked.]:uselimit:'
86     '(-format)-format=-[The format for output. By default it is a whitespace-delimited table. This can also be json.]:format:(json table)'
87 )
88
89 typeset -a server_args
90 server_args=(
91     '*-config=-[Path to the configuration file or directory. This can be specified multiple times. If it is a directory, all files with a ".hcl" or ".json" suffix will be loaded.]:config:_files'
92     '-dev[Enables Dev mode. In this mode, Vault is completely in-memory and unsealed. Do not run the Dev server in production!]:dev:'
93     '-log-level=-[Log verbosity. Defaults to "info", will be outputtedto stderr. Supported values: "trace", "debug", "info", "warn", "err"]:loglevel:(trace debug info warn err)'
94 )
95
96 _vault_audit-list() {
97     _arguments : \
98         ${general_args[@]} && ret=0
99 }
100
101 _vault_audit-disable() {
102     # vault audit-list doesn't print the backend id so for now
103     # no *smart* autocompletion for this subcommand.
104     _arguments : \
105         ${general_args[@]} \
106         ':::(file syslog)' && ret=0
107 }
108
109 _vault_audit-enable() {
110     _arguments : \
111         ${general_args[@]} \
112         ${audit_enable_args[@]} \
113         ': :->backends' \
114         '*:: :->backendconfig' && ret=0
115
116     case $state in
117         backends)
118             local -a backends
119             backends=(
120                 'file:The "file" audit backend writes audit logs to a file.'
121                 'syslog:The "syslog" audit backend writes audit logs to syslog.'
122             )
123             _describe -t backends 'vault audit backends' backends && ret=0
124             ;;
125         backendconfig)
126             case ${line[1]} in
127                 file)
128                     _values -w "Audit Backend File" \
129                         'path[(required) - The path to where the file will be written. If this path exists, the audit backend will append to it.]:file:_files' \
130                         'log_raw[(optional) Should security sensitive information be logged raw. Defaults to "false".]:log_raw:(true false)' && ret=0
131                     ;;
132                 syslog)
133                     _values -w "Audit Backend Syslog" \
134                         'facility[(optional) - The syslog facility to use. Defaults to "AUTH".]:facility:(kern user mail daemon auth syslog lpr news uucp authpriv ftp cron local0 local1 local2 local3 local4 local5 local6 local7)' \
135                         'tag[(optional) - The syslog tag to use. Defaults to "vault".]:tag:' \
136                         'log_raw[(optional) Should security sensitive information be logged raw.]:log_raw:(true false)' && ret=0
137                             ;;
138             esac
139             ;;
140     esac
141 }
142
143 _vault_auth() {
144     _arguments : \
145         ${general_args[@]} \
146         ${auth_args[@]} && ret=0
147 }
148
149 _vault_auth-enable() {
150     _arguments : \
151         ${general_args[@]} \
152         ${auth_enable_args[@]} \
153         ':::(cert ldap github userpass app-id)' && ret=0
154 }
155
156 __vault_auth_methods() {
157     local -a authmethods
158     authmethods=($(vault auth -methods | awk 'NR>1{split ($1,a,"/"); print a[1]":["$2"]"}'))
159     _describe -t authmethods 'authmethods' authmethods && ret=0
160 }
161
162 _vault_auth-disable() {
163     _arguments : \
164         ${general_args[@]} \
165         ':::__vault_auth_methods' && ret=0
166
167 }
168
169 _vault_init() {
170     _arguments : \
171         ${general_args[@]} \
172         ${init_args[@]} && ret=0
173 }
174
175 _vault_key-status() {
176     _arguments : \
177         ${general_args[@]} && ret=0
178 }
179
180 __vault_mounts() {
181     local -a mounts
182     mounts=($(vault mounts | awk 'NR>1{split ($1,a,"/"); print a[1]":["$2"]"}'))
183     _describe -t mounts 'mounts' mounts && ret=0
184 }
185
186 _vault_mounts() {
187     _arguments : \
188         ${general_args[@]} && ret=0
189 }
190
191 _vault_mount() {
192     # to find out how many types of backends are there
193     _arguments : \
194         ${general_args[@]} \
195         ${mount_args[@]} \
196         ':::(generic ssh)' && ret=0
197 }
198
199 _vault_mount-tune() {
200     _arguments : \
201         ${general_args[@]} \
202         ${mount_tune_args[@]} \
203         ':::__vault_mounts' && ret=0
204 }
205
206 _vault_unmount() {
207     _arguments : \
208         ${general_args[@]} \
209         ':::__vault_mounts' && ret=0
210 }
211
212 _vault_remount() {
213     _arguments : \
214         ${general_args[@]} \
215         ':::__vault_mounts' \
216         ':::'  && ret=0
217 }
218
219 __vault_policies() {
220     local -a policies
221     policies=($(vault policies | awk '{print $1":["$1"]"}'))
222     _describe -t policies 'policies' policies && ret=0
223 }
224
225 _vault_policies() {
226     _arguments : \
227         ${general_args[@]} \
228         ':::__vault_policies' && ret=0
229 }
230
231 _vault_policy-delete() {
232     _arguments : \
233         ${general_args[@]} \
234         ':::__vault_policies' && ret=0
235 }
236
237 _vault_policy-write() {
238     _arguments : \
239         ${general_args[@]} \
240         ': ::' \
241         '::policy:_files' && ret=0
242 }
243
244 _vault_status() {
245     _arguments : \
246         ${general_args[@]} && ret=0
247 }
248
249 _vault_rekey() {
250     _arguments : \
251         ${general_args[@]} \
252         ${rekey_args[@]} \
253         ': ::' && ret=0
254 }
255
256 _vault_rotate() {
257     _arguments : \
258         ${general_args[@]} && ret=0
259 }
260
261 _vault_seal() {
262     _arguments : \
263         ${general_args[@]} && ret=0
264 }
265
266 _vault_ssh() {
267     _arguments : \
268         ${general_args[@]} \
269         ${ssh_args[@]} \
270         ': ::' && ret=0
271 }
272
273 _vault_token-create() {
274     _arguments : \
275         ${general_args[@]} \
276         ${token_create_args[@]} && ret=0
277 }
278
279 _vault_token-renew() {
280     _arguments : \
281         ${general_args[@]} \
282         '(-format)-format=-[The format for output. By default it is a whitespace-delimited table. This can also be json.]:format:(json table)' \
283         ': ::' \
284         ': ::' && ret=0
285 }
286
287 _vault_token-revoke() {
288     _arguments : \
289         ${general_args[@]} \
290         '(-mode)-mode=-[The type of revocation to do. See the documentation above for more information.]:mode:(  orphan path)' \
291         ': ::' && ret=0
292 }
293
294 _vault_unseal() {
295     _arguments : \
296         ${general_args[@]} \
297         '(-reset)-reset[Reset the unsealing process by throwing away prior keys in process to unseal the vault.]:reset:' \
298         ': ::' && ret=0
299 }
300
301 _vault_version() {
302     # no args
303 }
304
305 _vault_delete() {
306     _arguments : \
307         ${general_args[@]} \
308         ': ::' && ret=0
309 }
310
311 _vault_path-help() {
312     _arguments : \
313         ${general_args[@]} \
314         ': ::' && ret=0
315 }
316
317 _vault_revoke() {
318     _arguments : \
319         ${general_args[@]} \
320         '(-format)-format=-[The format for output. By default it is a whitespace-delimited table. This can also be json.]:format:(json table)' \
321         ': ::' \
322         ': ::' && ret=0
323 }
324
325 _vault_server() {
326     _arguments : \
327         ${server_args[@]} && ret=0
328
329 }
330
331 _vault_write() {
332     _arguments : \
333         ${general_args[@]} \
334         '(-f -force)'{-f,-force}'[Force the write to continue without any data values specified. This allows writing to keys that do not need or expect any fields to be specified.]:force:' \
335         ': ::' \
336         ': ::' && ret=0
337 }
338
339 _vault_read() {
340     _arguments : \
341         ${general_args[@]} \
342         '(-format)-format=-[The format for output. By default it is a whitespace-delimited table. This can also be json.]:format:(json table)' \
343         '(-field)-field=-[If included, the raw value of the specified field will be output raw to stdout.]:field:' \
344         ': ::' && ret=0
345 }
346
347 _vault_commands() {
348     local -a commands
349
350     commands=(
351         "delete":"Delete operation on secrets in Vault"
352         "path-help":"Look up the help for a path"
353         "read":"Read data or secrets from Vault"
354         "renew":"Renew the lease of a secret"
355         "revoke":"Revoke a secret"
356         "server":"Start a Vault server"
357         "status":"Outputs status of whether Vault is sealed and if HA mode is enabled"
358         "write":"Write secrets or configuration into Vault"
359         "audit-disable":"Disable an audit backend"
360         "audit-enable":"Enable an audit backend"
361         "audit-list":"Lists enabled audit backends in Vault"
362         "auth":"Prints information about how to authenticate with Vault"
363         "auth-disable":"Disable an auth provider"
364         "auth-enable":"Enable a new auth provider"
365         "init":"Initialize a new Vault server"
366         "key-status":"Provides information about the active encryption key"
367         "mount":"Mount a logical backend"
368         "mount-tune":"Tune mount configuration parameters"
369         "mounts":"Lists mounted backends in Vault"
370         "policies":"List the policies on the server"
371         "policy-delete":"Delete a policy from the server"
372         "policy-write":"Write a policy to the server"
373         "rekey":"Rekeys Vault to generate new unseal keys"
374         "remount":"Remount a secret backend to a new path"
375         "rotate":"Rotates the backend encryption key used to persist data"
376         "seal":"Seals the vault server"
377         "ssh":"Initiate a SSH session"
378         "token-create":"Create a new auth token"
379         "token-renew":"Renew an auth token if there is an associated lease"
380         "token-revoke":"Revoke one or more auth tokens"
381         "unmount":"Unmount a secret backend"
382         "unseal":"Unseals the vault server"
383         "version":"Prints the Vault version"
384     )
385
386     _describe -t commands 'vault command' commands && ret=0
387 }
388
389 local curcontext=$curcontext ret=1
390 _arguments : \
391     ${main_args[@]} \
392     '*:: :->subcommands' && ret=0
393 if ((CURRENT == 1 )); then
394     _vault_commands && ret=0
395 fi
396 if [[ $state == subcommands ]]; then
397     # (( CURRENT -- ))
398     curcontext="${curcontext%:*:*}:vault-$words[1]:"
399     _call_function ret _vault_$words[1]
400 fi