Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespaces #268

Merged
merged 7 commits into from Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Changelog

## 0.6.5 (September 12th, 2018)

IMPROVEMENTS:

* Support for Vault Namespaces.

## 0.6.4 (September 5th, 2018)

IMPROVEMENTS:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -41,6 +41,9 @@ client = hvac.Client(url='https://localhost:8200')
# Using TLS with client-side certificate authentication
client = hvac.Client(url='https://localhost:8200', cert=('path/to/cert.pem', 'path/to/key.pem'))

# Using Namespace
client = hvac.Client(url='http://localhost:8200', token=os.environ['VAULT_TOKEN'], namespace=os.environ['VAULT_NAMESPACE'])

```

### Read and write to secret backends
Expand Down
8 changes: 7 additions & 1 deletion hvac/adapters.py
Expand Up @@ -21,7 +21,7 @@ class Adapter(object):
__metaclass__ = ABCMeta

def __init__(self, base_uri=DEFAULT_BASE_URI, token=None, cert=None, verify=True, timeout=30, proxies=None,
allow_redirects=True, session=None):
allow_redirects=True, session=None, namespace=None):
"""Create a new request adapter instance.

:param base_uri: Base URL for the Vault instance being addressed.
Expand All @@ -43,12 +43,15 @@ def __init__(self, base_uri=DEFAULT_BASE_URI, token=None, cert=None, verify=True
:type allow_redirects: bool
:param session: Optional session object to use when performing request.
:type session: request.Session
:param namespace: Optional Vault Namespace.
:type namespace: str
"""
if not session:
session = requests.Session()

self.base_uri = base_uri
self.token = token
self.namespace = namespace
self.session = session
self.allow_redirects = allow_redirects

Expand Down Expand Up @@ -208,6 +211,9 @@ def request(self, method, url, headers=None, **kwargs):
if self.token:
headers['X-Vault-Token'] = self.token

if self.namespace:
headers['X-Vault-Namespace'] = self.namespace

wrap_ttl = kwargs.pop('wrap_ttl', None)
if wrap_ttl:
headers['X-Vault-Wrap-TTL'] = str(wrap_ttl)
Expand Down
4 changes: 3 additions & 1 deletion hvac/v1/__init__.py
Expand Up @@ -18,7 +18,7 @@ class Client(object):

def __init__(self, url='http://localhost:8200', token=None,
cert=None, verify=True, timeout=30, proxies=None,
allow_redirects=True, session=None, adapter=None):
allow_redirects=True, session=None, adapter=None, namespace=None):
"""Creates a new hvac client instnace.

:param url: Base URL for the Vault instance being addressed.
Expand All @@ -43,6 +43,8 @@ def __init__(self, url='http://localhost:8200', token=None,
:param adapter: Optional class to be used for performing requests. If none is provided, defaults to
hvac.adapters.Request
:type adapter: hvac.adapters.Adapter
:param namespace: Optional Vault Namespace.
tiny-dancer marked this conversation as resolved.
Show resolved Hide resolved
:type namespace: str
"""

if adapter is not None:
Expand Down
2 changes: 1 addition & 1 deletion version
@@ -1 +1 @@
0.6.4
0.6.5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that this change was made on this initial PR's commit. Would you mind getting it reverted @tiny-dancer? Pending that I see no reason we can't get this merged in. (FWIW, I am intending for a few other changes to go out in the 0.6.5 release that is tentatively slated for Oct. 1st.)