summaryrefslogtreecommitdiff
path: root/barbicanclient/v1/secrets.py
diff options
context:
space:
mode:
authorAdam Harwell <flux.adam@gmail.com>2018-08-02 08:53:32 +0900
committerAdam Harwell <flux.adam@gmail.com>2018-09-11 17:08:36 -0600
commit6651c8ffce48ce7ff08f5563a8e6212677ea0468 (patch)
tree3e2917d7133a79cf206c918d031f53159addef12 /barbicanclient/v1/secrets.py
parent1a8cc8c1ebac5fa0359cb3ed433bc60afba30972 (diff)
downloadpython-barbicanclient-6651c8ffce48ce7ff08f5563a8e6212677ea0468.tar.gz
Allow fetching by UUID, and respect interface
When passing a UUID to the client, use the Barbican endpoint from the service catalog to fetch the entity. When passing an href, strip everything before the UUID and use it the same as a passed UUID. This allows for service usage when secrets are created with a public endpoint but must be retrieved from an internal or admin endpoint, and is probably how all usage should have worked to begin with. Change-Id: I90778a2eeefc4cfe42b0e2a48ba09036e3e6d83d Story: 2003197 Task: 23353
Diffstat (limited to 'barbicanclient/v1/secrets.py')
-rw-r--r--barbicanclient/v1/secrets.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/barbicanclient/v1/secrets.py b/barbicanclient/v1/secrets.py
index c2577d0..5b0c4a1 100644
--- a/barbicanclient/v1/secrets.py
+++ b/barbicanclient/v1/secrets.py
@@ -357,14 +357,16 @@ class Secret(SecretFormatter):
else:
raise exceptions.PayloadException("Invalid Payload Type")
- self._api.put(self._secret_ref,
+ uuid_ref = base.calculate_uuid_ref(self._secret_ref, self._entity)
+ self._api.put(uuid_ref,
headers=headers,
data=self.payload)
def delete(self):
"""Deletes the Secret from Barbican"""
if self._secret_ref:
- self._api.delete(self._secret_ref)
+ uuid_ref = base.calculate_uuid_ref(self._secret_ref, self._entity)
+ self._api.delete(uuid_ref)
self._secret_ref = None
else:
raise LookupError("Secret is not yet stored.")
@@ -411,7 +413,8 @@ class Secret(SecretFormatter):
def _fill_lazy_properties(self):
if self._secret_ref and not self._name:
- result = self._api.get(self._secret_ref)
+ uuid_ref = base.calculate_uuid_ref(self._secret_ref, self._entity)
+ result = self._api.get(uuid_ref)
self._fill_from_data(
name=result.get('name'),
expiration=result.get('expiration'),
@@ -444,7 +447,7 @@ class SecretManager(base.BaseEntityManager):
def get(self, secret_ref, payload_content_type=None):
"""Retrieve an existing Secret from Barbican
- :param str secret_ref: Full HATEOAS reference to a Secret
+ :param str secret_ref: Full HATEOAS reference to a Secret, or a UUID
:param str payload_content_type: DEPRECATED: Content type to use for
payload decryption. Setting this can lead to unexpected results.
See Launchpad Bug #1419166.
@@ -455,7 +458,7 @@ class SecretManager(base.BaseEntityManager):
:raises barbicanclient.exceptions.HTTPServerError: 5xx Responses
"""
LOG.debug("Getting secret - Secret href: {0}".format(secret_ref))
- base.validate_ref(secret_ref, 'Secret')
+ base.validate_ref_and_return_uuid(secret_ref, 'Secret')
return Secret(
api=self._api,
payload_content_type=payload_content_type,
@@ -463,16 +466,16 @@ class SecretManager(base.BaseEntityManager):
)
def update(self, secret_ref, payload=None):
- """Update an existing Secret from Barbican
+ """Update an existing Secret in Barbican
- :param str secret_ref: Full HATEOAS reference to a Secret
+ :param str secret_ref: Full HATEOAS reference to a Secret, or a UUID
:param str payload: New payload to add to secret
:raises barbicanclient.exceptions.HTTPAuthError: 401 Responses
:raises barbicanclient.exceptions.HTTPClientError: 4xx Responses
:raises barbicanclient.exceptions.HTTPServerError: 5xx Responses
"""
- base.validate_ref(secret_ref, 'Secret')
+ base.validate_ref_and_return_uuid(secret_ref, 'Secret')
if not secret_ref:
raise ValueError('secret_ref is required.')
@@ -483,7 +486,8 @@ class SecretManager(base.BaseEntityManager):
else:
raise exceptions.PayloadException("Invalid Payload Type")
- self._api.put(secret_ref,
+ uuid_ref = base.calculate_uuid_ref(secret_ref, self._entity)
+ self._api.put(uuid_ref,
headers=headers,
data=payload)
@@ -524,15 +528,16 @@ class SecretManager(base.BaseEntityManager):
def delete(self, secret_ref):
"""Delete a Secret from Barbican
- :param secret_ref: The href for the secret to be deleted
+ :param secret_ref: Full HATEOAS reference to a Secret, or a UUID
:raises barbicanclient.exceptions.HTTPAuthError: 401 Responses
:raises barbicanclient.exceptions.HTTPClientError: 4xx Responses
:raises barbicanclient.exceptions.HTTPServerError: 5xx Responses
"""
- base.validate_ref(secret_ref, 'Secret')
+ base.validate_ref_and_return_uuid(secret_ref, 'Secret')
if not secret_ref:
raise ValueError('secret_ref is required.')
- self._api.delete(secret_ref)
+ uuid_ref = base.calculate_uuid_ref(secret_ref, self._entity)
+ self._api.delete(uuid_ref)
def list(self, limit=10, offset=0, name=None, algorithm=None, mode=None,
bits=0, secret_type=None, created=None, updated=None,