I want to get credentials (username and password)from Hashicorp vault using hvac python library and print them out or store them in some variable. However, I am getting an error TypeError: 'Response' object is not subscriptable
after the last print statement. But, my credentials are getting authenticated.
My codes is as follows
import hvac
vault_token = 's.MYBDmBvO5I.....' # Copying my token from vault
vault_url = 'https://vault.corp.foxbase.de/ui/vault/secrets'
client = hvac.Client(url=vault_url, token=vault_token)
res=client.is_authenticated()
print('here is : ',res)
secrets_list = client.secrets.kv.v1.read_secret(
path = 'databases/creds/data-science-access'
)
print("secrets list: ", secrets_list['username'])
output is
here is : True
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-52-3a463dc902b7> in <module>()
23 #secrets_list1 = secrets_list.json()
24
---> 25 print("secrets list: ", secrets_list['username'])
My credentials in Vault sit in databases/creds/data-science-access
. When I run this command in vault terminal "vault read databases/creds/data-science-access
" it generates the credentials as follows
Key Value
password xxx
username xxx
When I login to my vault, it looks like this
Can someone please rectify where I am getting it wrong? Perhaps some parameters like "vault_url","vault_token" or "path" values I have wrongly passed.