Add metadata read to kv2 list
@@ -87,18 +87,19 @@ def hashivault_list(params):
version = 2
secret = secret.lstrip('metadata/')
- response = None
try:
if version == 2:
- response = client.secrets.kv.v2.list_secrets(path=secret, mount_point=mount_point)
+ if secret:
+ response = client.secrets.kv.v2.read_secret_metadata(path=secret, mount_point=mount_point)
+ result['metadata'] = response.get('data', {})
+ else:
+ response = client.secrets.kv.v2.list_secrets('', mount_point=mount_point)
+ result['secrets'] = response.get('data', {}).get('keys', [])
else:
response = client.secrets.kv.v1.list_secrets(path=secret, mount_point=mount_point)
+ result['secrets'] = response.get('data', {}).get('keys', [])
except Exception as e:
- if response is None:
- response = {}
- else:
return {'failed': True, 'msg': str(e)}
- result['secrets'] = response.get('data', {}).get('keys', [])
return result
