From 9ac42de5a5e6a8c26666f789ebd92db6d9268fe0 Mon Sep 17 00:00:00 2001 From: Omer Date: Wed, 1 Oct 2025 15:09:37 +0300 Subject: [PATCH] Add description filter support to TLD list API The TLD list API endpoint previously only supported filtering by name, despite TLDs having a description field that is displayed in the client. This change adds 'description' to the accepted_filters in the TLDs controller, enabling users to filter TLDs by description using exact matches or wildcards. This brings TLD filtering in line with other resources such as zones and recordsets, which already support description filtering. Closes-Bug: #2116331 Generated-By: Claude Code Sonnet 4.5 Change-Id: Ia75345dc38d060bdd9f69d183e613373af1dca4f Signed-off-by: Omer --- api-ref/source/dns-api-v2-tld.inc | 1 + api-ref/source/parameters.yaml | 8 +++++++ designate/api/v2/controllers/tlds.py | 2 +- .../tests/functional/api/v2/test_tlds.py | 23 ++++++++++++++++++- ...d-description-filter-a7b8c9d0e1f2g3h4.yaml | 7 ++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/add-tld-description-filter-a7b8c9d0e1f2g3h4.yaml diff --git a/api-ref/source/dns-api-v2-tld.inc b/api-ref/source/dns-api-v2-tld.inc index 98d181934..750419d2e 100644 --- a/api-ref/source/dns-api-v2-tld.inc +++ b/api-ref/source/dns-api-v2-tld.inc @@ -155,6 +155,7 @@ Request - marker: marker - sort_dir: sort_dir - sort_key: sort_key + - description: tld_description_filter - name: tld_name_filter diff --git a/api-ref/source/parameters.yaml b/api-ref/source/parameters.yaml index 0cb7d962c..525685d43 100644 --- a/api-ref/source/parameters.yaml +++ b/api-ref/source/parameters.yaml @@ -280,6 +280,14 @@ target_project_id_filter: type: string min_version: 2.1 +tld_description_filter: + description: | + Filter results to only show tlds that have a description matching the + filter. Use ``*`` as a wildcard. + in: query + required: false + type: string + tld_name_filter: description: | Filter results to only show tlds that have a name matching the filter diff --git a/designate/api/v2/controllers/tlds.py b/designate/api/v2/controllers/tlds.py index 5251586ec..ca8d2dfb8 100644 --- a/designate/api/v2/controllers/tlds.py +++ b/designate/api/v2/controllers/tlds.py @@ -51,7 +51,7 @@ class TldsController(rest.RestController): context, params, self.SORT_KEYS) # Extract any filter params. - accepted_filters = ('name', ) + accepted_filters = ('name', 'description') criterion = self._apply_filter_params( params, accepted_filters, {}) diff --git a/designate/tests/functional/api/v2/test_tlds.py b/designate/tests/functional/api/v2/test_tlds.py index 87b6215c4..8b36e8714 100644 --- a/designate/tests/functional/api/v2/test_tlds.py +++ b/designate/tests/functional/api/v2/test_tlds.py @@ -198,7 +198,28 @@ class ApiV2TldsTest(v2.ApiV2TestCase): # Check that the correct number of tlds match self.assertEqual(correct_result, len(response.json['tlds'])) + def test_get_tld_filter_by_description(self): + self.policy({'create_tld': '@'}) + + # Create TLDs with descriptions + self.create_tld(name='com', description='Commercial TLD') + self.create_tld(name='org', description='Organization TLD') + self.create_tld(name='net', description='Network TLD') + + self.policy({'find_tlds': '@'}) + + # Test exact match + response = self.client.get('/tlds?description=Commercial TLD') + self.assertEqual(200, response.status_int) + self.assertEqual('application/json', response.content_type) + self.assertEqual(1, len(response.json['tlds'])) + + # Test wildcard match + response = self.client.get('/tlds?description=*TLD') + self.assertEqual(200, response.status_int) + self.assertEqual(3, len(response.json['tlds'])) + def test_invalid_tld_filter(self): - invalid_url = '/tlds?description=test' + invalid_url = '/tlds?invalid_filter=test' self._assert_exception( 'bad_request', 400, self.client.get, invalid_url) diff --git a/releasenotes/notes/add-tld-description-filter-a7b8c9d0e1f2g3h4.yaml b/releasenotes/notes/add-tld-description-filter-a7b8c9d0e1f2g3h4.yaml new file mode 100644 index 000000000..959afd679 --- /dev/null +++ b/releasenotes/notes/add-tld-description-filter-a7b8c9d0e1f2g3h4.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Added support for filtering TLDs by description in the API. + The TLD list endpoint now accepts a ``description`` query parameter + to filter results, matching the pattern used by other resources like + zones and recordsets. Wildcard filtering is supported using ``*``.