From 228f2ea0623ffcbd4798e825ccf50e5a1a43a2de Mon Sep 17 00:00:00 2001 From: Mathieu Cloutier Date: Tue, 8 Oct 2024 20:40:44 -0600 Subject: [PATCH] fix error when ne values are provided when creating an api key --- moto/apigateway/models.py | 2 +- moto/utilities/id_generator.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/moto/apigateway/models.py b/moto/apigateway/models.py index aa02fcc25224..1bfb5111793f 100644 --- a/moto/apigateway/models.py +++ b/moto/apigateway/models.py @@ -2177,7 +2177,7 @@ def create_api_key(self, payload: Dict[str, Any]) -> ApiKey: self.account_id, self.region_name, # The value of an api key must be unique on aws - payload["value"], + payload.get("value"), ).generate() key = ApiKey(api_key_id=api_key_id, **payload) self.keys[key.id] = key diff --git a/moto/utilities/id_generator.py b/moto/utilities/id_generator.py index 53c9f3bf3a61..dadefdc64fb1 100644 --- a/moto/utilities/id_generator.py +++ b/moto/utilities/id_generator.py @@ -20,7 +20,7 @@ class ResourceIdentifier(abc.ABC): def __init__(self, account_id: str, region: str, name: str): self.account_id = account_id self.region = region - self.name = name + self.name = name or "" @abc.abstractmethod def generate(self) -> str: ... @@ -57,7 +57,9 @@ def get_custom_id( def set_custom_id( self, resource_identifier: ResourceIdentifier, custom_id: str ) -> None: - # sets a custom_id for a resource + # Do not set a custom_id for a resource no value was found for the name + if not resource_identifier.name: + return with self._lock: self._custom_ids[resource_identifier.unique_identifier] = custom_id