forked from hashicorp/vault-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
29 lines (21 loc) · 632 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
import hvac
import sys
# Authentication
client = hvac.Client(
url='http://127.0.0.1:8200',
token='dev-only-token',
)
# Writing a secret
create_response = client.secrets.kv.v2.create_or_update_secret(
path='my-secret-password',
secret=dict(password='Hashi123'),
)
print('Secret written successfully.')
# Reading a secret
read_response = client.secrets.kv.read_secret_version(path='my-secret-password')
password = read_response['data']['data']['password']
if password != 'Hashi123':
sys.exit('unexpected password')
print('Access granted!')