Merge "List federated projects and domains"
This commit is contained in:
@@ -15,9 +15,12 @@ import uuid
|
||||
|
||||
from keystoneclient import exceptions
|
||||
from keystoneclient.tests.v3 import utils
|
||||
from keystoneclient.v3.contrib.federation import base
|
||||
from keystoneclient.v3.contrib.federation import identity_providers
|
||||
from keystoneclient.v3.contrib.federation import mappings
|
||||
from keystoneclient.v3.contrib.federation import protocols
|
||||
from keystoneclient.v3 import domains
|
||||
from keystoneclient.v3 import projects
|
||||
|
||||
|
||||
class IdentityProviderTests(utils.TestCase, utils.CrudTests):
|
||||
@@ -313,3 +316,72 @@ class ProtocolTests(utils.TestCase, utils.CrudTests):
|
||||
self.assertEqual(expected, returned.to_dict())
|
||||
request_body = {'mapping_id': request_args['mapping']}
|
||||
self.assertEntityRequestBodyIs(request_body)
|
||||
|
||||
|
||||
class EntityManagerTests(utils.TestCase):
|
||||
def test_create_object_expect_fail(self):
|
||||
self.assertRaises(TypeError,
|
||||
base.EntityManager,
|
||||
self.client)
|
||||
|
||||
|
||||
class FederationProjectTests(utils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(FederationProjectTests, self).setUp()
|
||||
self.key = 'project'
|
||||
self.collection_key = 'projects'
|
||||
self.model = projects.Project
|
||||
self.manager = self.client.federation.projects
|
||||
self.URL = "%s%s" % (self.TEST_URL, '/OS-FEDERATION/projects')
|
||||
|
||||
def new_ref(self, **kwargs):
|
||||
kwargs.setdefault('id', uuid.uuid4().hex)
|
||||
kwargs.setdefault('domain_id', uuid.uuid4().hex)
|
||||
kwargs.setdefault('enabled', True)
|
||||
kwargs.setdefault('name', uuid.uuid4().hex)
|
||||
return kwargs
|
||||
|
||||
def test_list_accessible_projects(self):
|
||||
projects_ref = [self.new_ref(), self.new_ref()]
|
||||
projects_json = {
|
||||
self.collection_key: [self.new_ref(), self.new_ref()]
|
||||
}
|
||||
self.requests.register_uri('GET', self.URL,
|
||||
json=projects_json, status_code=200)
|
||||
returned_list = self.manager.list()
|
||||
|
||||
self.assertEqual(len(projects_ref), len(returned_list))
|
||||
for project in returned_list:
|
||||
self.assertIsInstance(project, self.model)
|
||||
|
||||
|
||||
class FederationDomainTests(utils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(FederationDomainTests, self).setUp()
|
||||
self.key = 'domain'
|
||||
self.collection_key = 'domains'
|
||||
self.model = domains.Domain
|
||||
self.manager = self.client.federation.domains
|
||||
|
||||
self.URL = "%s%s" % (self.TEST_URL, '/OS-FEDERATION/domains')
|
||||
|
||||
def new_ref(self, **kwargs):
|
||||
kwargs.setdefault('id', uuid.uuid4().hex)
|
||||
kwargs.setdefault('enabled', True)
|
||||
kwargs.setdefault('name', uuid.uuid4().hex)
|
||||
kwargs.setdefault('description', uuid.uuid4().hex)
|
||||
return kwargs
|
||||
|
||||
def test_list_accessible_domains(self):
|
||||
domains_ref = [self.new_ref(), self.new_ref()]
|
||||
domains_json = {
|
||||
self.collection_key: domains_ref
|
||||
}
|
||||
self.requests.register_uri('GET', self.URL,
|
||||
json=domains_json, status_code=200)
|
||||
returned_list = self.manager.list()
|
||||
self.assertEqual(len(domains_ref), len(returned_list))
|
||||
for domain in returned_list:
|
||||
self.assertIsInstance(domain, self.model)
|
||||
|
38
keystoneclient/v3/contrib/federation/base.py
Normal file
38
keystoneclient/v3/contrib/federation/base.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# 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.
|
||||
|
||||
import abc
|
||||
import six
|
||||
|
||||
from keystoneclient.auth import base as base_auth
|
||||
from keystoneclient import base
|
||||
from keystoneclient import exceptions
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class EntityManager(base.Manager):
|
||||
"""Manager class for listing federated accessible objects."""
|
||||
resource_class = None
|
||||
|
||||
@abc.abstractproperty
|
||||
def object_type(self):
|
||||
raise exceptions.MethodNotImplemented
|
||||
|
||||
def list(self):
|
||||
url = '/OS-FEDERATION/%s' % self.object_type
|
||||
try:
|
||||
tenant_list = self._list(url, self.object_type)
|
||||
except exceptions.EndpointNotFound:
|
||||
endpoint_filter = {'interface': base_auth.AUTH_INTERFACE}
|
||||
tenant_list = self._list(url, self.object_type,
|
||||
endpoint_filter=endpoint_filter)
|
||||
return tenant_list
|
@@ -10,8 +10,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from keystoneclient.v3.contrib.federation import domains
|
||||
from keystoneclient.v3.contrib.federation import identity_providers
|
||||
from keystoneclient.v3.contrib.federation import mappings
|
||||
from keystoneclient.v3.contrib.federation import projects
|
||||
from keystoneclient.v3.contrib.federation import protocols
|
||||
|
||||
|
||||
@@ -21,3 +23,5 @@ class FederationManager(object):
|
||||
api)
|
||||
self.mappings = mappings.MappingManager(api)
|
||||
self.protocols = protocols.ProtocolManager(api)
|
||||
self.projects = projects.ProjectManager(api)
|
||||
self.domains = domains.DomainManager(api)
|
||||
|
19
keystoneclient/v3/contrib/federation/domains.py
Normal file
19
keystoneclient/v3/contrib/federation/domains.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# 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 keystoneclient.v3.contrib.federation import base as federation_base
|
||||
from keystoneclient.v3 import domains
|
||||
|
||||
|
||||
class DomainManager(federation_base.EntityManager):
|
||||
object_type = 'domains'
|
||||
resource_class = domains.Domain
|
19
keystoneclient/v3/contrib/federation/projects.py
Normal file
19
keystoneclient/v3/contrib/federation/projects.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# 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 keystoneclient.v3.contrib.federation import base as federation_base
|
||||
from keystoneclient.v3 import projects
|
||||
|
||||
|
||||
class ProjectManager(federation_base.EntityManager):
|
||||
object_type = 'projects'
|
||||
resource_class = projects.Project
|
Reference in New Issue
Block a user