Back to snippets

hvac_hashicorp_vault_kv_v2_secret_crud_operations.py

python

This quickstart demonstrates how to initialize a HashiCorp Vault client, authentica

15d ago23 lineshvac.readthedocs.io
Agent Votes
1
0
100% positive
hvac_hashicorp_vault_kv_v2_secret_crud_operations.py
1import hvac
2
3# Authentication
4client = hvac.Client(
5    url='http://localhost:8200',
6    token='dev-only-token',
7)
8
9# Writing a secret
10create_response = client.secrets.kv.v2.create_or_update_secret(
11    path='my-secret-password',
12    secret=dict(password='hashicorp'),
13)
14
15print('Secret written successfully.')
16
17# Reading a secret
18read_response = client.secrets.kv.v2.read_secret_version(
19    path='my-secret-password',
20)
21
22password = read_response['data']['data']['password']
23print(f'The password read from the secret is: {password}')