Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions bin/summarize-user-events
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SummarizeUserEvents
def matchers
@matchers ||= [
EventSummarizer::ExampleMatcher.new,
EventSummarizer::AccountDeletionMatcher.new,
]
end

Expand Down
74 changes: 74 additions & 0 deletions lib/event_summarizer/account_deletion_matcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# frozen_string_literal: true

module EventSummarizer
class AccountDeletionMatcher
ACCOUNT_DELETION_STARTED_EVENT = 'Account Reset: request'
ACCOUNT_DELETION_SUBMITTED_EVENT = 'Account Reset: delete'
ACCOUNT_DELETION_CANCELED_EVENT = 'Account Reset: cancel'

EVENT_PROPERTIES = ['@message', 'properties', 'event_properties'].freeze

attr_accessor :account_deletion_events, :event_summaries

def initialize
@account_deletion_events = Array.new
@event_summaries = Array.new
account_deletion_events
end

def handle_cloudwatch_event(event)
case event['name']
when ACCOUNT_DELETION_STARTED_EVENT
process_account_reset_request(event)
when ACCOUNT_DELETION_SUBMITTED_EVENT
process_account_reset_delete(event)
when ACCOUNT_DELETION_CANCELED_EVENT
process_account_reset_cancel(event)
end
end

def finish
event_summaries
end

private

def process_account_reset_request(event)
event_message = {
title: 'Account deletion Request',
attributes: [
{ type: :account_deletion_request,
description: "On #{event["@timestamp"]} user initiated account deletion" },
],
}
event_summaries.push(event_message)
end

def process_account_reset_cancel(event)
event_message = {
title: 'Account deletion cancelled',
attributes: [
{ type: :account_deletion_cancelled,
description: "On #{event["@timestamp"]} user initiated account deletion" },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: "On #{event["@timestamp"]} user initiated account deletion" },
description: "On #{event["@timestamp"]} user canceled account deletion" },

],
}
event_summaries.push(event_message)
end

def process_account_reset_delete(event)
message = event['@message']
age = message['properties']['event_properties']['account_age_in_days']
date = event['@timestamp']
event_message = {
title: 'Account deleted',
attributes: [
{
type: :account_deleted,
description: "On #{date} user deleted their account which was #{age} days old",
},
],
}
event_summaries.push(event_message)
end
end
end