diff --git a/keystone_client/client.py b/keystone_client/client.py index 6130a7e..e92a11c 100644 --- a/keystone_client/client.py +++ b/keystone_client/client.py @@ -306,6 +306,8 @@ def _retrieve_factory(self, endpoint: Endpoint) -> callable: def retrieve_record( pk: int | None = None, filters: dict | None = None, + search: str | None = None, + order: str | None = None, timeout=DEFAULT_TIMEOUT ) -> Union[None, dict, list[dict]]: """Retrieve one or more API records. @@ -317,6 +319,8 @@ def retrieve_record( Args: pk: Optional primary key to fetch a specific record. filters: Optional query parameters to include in the request. + search: Optionally search records for the given string. + order: Optional order returned values by the given parameter. timeout: Seconds before the request times out. Returns: @@ -325,6 +329,11 @@ def retrieve_record( url = endpoint.join_url(self.url, pk) + for param_name, value in zip(('_search', '_order'), (search, order)): + if value is not None: + filters = filters or {} + filters[param_name] = value + try: response = self.http_get(url, params=filters, timeout=timeout) response.raise_for_status() diff --git a/tests/client/test_KeystoneClient.py b/tests/client/test_KeystoneClient.py index ee0e475..b3fd416 100644 --- a/tests/client/test_KeystoneClient.py +++ b/tests/client/test_KeystoneClient.py @@ -115,7 +115,7 @@ def test_retrieve_by_pk(self) -> None: self.assertIsNotNone(retrieved_cluster) self.assertEqual(retrieved_cluster['id'], pk) - def test_retrieve_by_filters(self) -> None: + def test_retrieve_with_filters(self) -> None: """Test the filtering of returned records via search params.""" retrieved_clusters = self.client.retrieve_cluster(filters={"name": "Test-Cluster"})