-
Notifications
You must be signed in to change notification settings - Fork 166
Modularize Attempts API Tracker - FCMS Prework #12472
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
Changes from all commits
11bbba1
6740937
8cf7dfd
dbc6c6e
440b54d
5d14fbb
59cde25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,44 +24,16 @@ def initialize(session_id:, request:, user:, sp:, cookie_device_uuid:, | |
| def track_event(event_type, metadata = {}) | ||
| return unless enabled? | ||
|
|
||
| extra_metadata = | ||
| if metadata.has_key?(:failure_reason) && | ||
| (metadata[:failure_reason].blank? || metadata[:success].present?) | ||
| metadata.except(:failure_reason) | ||
| else | ||
| metadata | ||
| end | ||
|
|
||
| event_metadata = { | ||
| user_agent: request&.user_agent, | ||
| unique_session_id: hashed_session_id, | ||
| user_uuid: agency_uuid(event_type: event_type), | ||
| device_id: cookie_device_uuid, | ||
| user_ip_address: request&.remote_ip, | ||
| application_url: sp_redirect_uri, | ||
| language: user&.email_language || I18n.locale.to_s, | ||
| client_port: CloudFrontHeaderParser.new(request).client_port, | ||
| aws_region: IdentityConfig.store.aws_region, | ||
| google_analytics_cookies: google_analytics_cookies(request), | ||
| } | ||
|
|
||
| event_metadata.merge!(extra_metadata) | ||
|
|
||
| event = AttemptEvent.new( | ||
| event_type: event_type, | ||
| session_id: session_id, | ||
| occurred_at: Time.zone.now, | ||
| event_metadata: event_metadata, | ||
| ) | ||
|
|
||
| jwe = event.to_jwe( | ||
| issuer: sp.issuer, | ||
| public_key: sp.attempts_public_key, | ||
| event_metadata: event_metadata(event_type:, metadata:), | ||
| ) | ||
|
|
||
| redis_client.write_event( | ||
| event_key: event.jti, | ||
| jwe: jwe, | ||
| jwe: jwe(event), | ||
| timestamp: event.occurred_at, | ||
| issuer: sp.issuer, | ||
| ) | ||
|
|
@@ -83,6 +55,45 @@ def parse_failure_reason(result) | |
|
|
||
| private | ||
|
|
||
| def jwe(event) | ||
| event.to_jwe( | ||
| issuer: sp.issuer, | ||
| public_key: sp.attempts_public_key, | ||
| ) | ||
| end | ||
|
|
||
| def extra_attributes | ||
| {} | ||
| end | ||
|
|
||
| def extra_metadata(metadata:) | ||
| failure_metadata(metadata:).merge(extra_attributes) | ||
| end | ||
|
|
||
| def failure_metadata(metadata:) | ||
| if metadata.has_key?(:failure_reason) && | ||
| (metadata[:failure_reason].blank? || metadata[:success].present?) | ||
| metadata.except(:failure_reason) | ||
| else | ||
| metadata | ||
| end | ||
| end | ||
|
|
||
| def event_metadata(event_type:, metadata:) | ||
| { | ||
| user_agent: request&.user_agent, | ||
| unique_session_id: hashed_session_id, | ||
| user_uuid: agency_uuid(event_type: event_type), | ||
| device_id: cookie_device_uuid, | ||
| user_ip_address: request&.remote_ip, | ||
| application_url: sp_redirect_uri, | ||
| language: user&.email_language || I18n.locale.to_s, | ||
| client_port: CloudFrontHeaderParser.new(request).client_port, | ||
| aws_region: IdentityConfig.store.aws_region, | ||
| google_analytics_cookies: google_analytics_cookies(request), | ||
| }.merge!(extra_metadata(metadata:)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think the |
||
| end | ||
|
|
||
| def google_analytics_cookies(request) | ||
| return nil unless request&.cookies | ||
| request.cookies.filter do |key, value| | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.