Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(apigateway): return only the API keys that match nameQuery (#2015)

mishukdutta-cz7e8bf0964d95
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a4543509..747dc1a4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
### Fixed
+- **API Gateway — `GetApiKeys` filters by `nameQuery`** — `GetApiKeys` ignored `nameQuery` and returned all the API keys, so a lookup by name could get the wrong key. It now returns only the keys whose names start with `nameQuery`.
- **RDS — creating an existing parameter group is refused** — `CreateDBParameterGroup` and `CreateDBClusterParameterGroup` with a name already in use replaced the group with an empty one, dropping its parameters; they now return `DBParameterGroupAlreadyExists`, as AWS does. Contributed by @skialpine.
- **RDS — a backup retention period of 0 turns binary logging off** — on RDS for MySQL, `BackupRetentionPeriod=0` turns binary logging off; MiniStack's MySQL 8.0/8.4 instances kept the image default, binary logging on. Such an instance now starts with binary logging off. Contributed by @skialpine.
- **IoT — `CreateThingGroup` on an existing name returns the group when nothing differs** — a repeated `CreateThingGroup` always failed with `ResourceAlreadyExistsException`. It now returns the existing group's name, ARN and id when the description, attributes (in any order), parent and tags match, and answers 409 with AWS's message otherwise, leaving the group unchanged, as AWS does. An `AWS::IoT::ThingGroup` that names an existing group still fails its stack, with or without matching properties, now with AWS's name-conflict message. Contributed by @iot-rocket.
diff --git a/ministack/services/apigateway_v1.py b/ministack/services/apigateway_v1.py
index ac9592a5..a3616c53 100644
--- a/ministack/services/apigateway_v1.py
+++ b/ministack/services/apigateway_v1.py
@@ -4384,7 +4384,12 @@ def _create_api_key(data):
def _get_api_keys(query_params):
- return _v1_paginated_response(list(_api_keys.values()), query_params)
+ keys = list(_api_keys.values())
+ name_query = _qp(query_params, "name")
+ if name_query:
+ # AWS returns the keys whose names start with nameQuery.
+ keys = [key for key in keys if key["name"].startswith(name_query)]
+ return _v1_paginated_response(keys, query_params)
def _get_api_key(key_id):
diff --git a/tests/test_apigatewayv1.py b/tests/test_apigatewayv1.py
index 8cd1a76e..0b9a1c8a 100644
--- a/tests/test_apigatewayv1.py
+++ b/tests/test_apigatewayv1.py
@@ -2309,6 +2309,17 @@ def test_apigwv1_update_api_key(apigw_v1):
assert isinstance(resp["lastUpdatedDate"], datetime.datetime)
apigw_v1.delete_api_key(apiKey=key_id)
+def test_apigwv1_get_api_keys_filters_by_name_query(apigw_v1):
+ """GetApiKeys with nameQuery returns only the keys whose names start with it."""
+ key_ids = [
+ apigw_v1.create_api_key(name=name)["id"]
+ for name in ("v1-namequery-other", "v1-namequery-target", "v1-namequery-target-2")
+ ]
+ resp = apigw_v1.get_api_keys(nameQuery="v1-namequery-target")
+ assert sorted(item["name"] for item in resp["items"]) == ["v1-namequery-target", "v1-namequery-target-2"]
+ for key_id in key_ids:
+ apigw_v1.delete_api_key(apiKey=key_id)
+
def test_apigwv1_update_usage_plan(apigw_v1):
"""UpdateUsagePlan updates name via patchOperations."""
plan_id = apigw_v1.create_usage_plan(name="v1-plan-update-before")["id"]