Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SES Event Info #331

Merged
merged 1 commit into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions iopipe/contrib/eventinfo/event_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,26 @@ class ServerlessLambda(EventType):
required_keys = ["identity.userAgent", "identity.sourceIp", "identity.accountId"]


class SES(EventType):
type = "ses"
keys = [
"Records[0].ses.mail.commonHeaders.date",
"Records[0].ses.mail.commonHeaders.messageId",
"Records[0].ses.mail.commonHeaders.returnPath",
"Records[0].ses.mail.commonHeaders.subject",
"Records[0].ses.mail.messageId",
"Records[0].ses.mail.source",
]
required_keys = ["Records[0].eventVersion", "Records[0].eventSource"]

def has_required_keys(self):
return (
super(SES, self).has_required_keys()
and get_value(self.event, "Records[0].eventVersion") == "1.0"
and get_value(self.event, "Records[0].eventSource") == "aws:ses"
)


class SNS(EventType):
type = "sns"
keys = [
Expand Down Expand Up @@ -228,6 +248,7 @@ def has_required_keys(self):
Firehose,
Kinesis,
S3,
SES,
SNS,
SQS,
Scheduled,
Expand Down
5 changes: 5 additions & 0 deletions tests/contrib/eventinfo/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def event_kinesis():
return _load_event("kinesis")


@pytest.fixture
def event_ses():
return _load_event("ses")


@pytest.fixture
def event_sns():
return _load_event("sns")
Expand Down
97 changes: 97 additions & 0 deletions tests/contrib/eventinfo/events/ses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"Records": [
{
"eventVersion": "1.0",
"ses": {
"mail": {
"commonHeaders": {
"from": [
"Jane Doe <janedoe@example.com>"
],
"to": [
"johndoe@example.com"
],
"returnPath": "janedoe@example.com",
"messageId": "<0123456789example.com>",
"date": "Wed, 7 Oct 2015 12:34:56 -0700",
"subject": "Test Subject"
},
"source": "janedoe@example.com",
"timestamp": "1970-01-01T00:00:00.000Z",
"destination": [
"johndoe@example.com"
],
"headers": [
{
"name": "Return-Path",
"value": "<janedoe@example.com>"
},
{
"name": "Received",
"value": "from mailer.example.com (mailer.example.com [203.0.113.1]) by inbound-smtp.us-west-2.amazonaws.com with SMTP id o3vrnil0e2ic for johndoe@example.com; Wed, 07 Oct 2015 12:34:56 +0000 (UTC)"
},
{
"name": "DKIM-Signature",
"value": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=example; h=mime-version:from:date:message-id:subject:to:content-type; bh=jX3F0bCAI7sIbkHyy3mLYO28ieDQz2R0P8HwQkklFj4=; b=sQwJ+LMe9RjkesGu+vqU56asvMhrLRRYrWCbV"
},
{
"name": "MIME-Version",
"value": "1.0"
},
{
"name": "From",
"value": "Jane Doe <janedoe@example.com>"
},
{
"name": "Date",
"value": "Wed, 7 Oct 2015 12:34:56 -0700"
},
{
"name": "Message-ID",
"value": "<0123456789example.com>"
},
{
"name": "Subject",
"value": "Test Subject"
},
{
"name": "To",
"value": "johndoe@example.com"
},
{
"name": "Content-Type",
"value": "text/plain; charset=UTF-8"
}
],
"headersTruncated": false,
"messageId": "o3vrnil0e2ic28tr"
},
"receipt": {
"recipients": [
"johndoe@example.com"
],
"timestamp": "1970-01-01T00:00:00.000Z",
"spamVerdict": {
"status": "PASS"
},
"dkimVerdict": {
"status": "PASS"
},
"processingTimeMillis": 574,
"action": {
"type": "Lambda",
"invocationType": "Event",
"functionArn": "arn:aws:lambda:us-west-2:012345678912:function:Example"
},
"spfVerdict": {
"status": "PASS"
},
"virusVerdict": {
"status": "PASS"
}
}
},
"eventSource": "aws:ses"
}
]
}
16 changes: 16 additions & 0 deletions tests/contrib/eventinfo/test_event_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ def test__event_types__serverless_lambda(event_serverless_lambda):
assert event_info["@iopipe/event-info.eventType.source"] == event.source


def test__event_types__ses(event_ses):
event = et.SES(event_ses)

assert event.has_required_keys() is True

event_info = event.collect()

assert event_info != {}

expected_keys = ["@iopipe/event-info.eventType"] + [
"@iopipe/event-info.ses.%s" % key for key in event.keys
]

assert list(event_info.keys()).sort() == expected_keys.sort()


def test__event_types__sns(event_sns):
event = et.SNS(event_sns)
assert event.has_required_keys() is True
Expand Down