From d85c7eef001def20b37ae19bca0fdec234140522 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 20 Mar 2020 14:45:16 +0100 Subject: [PATCH] Add support for Identity Providers Change-Id: I7f0ea852fd03ecca64e0387e5019335a4664aba6 Depends-On: https://review.opendev.org/714120 --- openstack/identity/v3/_proxy.py | 91 +++++++++++++++++++ openstack/identity/v3/identity_provider.py | 48 ++++++++++ .../identity/v3/test_identity_provider.py | 59 ++++++++++++ 3 files changed, 198 insertions(+) create mode 100644 openstack/identity/v3/identity_provider.py create mode 100644 openstack/tests/unit/identity/v3/test_identity_provider.py diff --git a/openstack/identity/v3/_proxy.py b/openstack/identity/v3/_proxy.py index 461fbefb9..f7da56a15 100644 --- a/openstack/identity/v3/_proxy.py +++ b/openstack/identity/v3/_proxy.py @@ -17,6 +17,7 @@ from openstack.identity.v3 import credential as _credential from openstack.identity.v3 import domain as _domain from openstack.identity.v3 import endpoint as _endpoint from openstack.identity.v3 import group as _group +from openstack.identity.v3 import identity_provider as _identity_provider from openstack.identity.v3 import limit as _limit from openstack.identity.v3 import mapping as _mapping from openstack.identity.v3 import policy as _policy @@ -1400,3 +1401,93 @@ class Proxy(proxy.Proxy): :rtype: :class:`~openstack.identity.v3.mapping.Mapping` """ return self._update(_mapping.Mapping, mapping, **attrs) + + def create_identity_provider(self, **attrs): + """Create a new identity provider from attributes + + :param dict attrs: Keyword arguments which will be used to create a + :class:`~openstack.identity.v3.identity_provider.IdentityProvider` + comprised of the properties on the IdentityProvider class. + + :returns: The results of identity provider creation + :rtype: + :class:`~openstack.identity.v3.identity_provider.IdentityProvider` + """ + return self._create(_identity_provider.IdentityProvider, **attrs) + + def delete_identity_provider(self, identity_provider, ignore_missing=True): + """Delete an identity provider + + :param mapping: The ID of an identity provoder or a + :class:`~openstack.identity.v3.identity_provider.IdentityProvider` + instance. + :param bool ignore_missing: When set to ``False`` + :class:`~openstack.exceptions.ResourceNotFound` will be + raised when the identity provider does not exist. + When set to ``True``, no exception will be set when + attempting to delete a nonexistent identity provider. + + :returns: ``None`` + """ + self._delete(_identity_provider.IdentityProvider, identity_provider, + ignore_missing=ignore_missing) + + def find_identity_provider(self, name_or_id, ignore_missing=True): + """Find a single identity provider + + :param name_or_id: The name or ID of an identity provider + :param bool ignore_missing: When set to ``False`` + :class:`~openstack.exceptions.ResourceNotFound` will be + raised when the resource does not exist. + When set to ``True``, None will be returned when + attempting to find a nonexistent resource. + :returns: The details of an identity provider or None. + :rtype: + :class:`~openstack.identity.v3.identity_provider.IdentityProvider` + """ + return self._find(_identity_provider.IdentityProvider, name_or_id, + ignore_missing=ignore_missing) + + def get_identity_provider(self, identity_provider): + """Get a single mapping + + :param mapping: The value can be the ID of an identity provider or a + :class:`~openstack.identity.v3.identity_provider.IdentityProvider` + instance. + + :returns: The details of an identity provider. + :rtype: + :class:`~openstack.identity.v3.identity_provider.IdentityProvider` + :raises: :class:`~openstack.exceptions.ResourceNotFound` + when no resource can be found. + """ + return self._get(_identity_provider.IdentityProvider, + identity_provider) + + def identity_providers(self, **query): + """Retrieve a generator of identity providers + + :param kwargs query: Optional query parameters to be sent to limit + the resources being returned. + + :returns: A generator of identity provider instances. + :rtype: + :class:`~openstack.identity.v3.identity_provider.IdentityProvider` + """ + return self._list(_identity_provider.IdentityProvider, **query) + + def update_identity_provider(self, identity_provider, **attrs): + """Update a mapping + + :param mapping: Either the ID of an identity provider or a + :class:`~openstack.identity.v3.identity_provider.IdentityProvider` + instance. + :attrs kwargs: The attributes to update on the identity_provider + represented by ``value``. + + :returns: The updated identity provider. + :rtype: + :class:`~openstack.identity.v3.identity_provider.IdentityProvider` + """ + return self._update(_identity_provider.IdentityProvider, + identity_provider, **attrs) diff --git a/openstack/identity/v3/identity_provider.py b/openstack/identity/v3/identity_provider.py new file mode 100644 index 000000000..6baea2551 --- /dev/null +++ b/openstack/identity/v3/identity_provider.py @@ -0,0 +1,48 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack import resource + + +class IdentityProvider(resource.Resource): + resource_key = 'identity_provider' + resources_key = 'identity_providers' + base_path = '/OS-FEDERATION/identity_providers' + + # capabilities + allow_create = True + allow_fetch = True + allow_commit = True + allow_delete = True + allow_list = True + create_method = 'PUT' + create_exclude_id_from_body = True + commit_method = 'PATCH' + + _query_mapping = resource.QueryParameters( + 'id', + is_enabled='enabled', + ) + + # Properties + #: The id of a domain associated with this identity provider. + # *Type: string* + domain_id = resource.Body('domain_id') + #: A description of this identity provider. *Type: string* + description = resource.Body('description') + #: If the identity provider is currently enabled. *Type: bool* + is_enabled = resource.Body('enabled', type=bool) + #: Remote IDs associated with the identity provider. *Type: list* + remote_ids = resource.Body('remote_ids', type=list) + + #: The identifier of the identity provider (read only). *Type: string* + name = resource.Body('id') diff --git a/openstack/tests/unit/identity/v3/test_identity_provider.py b/openstack/tests/unit/identity/v3/test_identity_provider.py new file mode 100644 index 000000000..c3c9c512f --- /dev/null +++ b/openstack/tests/unit/identity/v3/test_identity_provider.py @@ -0,0 +1,59 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack.tests.unit import base + +from openstack.identity.v3 import identity_provider + +IDENTIFIER = 'IDENTIFIER' +EXAMPLE = { + 'id': IDENTIFIER, + 'domain_id': 'example_domain', + 'description': 'An example description', + 'is_enabled': True, + 'remote_ids': ['https://auth.example.com/auth/realms/ExampleRealm'], +} + + +class TestIdentityProvider(base.TestCase): + + def test_basic(self): + sot = identity_provider.IdentityProvider() + self.assertEqual('identity_provider', sot.resource_key) + self.assertEqual('identity_providers', sot.resources_key) + self.assertEqual('/OS-FEDERATION/identity_providers', sot.base_path) + self.assertTrue(sot.allow_create) + self.assertTrue(sot.allow_fetch) + self.assertTrue(sot.allow_commit) + self.assertTrue(sot.allow_delete) + self.assertTrue(sot.allow_list) + self.assertTrue(sot.create_exclude_id_from_body) + self.assertEqual('PATCH', sot.commit_method) + self.assertEqual('PUT', sot.create_method) + + self.assertDictEqual( + { + 'id': 'id', + 'limit': 'limit', + 'marker': 'marker', + 'is_enabled': 'enabled', + }, + sot._query_mapping._mapping) + + def test_make_it(self): + sot = identity_provider.IdentityProvider(**EXAMPLE) + self.assertEqual(EXAMPLE['id'], sot.id) + self.assertEqual(EXAMPLE['id'], sot.name) + self.assertEqual(EXAMPLE['domain_id'], sot.domain_id) + self.assertEqual(EXAMPLE['description'], sot.description) + self.assertEqual(EXAMPLE['is_enabled'], sot.is_enabled) + self.assertEqual(EXAMPLE['remote_ids'], sot.remote_ids)