diff --git a/api-ref/source/v3-ext/ep-filter.inc b/api-ref/source/v3-ext/ep-filter.inc index 176e5a5b6a..97dd39ead9 100644 --- a/api-ref/source/v3-ext/ep-filter.inc +++ b/api-ref/source/v3-ext/ep-filter.inc @@ -266,6 +266,16 @@ List all available endpoint groups. Relationship: ``https://docs.openstack.org/api/openstack-identity/3/ext/OS-EP-FILTER/1.0/rel/endpoint_groups`` +Request +------- + +Parameters +~~~~~~~~~~ + +.. rest_parameters:: parameters.yaml + + - name: request_endpoint_group_name_query_not_required + Response -------- @@ -782,4 +792,4 @@ Example Status: 200 OK .. literalinclude:: samples/OS-EP-FILTER/endpoint-groups-response.json - :language: javascript \ No newline at end of file + :language: javascript diff --git a/api-ref/source/v3-ext/parameters.yaml b/api-ref/source/v3-ext/parameters.yaml index 65145a6e9e..2937fb6764 100644 --- a/api-ref/source/v3-ext/parameters.yaml +++ b/api-ref/source/v3-ext/parameters.yaml @@ -93,6 +93,13 @@ user_id_path: type: string # variables in query +request_endpoint_group_name_query_not_required: + description: | + Filters the response by an endpoint group name. + in: query + required: false + type: string + since_query: description: | A timestamp used to limit the list of results to events diff --git a/keystone/api/os_ep_filter.py b/keystone/api/os_ep_filter.py index 06e573fb65..9645496e73 100644 --- a/keystone/api/os_ep_filter.py +++ b/keystone/api/os_ep_filter.py @@ -66,9 +66,12 @@ class EndpointGroupsResource(ks_flask.ResourceBase): PROVIDERS.catalog_api.get_endpoint_group(endpoint_group_id)) def _list_endpoint_groups(self): - ENFORCER.enforce_call(action='identity:list_endpoint_groups') - return self.wrap_collection( - PROVIDERS.catalog_api.list_endpoint_groups()) + filters = ('name') + ENFORCER.enforce_call(action='identity:list_endpoint_groups', + filters=filters) + hints = self.build_driver_hints(filters) + refs = PROVIDERS.catalog_api.list_endpoint_groups(hints) + return self.wrap_collection(refs, hints=hints) def get(self, endpoint_group_id=None): if endpoint_group_id is not None: diff --git a/keystone/catalog/backends/base.py b/keystone/catalog/backends/base.py index 5b86f383bc..57e29f9976 100644 --- a/keystone/catalog/backends/base.py +++ b/keystone/catalog/backends/base.py @@ -441,7 +441,7 @@ class CatalogDriverBase(provider_api.ProviderAPIMixin, object): raise exception.NotImplemented() # pragma: no cover @abc.abstractmethod - def list_endpoint_groups(self): + def list_endpoint_groups(self, hints): """List all endpoint groups. :returns: None. diff --git a/keystone/catalog/backends/sql.py b/keystone/catalog/backends/sql.py index 77a718516c..27516315ad 100644 --- a/keystone/catalog/backends/sql.py +++ b/keystone/catalog/backends/sql.py @@ -548,10 +548,11 @@ class Catalog(base.CatalogDriverBase): else: return endpoint_group_project_ref - def list_endpoint_groups(self): + def list_endpoint_groups(self, hints): with sql.session_for_read() as session: query = session.query(EndpointGroup) - endpoint_group_refs = query.all() + endpoint_group_refs = sql.filter_limit_query( + EndpointGroup, query, hints) return [e.to_dict() for e in endpoint_group_refs] def list_endpoint_groups_for_project(self, project_id): diff --git a/keystone/catalog/backends/templated.py b/keystone/catalog/backends/templated.py index 44a3948956..8e1fbbfd27 100644 --- a/keystone/catalog/backends/templated.py +++ b/keystone/catalog/backends/templated.py @@ -326,7 +326,7 @@ class Catalog(base.CatalogDriverBase): def get_endpoint_group_in_project(self, endpoint_group_id, project_id): raise exception.NotImplemented() - def list_endpoint_groups(self): + def list_endpoint_groups(self, hints): raise exception.NotImplemented() def list_endpoint_groups_for_project(self, project_id): diff --git a/keystone/tests/unit/test_associate_project_endpoint_extension.py b/keystone/tests/unit/test_associate_project_endpoint_extension.py index 37c3a5d0b8..3b783a8d2f 100644 --- a/keystone/tests/unit/test_associate_project_endpoint_extension.py +++ b/keystone/tests/unit/test_associate_project_endpoint_extension.py @@ -1046,6 +1046,29 @@ class EndpointGroupCRUDTestCase(EndpointFilterTestCase): self.head(url, expected_status=http_client.OK) + def test_list_endpoint_groups_by_name(self): + """GET & HEAD /OS-EP-FILTER/endpoint_groups.""" + # create an endpoint group to work with + endpoint_group_id = self._create_valid_endpoint_group( + self.DEFAULT_ENDPOINT_GROUP_URL, self.DEFAULT_ENDPOINT_GROUP_BODY) + + # retrieve the single endpointgroup by name + url = ('/OS-EP-FILTER/endpoint_groups?name=%(name)s' % + {'name': 'endpoint_group_name'}) + r = self.get(url, expected_status=http_client.OK) + self.assertNotEmpty(r.result['endpoint_groups']) + self.assertEqual(1, len(r.result['endpoint_groups'])) + self.assertEqual(endpoint_group_id, + r.result['endpoint_groups'][0].get('id')) + + self.head(url, expected_status=http_client.OK) + + # try to retrieve a non existant one + url = ('/OS-EP-FILTER/endpoint_groups?name=%(name)s' % + {'name': 'fake'}) + r = self.get(url, expected_status=http_client.OK) + self.assertEqual(0, len(r.result['endpoint_groups'])) + def test_list_projects_associated_with_endpoint_group(self): """GET & HEAD /OS-EP-FILTER/endpoint_groups/{endpoint_group}/projects. diff --git a/releasenotes/notes/bug1828565-0790c4c60ba34100.yaml b/releasenotes/notes/bug1828565-0790c4c60ba34100.yaml new file mode 100644 index 0000000000..3f89c08cd2 --- /dev/null +++ b/releasenotes/notes/bug1828565-0790c4c60ba34100.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + [`bug 1828565 `_] + Fixes endpoint group listing by name. This allows the openstackclient + command to search endpoint groups by name.