Blackify openstack.key_manager
Black used with the '-l 79 -S' flags. A future change will ignore this commit in git-blame history by adding a 'git-blame-ignore-revs' file. Change-Id: Ief5e4e9fa2675c7e74b77feb54776c692deaf33f Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
3d2511f980
commit
93d8f41713
@ -16,7 +16,6 @@ from openstack import format
|
|||||||
|
|
||||||
|
|
||||||
class HREFToUUID(format.Formatter):
|
class HREFToUUID(format.Formatter):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def deserialize(cls, value):
|
def deserialize(cls, value):
|
||||||
"""Convert a HREF to the UUID portion"""
|
"""Convert a HREF to the UUID portion"""
|
||||||
|
@ -49,8 +49,9 @@ class Proxy(proxy.Proxy):
|
|||||||
|
|
||||||
:returns: ``None``
|
:returns: ``None``
|
||||||
"""
|
"""
|
||||||
self._delete(_container.Container, container,
|
self._delete(
|
||||||
ignore_missing=ignore_missing)
|
_container.Container, container, ignore_missing=ignore_missing
|
||||||
|
)
|
||||||
|
|
||||||
def find_container(self, name_or_id, ignore_missing=True):
|
def find_container(self, name_or_id, ignore_missing=True):
|
||||||
"""Find a single container
|
"""Find a single container
|
||||||
@ -64,8 +65,9 @@ class Proxy(proxy.Proxy):
|
|||||||
:returns: One :class:`~openstack.key_manager.v1.container.Container`
|
:returns: One :class:`~openstack.key_manager.v1.container.Container`
|
||||||
or None
|
or None
|
||||||
"""
|
"""
|
||||||
return self._find(_container.Container, name_or_id,
|
return self._find(
|
||||||
ignore_missing=ignore_missing)
|
_container.Container, name_or_id, ignore_missing=ignore_missing
|
||||||
|
)
|
||||||
|
|
||||||
def get_container(self, container):
|
def get_container(self, container):
|
||||||
"""Get a single container
|
"""Get a single container
|
||||||
@ -143,8 +145,9 @@ class Proxy(proxy.Proxy):
|
|||||||
attempting to find a nonexistent resource.
|
attempting to find a nonexistent resource.
|
||||||
:returns: One :class:`~openstack.key_manager.v1.order.Order` or None
|
:returns: One :class:`~openstack.key_manager.v1.order.Order` or None
|
||||||
"""
|
"""
|
||||||
return self._find(_order.Order, name_or_id,
|
return self._find(
|
||||||
ignore_missing=ignore_missing)
|
_order.Order, name_or_id, ignore_missing=ignore_missing
|
||||||
|
)
|
||||||
|
|
||||||
def get_order(self, order):
|
def get_order(self, order):
|
||||||
"""Get a single order
|
"""Get a single order
|
||||||
@ -223,8 +226,9 @@ class Proxy(proxy.Proxy):
|
|||||||
:returns: One :class:`~openstack.key_manager.v1.secret.Secret` or
|
:returns: One :class:`~openstack.key_manager.v1.secret.Secret` or
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
return self._find(_secret.Secret, name_or_id,
|
return self._find(
|
||||||
ignore_missing=ignore_missing)
|
_secret.Secret, name_or_id, ignore_missing=ignore_missing
|
||||||
|
)
|
||||||
|
|
||||||
def get_secret(self, secret):
|
def get_secret(self, secret):
|
||||||
"""Get a single secret
|
"""Get a single secret
|
||||||
|
@ -30,8 +30,8 @@ class Container(resource.Resource):
|
|||||||
container_ref = resource.Body('container_ref')
|
container_ref = resource.Body('container_ref')
|
||||||
#: The ID for this container
|
#: The ID for this container
|
||||||
container_id = resource.Body(
|
container_id = resource.Body(
|
||||||
'container_ref', alternate_id=True,
|
'container_ref', alternate_id=True, type=_format.HREFToUUID
|
||||||
type=_format.HREFToUUID)
|
)
|
||||||
#: The timestamp when this container was created.
|
#: The timestamp when this container was created.
|
||||||
created_at = resource.Body('created')
|
created_at = resource.Body('created')
|
||||||
#: The name of this container
|
#: The name of this container
|
||||||
|
@ -36,7 +36,8 @@ class Order(resource.Resource):
|
|||||||
order_ref = resource.Body('order_ref')
|
order_ref = resource.Body('order_ref')
|
||||||
#: The ID of this order
|
#: The ID of this order
|
||||||
order_id = resource.Body(
|
order_id = resource.Body(
|
||||||
'order_ref', alternate_id=True, type=_format.HREFToUUID)
|
'order_ref', alternate_id=True, type=_format.HREFToUUID
|
||||||
|
)
|
||||||
#: Secret href associated with the order
|
#: Secret href associated with the order
|
||||||
secret_ref = resource.Body('secret_ref')
|
secret_ref = resource.Body('secret_ref')
|
||||||
#: Secret ID associated with the order
|
#: Secret ID associated with the order
|
||||||
|
@ -27,11 +27,17 @@ class Secret(resource.Resource):
|
|||||||
allow_list = True
|
allow_list = True
|
||||||
|
|
||||||
_query_mapping = resource.QueryParameters(
|
_query_mapping = resource.QueryParameters(
|
||||||
"name", "mode", "bits",
|
"name",
|
||||||
"secret_type", "acl_only",
|
"mode",
|
||||||
"created", "updated",
|
"bits",
|
||||||
"expiration", "sort",
|
"secret_type",
|
||||||
algorithm="alg")
|
"acl_only",
|
||||||
|
"created",
|
||||||
|
"updated",
|
||||||
|
"expiration",
|
||||||
|
"sort",
|
||||||
|
algorithm="alg",
|
||||||
|
)
|
||||||
|
|
||||||
# Properties
|
# Properties
|
||||||
#: Metadata provided by a user or system for informational purposes
|
#: Metadata provided by a user or system for informational purposes
|
||||||
@ -59,7 +65,8 @@ class Secret(resource.Resource):
|
|||||||
# in all of OpenStack because of the departure from using actual IDs
|
# in all of OpenStack because of the departure from using actual IDs
|
||||||
# that even this service can't even use itself.
|
# that even this service can't even use itself.
|
||||||
secret_id = resource.Body(
|
secret_id = resource.Body(
|
||||||
'secret_ref', alternate_id=True, type=_format.HREFToUUID)
|
'secret_ref', alternate_id=True, type=_format.HREFToUUID
|
||||||
|
)
|
||||||
#: Used to indicate the type of secret being stored.
|
#: Used to indicate the type of secret being stored.
|
||||||
secret_type = resource.Body('secret_type')
|
secret_type = resource.Body('secret_type')
|
||||||
#: The status of this secret
|
#: The status of this secret
|
||||||
@ -77,10 +84,17 @@ class Secret(resource.Resource):
|
|||||||
#: (required if payload is encoded)
|
#: (required if payload is encoded)
|
||||||
payload_content_encoding = resource.Body('payload_content_encoding')
|
payload_content_encoding = resource.Body('payload_content_encoding')
|
||||||
|
|
||||||
def fetch(self, session, requires_id=True,
|
def fetch(
|
||||||
base_path=None, error_message=None, skip_cache=False):
|
self,
|
||||||
request = self._prepare_request(requires_id=requires_id,
|
session,
|
||||||
base_path=base_path)
|
requires_id=True,
|
||||||
|
base_path=None,
|
||||||
|
error_message=None,
|
||||||
|
skip_cache=False,
|
||||||
|
):
|
||||||
|
request = self._prepare_request(
|
||||||
|
requires_id=requires_id, base_path=base_path
|
||||||
|
)
|
||||||
|
|
||||||
response = session.get(request.url).json()
|
response = session.get(request.url).json()
|
||||||
|
|
||||||
@ -96,7 +110,8 @@ class Secret(resource.Resource):
|
|||||||
payload = session.get(
|
payload = session.get(
|
||||||
utils.urljoin(request.url, "payload"),
|
utils.urljoin(request.url, "payload"),
|
||||||
headers={"Accept": content_type},
|
headers={"Accept": content_type},
|
||||||
skip_cache=skip_cache)
|
skip_cache=skip_cache,
|
||||||
|
)
|
||||||
response["payload"] = payload.text
|
response["payload"] = payload.text
|
||||||
|
|
||||||
# We already have the JSON here so don't call into _translate_response
|
# We already have the JSON here so don't call into _translate_response
|
||||||
|
@ -24,12 +24,11 @@ EXAMPLE = {
|
|||||||
'status': '5',
|
'status': '5',
|
||||||
'type': '6',
|
'type': '6',
|
||||||
'updated': '2015-03-09T12:15:57.233772',
|
'updated': '2015-03-09T12:15:57.233772',
|
||||||
'consumers': ['7']
|
'consumers': ['7'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class TestContainer(base.TestCase):
|
class TestContainer(base.TestCase):
|
||||||
|
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
sot = container.Container()
|
sot = container.Container()
|
||||||
self.assertIsNone(sot.resource_key)
|
self.assertIsNone(sot.resource_key)
|
||||||
|
@ -27,12 +27,11 @@ EXAMPLE = {
|
|||||||
'sub_status': '7',
|
'sub_status': '7',
|
||||||
'sub_status_message': '8',
|
'sub_status_message': '8',
|
||||||
'type': '9',
|
'type': '9',
|
||||||
'updated': '10'
|
'updated': '10',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class TestOrder(base.TestCase):
|
class TestOrder(base.TestCase):
|
||||||
|
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
sot = order.Order()
|
sot = order.Order()
|
||||||
self.assertIsNone(sot.resource_key)
|
self.assertIsNone(sot.resource_key)
|
||||||
|
@ -28,12 +28,14 @@ class TestKeyManagerContainer(TestKeyManagerProxy):
|
|||||||
self.verify_create(self.proxy.create_container, container.Container)
|
self.verify_create(self.proxy.create_container, container.Container)
|
||||||
|
|
||||||
def test_container_delete(self):
|
def test_container_delete(self):
|
||||||
self.verify_delete(self.proxy.delete_container,
|
self.verify_delete(
|
||||||
container.Container, False)
|
self.proxy.delete_container, container.Container, False
|
||||||
|
)
|
||||||
|
|
||||||
def test_container_delete_ignore(self):
|
def test_container_delete_ignore(self):
|
||||||
self.verify_delete(self.proxy.delete_container,
|
self.verify_delete(
|
||||||
container.Container, True)
|
self.proxy.delete_container, container.Container, True
|
||||||
|
)
|
||||||
|
|
||||||
def test_container_find(self):
|
def test_container_find(self):
|
||||||
self.verify_find(self.proxy.find_container, container.Container)
|
self.verify_find(self.proxy.find_container, container.Container)
|
||||||
@ -87,8 +89,8 @@ class TestKeyManagerSecret(TestKeyManagerProxy):
|
|||||||
def test_secret_get(self):
|
def test_secret_get(self):
|
||||||
self.verify_get(self.proxy.get_secret, secret.Secret)
|
self.verify_get(self.proxy.get_secret, secret.Secret)
|
||||||
self.verify_get_overrided(
|
self.verify_get_overrided(
|
||||||
self.proxy, secret.Secret,
|
self.proxy, secret.Secret, 'openstack.key_manager.v1.secret.Secret'
|
||||||
'openstack.key_manager.v1.secret.Secret')
|
)
|
||||||
|
|
||||||
def test_secrets(self):
|
def test_secrets(self):
|
||||||
self.verify_list(self.proxy.secrets, secret.Secret)
|
self.verify_list(self.proxy.secrets, secret.Secret)
|
||||||
|
@ -31,12 +31,11 @@ EXAMPLE = {
|
|||||||
'secret_type': '9',
|
'secret_type': '9',
|
||||||
'payload': '10',
|
'payload': '10',
|
||||||
'payload_content_type': '11',
|
'payload_content_type': '11',
|
||||||
'payload_content_encoding': '12'
|
'payload_content_encoding': '12',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class TestSecret(base.TestCase):
|
class TestSecret(base.TestCase):
|
||||||
|
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
sot = secret.Secret()
|
sot = secret.Secret()
|
||||||
self.assertIsNone(sot.resource_key)
|
self.assertIsNone(sot.resource_key)
|
||||||
@ -48,19 +47,23 @@ class TestSecret(base.TestCase):
|
|||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
|
|
||||||
self.assertDictEqual({"name": "name",
|
self.assertDictEqual(
|
||||||
"mode": "mode",
|
{
|
||||||
"bits": "bits",
|
"name": "name",
|
||||||
"secret_type": "secret_type",
|
"mode": "mode",
|
||||||
"acl_only": "acl_only",
|
"bits": "bits",
|
||||||
"created": "created",
|
"secret_type": "secret_type",
|
||||||
"updated": "updated",
|
"acl_only": "acl_only",
|
||||||
"expiration": "expiration",
|
"created": "created",
|
||||||
"sort": "sort",
|
"updated": "updated",
|
||||||
"algorithm": "alg",
|
"expiration": "expiration",
|
||||||
"limit": "limit",
|
"sort": "sort",
|
||||||
"marker": "marker"},
|
"algorithm": "alg",
|
||||||
sot._query_mapping._mapping)
|
"limit": "limit",
|
||||||
|
"marker": "marker",
|
||||||
|
},
|
||||||
|
sot._query_mapping._mapping,
|
||||||
|
)
|
||||||
|
|
||||||
def test_make_it(self):
|
def test_make_it(self):
|
||||||
sot = secret.Secret(**EXAMPLE)
|
sot = secret.Secret(**EXAMPLE)
|
||||||
@ -77,10 +80,12 @@ class TestSecret(base.TestCase):
|
|||||||
self.assertEqual(EXAMPLE['updated'], sot.updated_at)
|
self.assertEqual(EXAMPLE['updated'], sot.updated_at)
|
||||||
self.assertEqual(EXAMPLE['secret_type'], sot.secret_type)
|
self.assertEqual(EXAMPLE['secret_type'], sot.secret_type)
|
||||||
self.assertEqual(EXAMPLE['payload'], sot.payload)
|
self.assertEqual(EXAMPLE['payload'], sot.payload)
|
||||||
self.assertEqual(EXAMPLE['payload_content_type'],
|
self.assertEqual(
|
||||||
sot.payload_content_type)
|
EXAMPLE['payload_content_type'], sot.payload_content_type
|
||||||
self.assertEqual(EXAMPLE['payload_content_encoding'],
|
)
|
||||||
sot.payload_content_encoding)
|
self.assertEqual(
|
||||||
|
EXAMPLE['payload_content_encoding'], sot.payload_content_encoding
|
||||||
|
)
|
||||||
|
|
||||||
def test_get_no_payload(self):
|
def test_get_no_payload(self):
|
||||||
sot = secret.Secret(id="id")
|
sot = secret.Secret(id="id")
|
||||||
@ -112,11 +117,17 @@ class TestSecret(base.TestCase):
|
|||||||
rv = sot.fetch(sess)
|
rv = sot.fetch(sess)
|
||||||
|
|
||||||
sess.get.assert_has_calls(
|
sess.get.assert_has_calls(
|
||||||
[mock.call("secrets/id",),
|
[
|
||||||
mock.call(
|
mock.call(
|
||||||
"secrets/id/payload",
|
"secrets/id",
|
||||||
headers={"Accept": content_type},
|
),
|
||||||
skip_cache=False)])
|
mock.call(
|
||||||
|
"secrets/id/payload",
|
||||||
|
headers={"Accept": content_type},
|
||||||
|
skip_cache=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(rv.payload, payload)
|
self.assertEqual(rv.payload, payload)
|
||||||
self.assertEqual(rv.status, metadata["status"])
|
self.assertEqual(rv.status, metadata["status"])
|
||||||
@ -129,7 +140,9 @@ class TestSecret(base.TestCase):
|
|||||||
|
|
||||||
def test_get_with_payload_from_content_types(self):
|
def test_get_with_payload_from_content_types(self):
|
||||||
content_type = "some/type"
|
content_type = "some/type"
|
||||||
metadata = {"status": "fine",
|
metadata = {
|
||||||
"content_types": {"default": content_type}}
|
"status": "fine",
|
||||||
|
"content_types": {"default": content_type},
|
||||||
|
}
|
||||||
sot = secret.Secret(id="id")
|
sot = secret.Secret(id="id")
|
||||||
self._test_payload(sot, metadata, content_type)
|
self._test_payload(sot, metadata, content_type)
|
||||||
|
Loading…
Reference in New Issue
Block a user