Skip to content

Commit 7dcadb3

Browse files
committed
Merge remote-tracking branch 'upstream2/async' into async
2 parents de5212a + 4327001 commit 7dcadb3

17 files changed

+994
-277
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
/cover
1212
*~
1313

14-
/hvac/version
14+
/hsync_hvac/version
15+
16+
.idea

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include hvac/version
1+
include async_hvac/version

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ test: version
22
tox
33

44
version:
5-
cp version hvac/version
5+
cp version async_hvac/version
66

77
clean:
8-
rm -rf dist hvac.egg-info
8+
rm -rf dist async_hvac.egg-info
99

1010
distclean: clean
11-
rm -rf build hvac/version .tox
11+
rm -rf build async_hvac/version .tox
1212

1313
package: version
1414
python setup.py sdist

README.md

+57-59
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
# HVAC
1+
# ASYNC-HVAC
22

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
44

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.
86

97
## Getting started
108

119
### Installation
1210

1311
```bash
14-
pip install hvac
12+
pip install ahvac
1513
```
1614
or
1715
```bash
18-
pip install "hvac[parser]"
16+
pip install async-hvac[parser]
1917
```
2018
if you would like to be able to return parsed HCL data as a Python dict for methods that support it.
2119

@@ -42,42 +40,42 @@ client = hvac.Client(url='https://localhost:8200',
4240
### Read and write to secret backends
4341

4442
```python
45-
client.write('secret/foo', baz='bar', lease='1h')
43+
await client.write('secret/foo', baz='bar', lease='1h')
4644

47-
print(client.read('secret/foo'))
45+
print(await client.read('secret/foo'))
4846

49-
client.delete('secret/foo')
47+
await client.delete('secret/foo')
5048
```
5149

5250
### Authenticate to different auth backends
5351

5452
```python
5553
# Token
5654
client.token = 'MY_TOKEN'
57-
assert client.is_authenticated() # => True
55+
assert await client.is_authenticated() # => True
5856

5957
# 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')
6159

6260
# App Role
63-
client.auth_approle('MY_ROLE_ID', 'MY_SECRET_ID')
61+
await client.auth_approle('MY_ROLE_ID', 'MY_SECRET_ID')
6462

6563
# GitHub
66-
client.auth_github('MY_GITHUB_TOKEN')
64+
await client.auth_github('MY_GITHUB_TOKEN')
6765

6866
# 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')
7169

7270
# TLS
7371
client = Client(cert=('path/to/cert.pem', 'path/to/key.pem'))
74-
client.auth_tls()
72+
await client.auth_tls()
7573

7674
# 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')
7876

7977
# 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)
8179
print(result['auth']['client_token']) # => u'NEW_TOKEN'
8280

8381
# Custom or unsupported auth type
@@ -87,72 +85,72 @@ params = {
8785
'custom_param': 'MY_CUSTOM_PARAM',
8886
}
8987

90-
result = client.auth('/v1/auth/CUSTOM_AUTH/login', json=params)
88+
result = await client.auth('/v1/auth/CUSTOM_AUTH/login', json=params)
9189

9290
# Logout
93-
client.logout()
91+
await client.logout()
9492
```
9593

9694
### Manage tokens
9795

9896
```python
99-
token = client.create_token(policies=['root'], lease='1h')
97+
token = await client.create_token(policies=['root'], lease='1h')
10098

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')
103101

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)
106104

107-
client.revoke_token_prefix('zzz')
105+
await client.revoke_token_prefix('zzz')
108106

109-
client.renew_token('aaa')
107+
await client.renew_token('aaa')
110108
```
111109

112110
### Managing tokens using accessors
113111

114112
```python
115-
token = client.create_token(policies=['root'], lease='1h')
113+
token = await client.create_token(policies=['root'], lease='1h')
116114
token_accessor = token['auth']['accessor']
117115

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)
120118
```
121119

122120
### Wrapping/unwrapping a token
123121

124122
```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'])
127125
```
128126

129127
### Manipulate auth backends
130128

131129
```python
132-
backends = client.list_auth_backends()
130+
backends = await client.list_auth_backends()
133131

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')
136134
```
137135

138136
### Manipulate secret backends
139137

140138
```python
141-
backends = client.list_secret_backends()
139+
backends = await client.list_secret_backends()
142140

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')
145143

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')
148146

149-
client.remount_secret_backend('aws-us-east-1', 'aws-east')
147+
await client.remount_secret_backend('aws-us-east-1', 'aws-east')
150148
```
151149

152150
### Manipulate policies
153151

154152
```python
155-
policies = client.list_policies() # => ['root']
153+
policies = await client.list_policies() # => ['root']
156154

157155
policy = """
158156
path "sys" {
@@ -168,39 +166,39 @@ path "secret/foo" {
168166
}
169167
"""
170168

171-
client.set_policy('myapp', policy)
169+
await client.set_policy('myapp', policy)
172170

173-
client.delete_policy('oldthing')
171+
await client.delete_policy('oldthing')
174172

175-
policy = client.get_policy('mypolicy')
173+
policy = await client.get_policy('mypolicy')
176174

177175
# 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)
179177
```
180178

181179
### Manipulate audit backends
182180

183181
```python
184-
backends = client.list_audit_backends()
182+
backends = await client.list_audit_backends()
185183

186184
options = {
187185
'path': '/tmp/vault.log',
188186
'log_raw': True,
189187
}
190188

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')
193191
```
194192

195193
### Initialize and seal/unseal
196194

197195
```python
198-
print(client.is_initialized()) # => False
196+
print(await client.is_initialized()) # => False
199197

200198
shares = 5
201199
threshold = 3
202200

203-
result = client.initialize(shares, threshold)
201+
result = await client.initialize(shares, threshold)
204202

205203
root_token = result['root_token']
206204
keys = result['keys']
@@ -210,18 +208,18 @@ print(client.is_initialized()) # => True
210208
print(client.is_sealed()) # => True
211209

212210
# 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])
216214

217215
# unseal with multiple keys until threshold met
218-
client.unseal_multi(keys)
216+
await client.unseal_multi(keys)
219217

220-
print(client.is_sealed()) # => False
218+
print(await client.is_sealed()) # => False
221219

222-
client.seal()
220+
await client.seal()
223221

224-
print(client.is_sealed()) # => True
222+
print(await client.is_sealed()) # => True
225223
```
226224

227225
## Testing

async-hvac.iml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="PYTHON_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$" />
6+
<orderEntry type="inheritedJdk" />
7+
<orderEntry type="sourceFolder" forTests="false" />
8+
</component>
9+
</module>

async_hvac/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from async_hvac.v1 import Client
2+
from async_hvac.v1 import async_to_sync
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)