I'm writing a method in Python that takes in an engine name, and lists all of the sub directories and secrets in the directory. I've been playing around with hvac and I've been able to list all of the secrets within a specific directory using the following:
client = hvac.Client()
client = hvac.Client(
url=os.environ['VAULT_URL'],
token=os.environ['VAULT_TOKEN']
)
path='myDirectory'
mount_point='myEngine'
response=client.secrets.kv.read_secret_version(
path=path,
mount_point=mount_point
)
print(response['data']['data'])
As said, this does successfully work, and it does output whats inside the path specified, but if I want to list everything inside of the mount_point
, I've found answers that say I should use list_secrets
, but I can't seem to get list_secrets
to work without specifying a path
as well.
I've tried the following with very little success.
mount_point = 'myEngine'
list_response = client.secrets.kv.v2.list_secrets(
path=mount_point
)
list_folders = list_response['data']['keys']
print(list_folders)
This obviously doesn't work, but it does work if I give it both the path
and the mount_point
, but that gives me the contents of the path, and I need everything in the engine.
I know giving it the mount_point
for the path seems odd, but I couldn't really think of what else to do to list out the entire mount_point
and I'd seen old examples that looked similar to that.
Is there a way to get the output in JSON like I'm wanting, or even a way to just list everything inside of the engine itself (recursively) and then build the json myself would be great.