generated from timoguin/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsns.py
62 lines (47 loc) · 1.41 KB
/
sns.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from dataclasses import dataclass
import logging
from typing import Optional
from .base import ModelBase
from ..utils.validators import is_valid_json
logging.getLogger(__name__).addHandler(logging.NullHandler())
@dataclass
class SnsMessageData(ModelBase):
"""Represents the data from an SNS message that is under the "Sns" field"""
message: str
message_id: str
signature: str
signature_version: str
signing_cert_url: str
subject: str
timestamp: str
topic_arn: str
type: str
unsubscribe_url: str
# TODO: Unsure if there are additional attributes if the message comes from an SNS
# FIFO topic
@dataclass
class SnsMessage(ModelBase):
"""Schema for an SNS message"""
message: str
message_id: str
subject: str
timestamp: str
topic_arn: str
type: str
unsubscribe_url: str
signature: Optional[str]
signature_version: Optional[str]
signing_cert_url: Optional[str]
# TODO: Unsure if there are additional attributes if the message comes from an SNS
# FIFO topic
@property
def is_body_json(self) -> bool:
"""Check if the message body is a JSON string"""
return is_valid_json(self.message)
@dataclass
class LambdaSnsMessage(ModelBase):
"""Represents the SNS message format when using Lambda subscriptions"""
event_source: str
event_version: str
event_subscription_arn: str
sns: SnsMessage