Skip to content

Commit 11c55b9

Browse files
fix(data-classes): Add missing SES fields and (aws-powertools#1045)
Changes: - Fix date type to be a str and not List[str] - Add missing fields from SESMailCommonHeaders (bcc, cc, sender and replyTo) - Add missing dkimVerdict field - Add missing dmarcPolicy field - Add missing topicArn field - Add missing docs for SESReceiptStatus status field related aws-powertools#1025
1 parent c67efe4 commit 11c55b9

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

Diff for: aws_lambda_powertools/utilities/data_classes/ses_event.py

+43-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Iterator, List
1+
from typing import Iterator, List, Optional
22

33
from aws_lambda_powertools.utilities.data_classes.common import DictWrapper
44

@@ -26,7 +26,7 @@ def get_from(self) -> List[str]:
2626
return self["from"]
2727

2828
@property
29-
def date(self) -> List[str]:
29+
def date(self) -> str:
3030
"""The date and time when Amazon SES received the message."""
3131
return self["date"]
3232

@@ -45,6 +45,26 @@ def subject(self) -> str:
4545
"""The value of the Subject header for the email."""
4646
return str(self["subject"])
4747

48+
@property
49+
def cc(self) -> Optional[List[str]]:
50+
"""The values in the CC header of the email."""
51+
return self.get("cc")
52+
53+
@property
54+
def bcc(self) -> Optional[List[str]]:
55+
"""The values in the BCC header of the email."""
56+
return self.get("bcc")
57+
58+
@property
59+
def sender(self) -> Optional[List[str]]:
60+
"""The values in the Sender header of the email."""
61+
return self.get("sender")
62+
63+
@property
64+
def reply_to(self) -> Optional[List[str]]:
65+
"""The values in the replyTo header of the email."""
66+
return self.get("replyTo")
67+
4868

4969
class SESMail(DictWrapper):
5070
@property
@@ -94,6 +114,9 @@ def common_headers(self) -> SESMailCommonHeaders:
94114
class SESReceiptStatus(DictWrapper):
95115
@property
96116
def status(self) -> str:
117+
"""Receipt status
118+
Possible values: 'PASS', 'FAIL', 'GRAY', 'PROCESSING_FAILED', 'DISABLED'
119+
"""
97120
return str(self["status"])
98121

99122

@@ -107,6 +130,12 @@ def get_type(self) -> str:
107130
# Note: this name conflicts with existing python builtins
108131
return self["type"]
109132

133+
@property
134+
def topic_arn(self) -> Optional[str]:
135+
"""String that contains the Amazon Resource Name (ARN) of the Amazon SNS topic to which the
136+
notification was published."""
137+
return self.get("topicArn")
138+
110139
@property
111140
def function_arn(self) -> str:
112141
"""String that contains the ARN of the Lambda function that was triggered.
@@ -154,12 +183,24 @@ def spf_verdict(self) -> SESReceiptStatus:
154183
"""Object that indicates whether the Sender Policy Framework (SPF) check passed."""
155184
return SESReceiptStatus(self["spfVerdict"])
156185

186+
@property
187+
def dkim_verdict(self) -> SESReceiptStatus:
188+
"""Object that indicates whether the DomainKeys Identified Mail (DKIM) check passed"""
189+
return SESReceiptStatus(self["dkimVerdict"])
190+
157191
@property
158192
def dmarc_verdict(self) -> SESReceiptStatus:
159193
"""Object that indicates whether the Domain-based Message Authentication,
160194
Reporting & Conformance (DMARC) check passed."""
161195
return SESReceiptStatus(self["dmarcVerdict"])
162196

197+
@property
198+
def dmarc_policy(self) -> Optional[str]:
199+
"""Indicates the Domain-based Message Authentication, Reporting & Conformance (DMARC) settings for
200+
the sending domain. This field only appears if the message fails DMARC authentication.
201+
Possible values for this field are: none, quarantine, reject"""
202+
return self.get("dmarcPolicy")
203+
163204
@property
164205
def action(self) -> SESReceiptAction:
165206
"""Object that encapsulates information about the action that was executed."""

Diff for: tests/events/sesEvent.json

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"dkimVerdict": {
7878
"status": "PASS"
7979
},
80+
"dmarcPolicy": "reject",
8081
"processingTimeMillis": 574,
8182
"action": {
8283
"type": "Lambda",

Diff for: tests/functional/test_data_classes.py

+7
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,10 @@ def test_ses_trigger_event():
691691
assert common_headers.to == [expected_address]
692692
assert common_headers.message_id == "<0123456789example.com>"
693693
assert common_headers.subject == "Test Subject"
694+
assert common_headers.cc is None
695+
assert common_headers.bcc is None
696+
assert common_headers.sender is None
697+
assert common_headers.reply_to is None
694698
receipt = record.ses.receipt
695699
assert receipt.timestamp == "1970-01-01T00:00:00.000Z"
696700
assert receipt.processing_time_millis == 574
@@ -699,10 +703,13 @@ def test_ses_trigger_event():
699703
assert receipt.virus_verdict.status == "PASS"
700704
assert receipt.spf_verdict.status == "PASS"
701705
assert receipt.dmarc_verdict.status == "PASS"
706+
assert receipt.dkim_verdict.status == "PASS"
707+
assert receipt.dmarc_policy == "reject"
702708
action = receipt.action
703709
assert action.get_type == action.raw_event["type"]
704710
assert action.function_arn == action.raw_event["functionArn"]
705711
assert action.invocation_type == action.raw_event["invocationType"]
712+
assert action.topic_arn is None
706713
assert event.record.raw_event == event["Records"][0]
707714
assert event.mail.raw_event == event["Records"][0]["ses"]["mail"]
708715
assert event.receipt.raw_event == event["Records"][0]["ses"]["receipt"]

0 commit comments

Comments
 (0)