1
- # HVAC
1
+ # ASYNC- HVAC
2
2
3
- [ HashiCorp] ( https://hashicorp.com/ ) [ Vault] ( https://www.vaultproject.io ) API client for Python 2/ 3
3
+ [ HashiCorp] ( https://hashicorp.com/ ) [ Vault] ( https://www.vaultproject.io ) API asyncio client for Python 3
4
4
5
- [ ![ Travis CI] ( https://travis-ci.org/ianunruh/hvac.svg?branch=master )] ( https://travis-ci.org/ianunruh/hvac ) [ ![ Latest Version] ( https://img.shields.io/pypi/v/hvac.svg )] ( https://pypi.python.org/pypi/hvac/ )
6
-
7
- Tested against Vault v0.1.2 and HEAD. Requires v0.1.2 or later.
5
+ Tested against Vault v0.10.1 and HEAD. Requires v0.1.2 or later.
8
6
9
7
## Getting started
10
8
11
9
### Installation
12
10
13
11
``` bash
14
- pip install hvac
12
+ pip install ahvac
15
13
```
16
14
or
17
15
``` bash
18
- pip install " hvac[parser]"
16
+ pip install async- hvac[parser]
19
17
```
20
18
if you would like to be able to return parsed HCL data as a Python dict for methods that support it.
21
19
@@ -42,42 +40,42 @@ client = hvac.Client(url='https://localhost:8200',
42
40
### Read and write to secret backends
43
41
44
42
``` python
45
- client.write(' secret/foo' , baz = ' bar' , lease = ' 1h' )
43
+ await client.write(' secret/foo' , baz = ' bar' , lease = ' 1h' )
46
44
47
- print (client.read(' secret/foo' ))
45
+ print (await client.read(' secret/foo' ))
48
46
49
- client.delete(' secret/foo' )
47
+ await client.delete(' secret/foo' )
50
48
```
51
49
52
50
### Authenticate to different auth backends
53
51
54
52
``` python
55
53
# Token
56
54
client.token = ' MY_TOKEN'
57
- assert client.is_authenticated() # => True
55
+ assert await client.is_authenticated() # => True
58
56
59
57
# App ID
60
- client.auth_app_id(' MY_APP_ID' , ' MY_USER_ID' )
58
+ await client.auth_app_id(' MY_APP_ID' , ' MY_USER_ID' )
61
59
62
60
# App Role
63
- client.auth_approle(' MY_ROLE_ID' , ' MY_SECRET_ID' )
61
+ await client.auth_approle(' MY_ROLE_ID' , ' MY_SECRET_ID' )
64
62
65
63
# GitHub
66
- client.auth_github(' MY_GITHUB_TOKEN' )
64
+ await client.auth_github(' MY_GITHUB_TOKEN' )
67
65
68
66
# LDAP, Username & Password
69
- client.auth_ldap(' MY_USERNAME' , ' MY_PASSWORD' )
70
- client.auth_userpass(' MY_USERNAME' , ' MY_PASSWORD' )
67
+ await client.auth_ldap(' MY_USERNAME' , ' MY_PASSWORD' )
68
+ await client.auth_userpass(' MY_USERNAME' , ' MY_PASSWORD' )
71
69
72
70
# TLS
73
71
client = Client(cert = (' path/to/cert.pem' , ' path/to/key.pem' ))
74
- client.auth_tls()
72
+ await client.auth_tls()
75
73
76
74
# Non-default mount point (available on all auth types)
77
- client.auth_userpass(' MY_USERNAME' , ' MY_PASSWORD' , mount_point = ' CUSTOM_MOUNT_POINT' )
75
+ await client.auth_userpass(' MY_USERNAME' , ' MY_PASSWORD' , mount_point = ' CUSTOM_MOUNT_POINT' )
78
76
79
77
# Authenticating without changing to new token (available on all auth types)
80
- result = client.auth_github(' MY_GITHUB_TOKEN' , use_token = False )
78
+ result = await client.auth_github(' MY_GITHUB_TOKEN' , use_token = False )
81
79
print (result[' auth' ][' client_token' ]) # => u'NEW_TOKEN'
82
80
83
81
# Custom or unsupported auth type
@@ -87,72 +85,72 @@ params = {
87
85
' custom_param' : ' MY_CUSTOM_PARAM' ,
88
86
}
89
87
90
- result = client.auth(' /v1/auth/CUSTOM_AUTH/login' , json = params)
88
+ result = await client.auth(' /v1/auth/CUSTOM_AUTH/login' , json = params)
91
89
92
90
# Logout
93
- client.logout()
91
+ await client.logout()
94
92
```
95
93
96
94
### Manage tokens
97
95
98
96
``` python
99
- token = client.create_token(policies = [' root' ], lease = ' 1h' )
97
+ token = await client.create_token(policies = [' root' ], lease = ' 1h' )
100
98
101
- current_token = client.lookup_token()
102
- some_other_token = client.lookup_token(' xxx' )
99
+ current_token = await client.lookup_token()
100
+ some_other_token = await client.lookup_token(' xxx' )
103
101
104
- client.revoke_token(' xxx' )
105
- client.revoke_token(' yyy' , orphan = True )
102
+ await client.revoke_token(' xxx' )
103
+ await client.revoke_token(' yyy' , orphan = True )
106
104
107
- client.revoke_token_prefix(' zzz' )
105
+ await client.revoke_token_prefix(' zzz' )
108
106
109
- client.renew_token(' aaa' )
107
+ await client.renew_token(' aaa' )
110
108
```
111
109
112
110
### Managing tokens using accessors
113
111
114
112
``` python
115
- token = client.create_token(policies = [' root' ], lease = ' 1h' )
113
+ token = await client.create_token(policies = [' root' ], lease = ' 1h' )
116
114
token_accessor = token[' auth' ][' accessor' ]
117
115
118
- same_token = client.lookup_token(token_accessor, accessor = True )
119
- client.revoke_token(token_accessor, accessor = True )
116
+ same_token = await client.lookup_token(token_accessor, accessor = True )
117
+ await client.revoke_token(token_accessor, accessor = True )
120
118
```
121
119
122
120
### Wrapping/unwrapping a token
123
121
124
122
``` python
125
- wrap = client.create_token(policies = [' root' ], lease = ' 1h' , wrap_ttl = ' 1m' )
126
- result = self .client.unwrap(wrap[' wrap_info' ][' token' ])
123
+ wrap = await client.create_token(policies = [' root' ], lease = ' 1h' , wrap_ttl = ' 1m' )
124
+ result = await self .client.unwrap(wrap[' wrap_info' ][' token' ])
127
125
```
128
126
129
127
### Manipulate auth backends
130
128
131
129
``` python
132
- backends = client.list_auth_backends()
130
+ backends = await client.list_auth_backends()
133
131
134
- client.enable_auth_backend(' userpass' , mount_point = ' customuserpass' )
135
- client.disable_auth_backend(' github' )
132
+ await client.enable_auth_backend(' userpass' , mount_point = ' customuserpass' )
133
+ await client.disable_auth_backend(' github' )
136
134
```
137
135
138
136
### Manipulate secret backends
139
137
140
138
``` python
141
- backends = client.list_secret_backends()
139
+ backends = await client.list_secret_backends()
142
140
143
- client.enable_secret_backend(' aws' , mount_point = ' aws-us-east-1' )
144
- client.disable_secret_backend(' mysql' )
141
+ await client.enable_secret_backend(' aws' , mount_point = ' aws-us-east-1' )
142
+ await client.disable_secret_backend(' mysql' )
145
143
146
- client.tune_secret_backend(' generic' , mount_point = ' test' , default_lease_ttl = ' 3600s' , max_lease_ttl = ' 8600s' )
147
- client.get_secret_backend_tuning(' generic' , mount_point = ' test' )
144
+ await client.tune_secret_backend(' generic' , mount_point = ' test' , default_lease_ttl = ' 3600s' , max_lease_ttl = ' 8600s' )
145
+ await client.get_secret_backend_tuning(' generic' , mount_point = ' test' )
148
146
149
- client.remount_secret_backend(' aws-us-east-1' , ' aws-east' )
147
+ await client.remount_secret_backend(' aws-us-east-1' , ' aws-east' )
150
148
```
151
149
152
150
### Manipulate policies
153
151
154
152
``` python
155
- policies = client.list_policies() # => ['root']
153
+ policies = await client.list_policies() # => ['root']
156
154
157
155
policy = """
158
156
path "sys" {
@@ -168,39 +166,39 @@ path "secret/foo" {
168
166
}
169
167
"""
170
168
171
- client.set_policy(' myapp' , policy)
169
+ await client.set_policy(' myapp' , policy)
172
170
173
- client.delete_policy(' oldthing' )
171
+ await client.delete_policy(' oldthing' )
174
172
175
- policy = client.get_policy(' mypolicy' )
173
+ policy = await client.get_policy(' mypolicy' )
176
174
177
175
# Requires pyhcl to automatically parse HCL into a Python dictionary
178
- policy = client.get_policy(' mypolicy' , parse = True )
176
+ policy = await client.get_policy(' mypolicy' , parse = True )
179
177
```
180
178
181
179
### Manipulate audit backends
182
180
183
181
``` python
184
- backends = client.list_audit_backends()
182
+ backends = await client.list_audit_backends()
185
183
186
184
options = {
187
185
' path' : ' /tmp/vault.log' ,
188
186
' log_raw' : True ,
189
187
}
190
188
191
- client.enable_audit_backend(' file' , options = options, name = ' somefile' )
192
- client.disable_audit_backend(' oldfile' )
189
+ await client.enable_audit_backend(' file' , options = options, name = ' somefile' )
190
+ await client.disable_audit_backend(' oldfile' )
193
191
```
194
192
195
193
### Initialize and seal/unseal
196
194
197
195
``` python
198
- print (client.is_initialized()) # => False
196
+ print (await client.is_initialized()) # => False
199
197
200
198
shares = 5
201
199
threshold = 3
202
200
203
- result = client.initialize(shares, threshold)
201
+ result = await client.initialize(shares, threshold)
204
202
205
203
root_token = result[' root_token' ]
206
204
keys = result[' keys' ]
@@ -210,18 +208,18 @@ print(client.is_initialized()) # => True
210
208
print (client.is_sealed()) # => True
211
209
212
210
# unseal with individual keys
213
- client.unseal(keys[0 ])
214
- client.unseal(keys[1 ])
215
- client.unseal(keys[2 ])
211
+ await client.unseal(keys[0 ])
212
+ await client.unseal(keys[1 ])
213
+ await client.unseal(keys[2 ])
216
214
217
215
# unseal with multiple keys until threshold met
218
- client.unseal_multi(keys)
216
+ await client.unseal_multi(keys)
219
217
220
- print (client.is_sealed()) # => False
218
+ print (await client.is_sealed()) # => False
221
219
222
- client.seal()
220
+ await client.seal()
223
221
224
- print (client.is_sealed()) # => True
222
+ print (await client.is_sealed()) # => True
225
223
```
226
224
227
225
## Testing
0 commit comments