diff --git a/contrib/heat_barbican/heat_barbican/client.py b/contrib/heat_barbican/heat_barbican/client.py index e331da8e0b..2dec88e133 100644 --- a/contrib/heat_barbican/heat_barbican/client.py +++ b/contrib/heat_barbican/heat_barbican/client.py @@ -16,18 +16,20 @@ from heat.engine.clients import client_plugin try: from barbicanclient import client as barbican_client - from barbicanclient.common import auth except ImportError: barbican_client = None - auth = None class BarbicanClientPlugin(client_plugin.ClientPlugin): def _create(self): - keystone_client = self.clients.client('keystone').client - auth_plugin = auth.KeystoneAuthV2(keystone=keystone_client) - client = barbican_client.Client(auth_plugin=auth_plugin) + endpoint_type = self._get_client_option('barbican', 'endpoint_type') + endpoint = self.url_for(service_type='key-manager', + endpoint_type=endpoint_type) + # Remove version if set + endpoint = endpoint.rsplit("/", 1)[0] + client = barbican_client.Client( + session=keystone_client.session, endpoint=endpoint) return client diff --git a/contrib/heat_barbican/heat_barbican/resources/order.py b/contrib/heat_barbican/heat_barbican/resources/order.py index 5032336a39..0818dc47c7 100644 --- a/contrib/heat_barbican/heat_barbican/resources/order.py +++ b/contrib/heat_barbican/heat_barbican/resources/order.py @@ -109,13 +109,13 @@ class Order(resource.Resource): def handle_create(self): info = dict(self.properties) - order = self.barbican().orders.Order(**info) + order = self.barbican().orders.create_key(**info) order_ref = order.submit() self.resource_id_set(order_ref) return order_ref def check_create_complete(self, order_href): - order = self.barbican().orders.Order(order_href) + order = self.barbican().orders.get(order_href) if order.status == 'ERROR': reason = order.error_reason @@ -140,7 +140,7 @@ class Order(resource.Resource): raise def _resolve_attribute(self, name): - order = self.barbican().orders.Order(self.resource_id) + order = self.barbican().orders.get(self.resource_id) return getattr(order, name) diff --git a/contrib/heat_barbican/heat_barbican/resources/secret.py b/contrib/heat_barbican/heat_barbican/resources/secret.py index 7a22864959..1822c3ee35 100644 --- a/contrib/heat_barbican/heat_barbican/resources/secret.py +++ b/contrib/heat_barbican/heat_barbican/resources/secret.py @@ -126,7 +126,7 @@ class Secret(resource.Resource): def handle_create(self): info = dict(self.properties) - secret = self.barbican().secrets.Secret(**info) + secret = self.barbican().secrets.create(**info) secret_ref = secret.store() self.resource_id_set(secret_ref) return secret_ref @@ -145,7 +145,7 @@ class Secret(resource.Resource): raise def _resolve_attribute(self, name): - secret = self.barbican().secrets.Secret(self.resource_id) + secret = self.barbican().secrets.get(self.resource_id) if name == self.DECRYPTED_PAYLOAD: return secret.payload diff --git a/contrib/heat_barbican/heat_barbican/tests/test_order.py b/contrib/heat_barbican/heat_barbican/tests/test_order.py index f16daa142c..b405cfe385 100644 --- a/contrib/heat_barbican/heat_barbican/tests/test_order.py +++ b/contrib/heat_barbican/heat_barbican/tests/test_order.py @@ -77,7 +77,7 @@ class TestOrder(common.HeatTestCase): def _create_resource(self, name, snippet, stack): res = order.Order(name, snippet, stack) res.check_create_complete = mock.Mock(return_value=True) - self.barbican.orders.Order.return_value = FakeOrder(name) + self.barbican.orders.create_key.return_value = FakeOrder(name) scheduler.TaskRunner(res.create)() return res @@ -85,7 +85,7 @@ class TestOrder(common.HeatTestCase): res = self._create_resource('foo', self.res_template, self.stack) expected_state = (res.CREATE, res.COMPLETE) self.assertEqual(expected_state, res.state) - args = self.barbican.orders.Order.call_args[1] + args = self.barbican.orders.create_key.call_args[1] self.assertEqual('foobar-order', args['name']) self.assertEqual('aes', args['algorithm']) self.assertEqual('cbc', args['mode']) @@ -98,7 +98,7 @@ class TestOrder(common.HeatTestCase): mock_order.secret_ref = 'test-secret-ref' res = self._create_resource('foo', self.res_template, self.stack) - self.barbican.orders.Order.return_value = mock_order + self.barbican.orders.get.return_value = mock_order self.assertEqual('test-order-ref', res.FnGetAtt('order_ref')) self.assertEqual('test-secret-ref', res.FnGetAtt('secret_ref')) @@ -106,15 +106,15 @@ class TestOrder(common.HeatTestCase): def test_attributes_handle_exceptions(self): mock_order = mock.Mock() res = self._create_resource('foo', self.res_template, self.stack) - self.barbican.orders.Order.return_value = mock_order + self.barbican.orders.get.return_value = mock_order self.barbican.barbican_client.HTTPClientError = Exception - self.barbican.orders.Order.side_effect = Exception('boom') + self.barbican.orders.get.side_effect = Exception('boom') self.assertRaises(self.barbican.barbican_client.HTTPClientError, res.FnGetAtt, 'order_ref') def test_create_order_sets_resource_id(self): - self.barbican.orders.Order.return_value = FakeOrder('foo') + self.barbican.orders.create_key.return_value = FakeOrder('foo') res = self._create_resource('foo', self.res_template, self.stack) self.assertEqual('foo', res.resource_id) @@ -122,7 +122,7 @@ class TestOrder(common.HeatTestCase): def test_create_order_defaults_to_octet_stream(self): res = self._create_resource('foo', self.res_template, self.stack) - args = self.barbican.orders.Order.call_args[1] + args = self.barbican.orders.create_key.call_args[1] self.assertEqual('application/octet-stream', args[res.PAYLOAD_CONTENT_TYPE]) @@ -133,7 +133,7 @@ class TestOrder(common.HeatTestCase): self.props) res = self._create_resource(defn.name, defn, self.stack) - args = self.barbican.orders.Order.call_args[1] + args = self.barbican.orders.create_key.call_args[1] self.assertEqual(content_type, args[res.PAYLOAD_CONTENT_TYPE]) def test_create_order_other_content_types_now_allowed(self): @@ -146,7 +146,7 @@ class TestOrder(common.HeatTestCase): scheduler.TaskRunner(res.create)) def test_delete_order(self): - self.barbican.orders.Order.return_value = 'foo' + self.barbican.orders.create_key.return_value = 'foo' res = self._create_resource('foo', self.res_template, self.stack) self.assertEqual('foo', res.resource_id) @@ -176,16 +176,16 @@ class TestOrder(common.HeatTestCase): res = order.Order('foo', self.res_template, self.stack) mock_active = mock.Mock(status='ACTIVE') - self.barbican.orders.Order.return_value = mock_active + self.barbican.orders.get.return_value = mock_active self.assertTrue(res.check_create_complete('foo')) mock_not_active = mock.Mock(status='PENDING') - self.barbican.orders.Order.return_value = mock_not_active + self.barbican.orders.get.return_value = mock_not_active self.assertFalse(res.check_create_complete('foo')) mock_not_active = mock.Mock(status='ERROR', error_reason='foo', error_status_code=500) - self.barbican.orders.Order.return_value = mock_not_active + self.barbican.orders.get.return_value = mock_not_active exc = self.assertRaises(exception.Error, res.check_create_complete, 'foo') self.assertIn('foo', six.text_type(exc)) diff --git a/contrib/heat_barbican/heat_barbican/tests/test_secret.py b/contrib/heat_barbican/heat_barbican/tests/test_secret.py index d3a83a7fe3..50bbb959e6 100644 --- a/contrib/heat_barbican/heat_barbican/tests/test_secret.py +++ b/contrib/heat_barbican/heat_barbican/tests/test_secret.py @@ -73,20 +73,20 @@ class TestSecret(common.HeatTestCase): def _create_resource(self, name, snippet, stack): res = secret.Secret(name, snippet, stack) - self.barbican.secrets.Secret.return_value = FakeSecret(name + '_id') + self.barbican.secrets.create.return_value = FakeSecret(name + '_id') scheduler.TaskRunner(res.create)() return res def test_create_secret(self): expected_state = (self.res.CREATE, self.res.COMPLETE) self.assertEqual(expected_state, self.res.state) - args = self.barbican.secrets.Secret.call_args[1] + args = self.barbican.secrets.create.call_args[1] self.assertEqual('foobar-secret', args['name']) def test_attributes(self): mock_secret = mock.Mock() mock_secret.status = 'test-status' - self.barbican.secrets.Secret.return_value = mock_secret + self.barbican.secrets.get.return_value = mock_secret mock_secret.payload = 'foo' self.assertEqual('test-status', self.res.FnGetAtt('status')) @@ -94,7 +94,7 @@ class TestSecret(common.HeatTestCase): def test_attributes_handles_exceptions(self): self.barbican.barbican_client.HTTPClientError = Exception - self.barbican.secrets.Secret.side_effect = Exception('boom') + self.barbican.secrets.get.side_effect = Exception('boom') self.assertRaises(self.barbican.barbican_client.HTTPClientError, self.res.FnGetAtt, 'order_ref') @@ -113,7 +113,7 @@ class TestSecret(common.HeatTestCase): props) res = self._create_resource(defn.name, defn, self.stack) - args = self.barbican.secrets.Secret.call_args[1] + args = self.barbican.secrets.create.call_args[1] self.assertEqual('foobar', args[res.PAYLOAD]) self.assertEqual(content_type, args[res.PAYLOAD_CONTENT_TYPE]) @@ -129,7 +129,7 @@ class TestSecret(common.HeatTestCase): props) res = self._create_resource(defn.name, defn, self.stack) - args = self.barbican.secrets.Secret.call_args[1] + args = self.barbican.secrets.create.call_args[1] self.assertEqual('foobar', args[res.PAYLOAD]) self.assertEqual(content_type, args[res.PAYLOAD_CONTENT_TYPE])