Fix error in v3 credentials create/update
The v3 credentials passes data associated with the credential in a "data" key, but the underlying API expects "blob", which is also what is documented in the API spec. Currently any attempt to create a credential with a type of 'ec2' will fail with 'Invalid blob in credential' So s/data/blob to fix. Change-Id: I0858e8c39653477eb554ee9d15fb4f2dde2b195c Closes-Bug: #1259461
This commit is contained in:
@@ -28,8 +28,28 @@ class CredentialTests(utils.TestCase, utils.CrudTests):
|
||||
|
||||
def new_ref(self, **kwargs):
|
||||
kwargs = super(CredentialTests, self).new_ref(**kwargs)
|
||||
kwargs.setdefault('data', uuid.uuid4().hex)
|
||||
kwargs.setdefault('blob', uuid.uuid4().hex)
|
||||
kwargs.setdefault('project_id', uuid.uuid4().hex)
|
||||
kwargs.setdefault('type', uuid.uuid4().hex)
|
||||
kwargs.setdefault('user_id', uuid.uuid4().hex)
|
||||
return kwargs
|
||||
|
||||
@staticmethod
|
||||
def _ref_data_not_blob(ref):
|
||||
ret_ref = ref.copy()
|
||||
ret_ref['data'] = ref['blob']
|
||||
del ret_ref['blob']
|
||||
return ret_ref
|
||||
|
||||
def test_create_data_not_blob(self):
|
||||
# Test create operation with previous, deprecated "data" argument,
|
||||
# which should be translated into "blob" at the API call level
|
||||
req_ref = self.new_ref()
|
||||
api_ref = self._ref_data_not_blob(req_ref)
|
||||
self.test_create(api_ref, req_ref)
|
||||
|
||||
def test_update_data_not_blob(self):
|
||||
# Likewise test update operation with data instead of blob argument
|
||||
req_ref = self.new_ref()
|
||||
api_ref = self._ref_data_not_blob(req_ref)
|
||||
self.test_update(api_ref, req_ref)
|
||||
|
@@ -261,12 +261,16 @@ class CrudTests(object):
|
||||
self.assertQueryStringIs({})
|
||||
|
||||
@httpretty.activate
|
||||
def test_update(self, ref=None):
|
||||
def test_update(self, ref=None, req_ref=None):
|
||||
ref = ref or self.new_ref()
|
||||
|
||||
self.stub_entity(httpretty.PATCH, id=ref['id'], entity=ref)
|
||||
|
||||
req_ref = ref.copy()
|
||||
# req_ref argument allows you to specify a different
|
||||
# signature for the request when the manager does some
|
||||
# conversion before doing the request (e.g converting
|
||||
# from datetime object to timestamp string)
|
||||
req_ref = (req_ref or ref).copy()
|
||||
req_ref.pop('id')
|
||||
|
||||
returned = self.manager.update(ref['id'], **parameterize(req_ref))
|
||||
|
@@ -33,11 +33,25 @@ class CredentialManager(base.CrudManager):
|
||||
collection_key = 'credentials'
|
||||
key = 'credential'
|
||||
|
||||
def create(self, user, type, data, project=None):
|
||||
def _get_data_blob(self, blob, data):
|
||||
# Ref bug #1259461, the <= 0.4.1 keystoneclient calling convention was
|
||||
# to pass "data", but the underlying API expects "blob", so
|
||||
# support both in the python API for backwards compatibility
|
||||
if blob is not None:
|
||||
return blob
|
||||
elif data is not None:
|
||||
# FIXME(shardy): Passing data is deprecated. Provide an
|
||||
# appropriate warning.
|
||||
return data
|
||||
else:
|
||||
raise ValueError(
|
||||
"Credential requires blob to be specified")
|
||||
|
||||
def create(self, user, type, blob=None, data=None, project=None):
|
||||
return super(CredentialManager, self).create(
|
||||
user_id=base.getid(user),
|
||||
type=type,
|
||||
data=data,
|
||||
blob=self._get_data_blob(blob, data),
|
||||
project_id=base.getid(project))
|
||||
|
||||
def get(self, credential):
|
||||
@@ -47,12 +61,13 @@ class CredentialManager(base.CrudManager):
|
||||
def list(self):
|
||||
return super(CredentialManager, self).list()
|
||||
|
||||
def update(self, credential, user, type=None, data=None, project=None):
|
||||
def update(self, credential, user, type=None, blob=None, data=None,
|
||||
project=None):
|
||||
return super(CredentialManager, self).update(
|
||||
credential_id=base.getid(credential),
|
||||
user_id=base.getid(user),
|
||||
type=type,
|
||||
data=data,
|
||||
blob=self._get_data_blob(blob, data),
|
||||
project_id=base.getid(project))
|
||||
|
||||
def delete(self, credential):
|
||||
|
Reference in New Issue
Block a user