From 38f6359dce229430c89e805cd35e773d8f86ea2a Mon Sep 17 00:00:00 2001 From: Akira Noda <61897166+tsugumi-sys@users.noreply.github.com> Date: Tue, 23 Jan 2024 23:39:22 +0900 Subject: [PATCH] Refactoring: Adding typing for event message structure (#7234) --- moto/events/notifications.py | 10 ++++++---- moto/events/utils.py | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/moto/events/notifications.py b/moto/events/notifications.py index fede9a8b4..d867f8f27 100644 --- a/moto/events/notifications.py +++ b/moto/events/notifications.py @@ -1,16 +1,18 @@ import json -from typing import Any, Dict +from typing import Any -_EVENT_S3_OBJECT_CREATED: Dict[str, Any] = { +from .utils import EventMessageType + +_EVENT_S3_OBJECT_CREATED: EventMessageType = { "version": "0", "id": "17793124-05d4-b198-2fde-7ededc63b103", "detail-type": "Object Created", "source": "aws.s3", "account": "123456789012", "time": "2021-11-12T00:00:00Z", - "region": None, + "region": "us-west-2", "resources": [], - "detail": None, + "detail": {}, } diff --git a/moto/events/utils.py b/moto/events/utils.py index ad359ab6d..416182880 100644 --- a/moto/events/utils.py +++ b/moto/events/utils.py @@ -1,3 +1,25 @@ +from typing import TYPE_CHECKING, List, TypedDict + +if TYPE_CHECKING: + from typing_extentions import Any, Dict, Required, Union + + +# NOTE: Typing is based on the following document https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html +EventMessageType = TypedDict( + "EventMessageType", + { + "version": str, + "id": str, + "detail-type": "Required[Union[str, List[str]]]", + "source": "Required[Union[str, List[str]]]", + "account": str, + "time": str, + "region": str, + "resources": List[str], + "detail": "Required[Dict[str, Any]]", + }, +) + PAGINATION_MODEL = { "list_rules": { "input_token": "next_token",