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

Adapt default Rails logs to JSON format #17

Merged

Conversation

amiedes
Copy link
Contributor

@amiedes amiedes commented Oct 16, 2020

private

def current_user(event_payload)
user_klass = defined?(Carto::User) ? Carto::User : User
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows identifying the user to whom the email was sent both in CartoDB + Central

address.length < 8 ||
address.split('@').select(&:present?).size != 2
return '[ADDRESS]'
end
Copy link
Contributor Author

@amiedes amiedes Oct 16, 2020

Choose a reason for hiding this comment

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

I do a more aggressive obfuscation of email addresses in case they are very short. Check the specs for examples.

subject { Carto::Common::ActionMailerLogSubscriber.new }

# Mocks CartoDB & Central users as they don't exist in the context of this gem
class User
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know this looks weird, but it's the best way I could think of to keep the logger specs in the common repository rather than duplicating it in both repos or adding a dependency to ActiveRecord

@@ -22,7 +22,9 @@ Gem::Specification.new do |spec|
spec.add_dependency 'activesupport', '~> 4.2.11.3'
spec.add_dependency 'argon2', '~> 2.0'

spec.add_development_dependency 'actionmailer', '~> 4.2'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for adding this dependency is that parent log subscriber class ActionMailer::LogSubscriber is defined there.

@@ -29,13 +30,16 @@ def self.remove_existing_log_subscriptions
unsubscribe(:action_view, subscriber)
when ActionController::LogSubscriber
unsubscribe(:action_controller, subscriber)
when ActionMailer::LogSubscriber
unsubscribe(:action_mailer, subscriber)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This dettaches the default log subscriber (no JSON format, no user identification)

@amiedes amiedes marked this pull request as ready for review October 16, 2020 16:53
@amiedes amiedes requested a review from rafatower October 16, 2020 16:53
@amiedes
Copy link
Contributor Author

amiedes commented Oct 16, 2020

@rafatower this is part of a leapfrog. I still have pending some testing in staging before actually including this in CartoDB/Central:

CartoDB/cartodb#15894

Copy link
Contributor

@rafatower rafatower left a comment

Choose a reason for hiding this comment

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

👍

end

address.split('@').map do |segment|
segment[0] + '*' * (segment.length - 2) + segment[-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

when obfuscating, I'd use fixed size always

@amiedes amiedes merged commit f098950 into master Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants