-
Notifications
You must be signed in to change notification settings - Fork 157
/
hashivault_token_renew.py
76 lines (69 loc) · 2.49 KB
/
hashivault_token_renew.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
from ansible.module_utils.hashivault import hashivault_argspec
from ansible.module_utils.hashivault import hashivault_auth_client
from ansible.module_utils.hashivault import hashivault_init
from ansible.module_utils.hashivault import hashiwrapper
ANSIBLE_METADATA = {'status': ['stableinterface'], 'supported_by': 'community', 'version': '1.1'}
DOCUMENTATION = '''
---
module: hashivault_token_renew
version_added: "3.11.0"
short_description: Hashicorp Vault token renew module
description:
- Module to renew tokens in Hashicorp Vault.
options:
renew_token:
description:
- token to renew if different from auth token
default: to authentication token
increment:
description:
- "Request a specific increment for renewal. Vault is not required to honor this request. If not supplied,\
Vault will use the default TTL."
self_renew:
description:
- Self renew token
wrap_ttl:
description:
- Indicates that the response should be wrapped in a cubbyhole token with the requested TTL.
extends_documentation_fragment: hashivault
'''
EXAMPLES = '''
---
- hosts: localhost
tasks:
- name: "Renew token"
hashivault_token_renew:
renew_token: "{{client_token}}"
increment: "5m"
register: "vault_token_renew"
'''
def main():
argspec = hashivault_argspec()
argspec['renew_token'] = dict(required=False, type='str', no_log=True)
argspec['increment'] = dict(required=False, type='str', default=None)
argspec['self_renew'] = dict(required=False, type='bool', default=False)
argspec['wrap_ttl'] = dict(required=False, type='int')
module = hashivault_init(argspec)
result = hashivault_token_renew(module.params)
if result.get('failed'):
module.fail_json(**result)
else:
module.exit_json(**result)
@hashiwrapper
def hashivault_token_renew(params):
client = hashivault_auth_client(params)
renew_token = params.get('renew_token')
increment = params.get('increment')
self_renew = params.get('self_renew')
if renew_token is None:
renew_token = params.get('token')
wrap_ttl = params.get('wrap_ttl')
if self_renew is True:
renew = client.renew_self_token(increment=increment, wrap_ttl=wrap_ttl)
else:
renew = client.renew_token(token=renew_token, increment=increment, wrap_ttl=wrap_ttl)
return {'changed': True, 'renew': renew}
if __name__ == '__main__':
main()