Skip to content

Commit

Permalink
fix error when ne values are provided when creating an api key
Browse files Browse the repository at this point in the history
  • Loading branch information
cloutierMat committed Oct 9, 2024
1 parent 56f5229 commit 228f2ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion moto/apigateway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions moto/utilities/id_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 228f2ea

Please sign in to comment.