Skip to content
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
25 changes: 15 additions & 10 deletions bin/summarize-user-events
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ Dir[File.expand_path(
end

class SummarizeUserEvents
attr_reader :uuid, :from_date, :to_date, :zone
attr_reader :file_name, :uuid, :from_date, :to_date, :zone

NICE_DATE_AND_TIME_FORMAT = '%B %d, %Y at %I:%M %p %Z'
TIME_ONLY_FORMAT = '%I:%M %p'

def initialize(user_uuid: nil, start_time: nil, end_time: nil, zone: 'UTC')
def initialize(file_name: nil, user_uuid: nil, start_time: nil, end_time: nil, zone: 'UTC')
@file_name = file_name
@zone = zone
Time.zone = zone
@uuid = user_uuid
Expand Down Expand Up @@ -146,18 +147,18 @@ class SummarizeUserEvents
end

def find_cloudwatch_events(&block)
if $stdin.tty?
unless file_name.nil?
warn 'Reading Cloudwatch events as newline-delimited JSON (ndjson) a file'
file_source(&block)
else
cloudwatch_source(&block)
else
warn 'Reading Cloudwatch events as newline-delimited JSON (ndjson) from stdin'
stdin_source(&block)
end
end

def stdin_source(&block)
def file_source(&block)
events = []

$stdin.each_line do |line|
File.read(file_name).each_line do |line|
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.

A common pattern in shell tools is to allow "-" to mean "use stdin". So it would be cool to just check if file_name == '-' and use stdin in that case (so, keep stdin_source and update find_cloudwatch_events to check if '-' has been passed as a filename and use stdin_source in that case, otherwise use file_source).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am going to merge the PR as is and make a note to come back to this after the holidays.

next if line.blank?
events << JSON.parse(line)
end
Expand Down Expand Up @@ -189,17 +190,21 @@ def main

Summarize user events in a human-readable format

Cloudwatch logs can be read from stdin as newline-delimited JSON (ndjson),
Cloudwatch logs can be read from a file as newline-delimited JSON (ndjson),
or fetched directly via aws-vault.

usage: #{basename} [OPTIONS]

Examples:
#{basename} << events.ndjson
#{basename} -f events.ndjson
aws-vault exec prod-power -- #{basename} -u 1234-5678-90ab-cdef -s 2024-12-09T10:00:00 -e 2024-12-09T14:30:00 -z America/New_York

EOM

opts.on('-f', '--file_name FILE_NAME', 'filename from which to read the events') do |val|
options[:file_name] = val
end

opts.on('-h', '--help', 'Display this message') do
warn opts
exit
Expand Down
16 changes: 3 additions & 13 deletions lib/event_summarizer/idv_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def handle_final_resolution_event(event:)
add_significant_event(
type: :start_gpo,
timestamp:,
description: 'User requested a letter to verfy by mail',
description: 'User requested a letter to verify by mail',
)
end

Expand Down Expand Up @@ -290,24 +290,14 @@ def handle_gpo_code_submission(event:)
return
end

# User successfully entered GPO code. If nothing else is pending,
# User successfully entered GPO code. If fraud review is not pending,
# then they are fully verified

ipp_pending = !!event.dig(
*EVENT_PROPERTIES,
'pending_in_person_enrollment',
)

fraud_review_pending = !!event.dig(
*EVENT_PROPERTIES,
'fraud_check_failed',
)

fully_verified = !(ipp_pending || fraud_review_pending)

description = ipp_pending ?
'User successfully entered a GPO code, but is still pending in-person proofing'
: 'User successfully entered a GPO code'
fully_verified = !fraud_review_pending

add_significant_event(
type: :gpo_code_success,
Expand Down