Skip to content

Commit

Permalink
Handle hvac read_acl_policy InvalidPath exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mleneveut committed Jun 24, 2024
1 parent 7364cc5 commit 65acb0b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ansible/modules/hashivault/hashivault_acl_policy_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ansible.module_utils.hashivault import hashivault_auth_client
from ansible.module_utils.hashivault import hashivault_init
from ansible.module_utils.hashivault import hashiwrapper
from hvac.exceptions import InvalidPath

ANSIBLE_METADATA = {'status': ['stableinterface'], 'supported_by': 'community', 'version': '1.1'}
DOCUMENTATION = '''
Expand Down Expand Up @@ -45,15 +46,18 @@ def main():
def hashivault_acl_policy_get(params):
name = params.get('name')
client = hashivault_auth_client(params)
policy = client.sys.read_acl_policy(name)
policy = policy.get('data', policy).get('policy', policy)
try:
policy = client.sys.read_acl_policy(name)
policy = policy.get('data', policy).get('policy', policy)
except InvalidPath as e:
policy = None

if policy is None:
result = {"changed": False, "rc": 1, "failed": True}
result['msg'] = u"Policy \"%s\" does not exist." % name
return result
else:
return {'rules': policy}


if __name__ == '__main__':
main()

0 comments on commit 65acb0b

Please sign in to comment.