diff options
author | George Claghorn <george@basecamp.com> | 2018-11-05 12:39:37 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-11-05 12:39:37 -0500 |
commit | b859eebff8545eea972d479137e14b917e6519dc (patch) | |
tree | 1473c5e5a67703e73633956a061735127c05e720 | |
parent | d02ae4c7ae336412a5ff19400cda6b87ed58a465 (diff) | |
download | rails-b859eebff8545eea972d479137e14b917e6519dc.tar.gz rails-b859eebff8545eea972d479137e14b917e6519dc.tar.bz2 rails-b859eebff8545eea972d479137e14b917e6519dc.zip |
Only load the AWS SDK when the Amazon ingress is configured
-rw-r--r-- | app/controllers/action_mailbox/base_controller.rb | 4 | ||||
-rw-r--r-- | app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb | 11 | ||||
-rw-r--r-- | lib/action_mailbox/engine.rb | 13 |
3 files changed, 24 insertions, 4 deletions
diff --git a/app/controllers/action_mailbox/base_controller.rb b/app/controllers/action_mailbox/base_controller.rb index a2f7eb4b61..c234ecd250 100644 --- a/app/controllers/action_mailbox/base_controller.rb +++ b/app/controllers/action_mailbox/base_controller.rb @@ -1,6 +1,10 @@ class ActionMailbox::BaseController < ActionController::Base skip_forgery_protection + def self.prepare + # Override in concrete controllers to run code on load. + end + before_action :ensure_configured private diff --git a/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb b/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb index 4d56e27c76..d3998be2d4 100644 --- a/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb +++ b/app/controllers/action_mailbox/ingresses/amazon/inbound_emails_controller.rb @@ -1,9 +1,14 @@ class ActionMailbox::Ingresses::Amazon::InboundEmailsController < ActionMailbox::BaseController before_action :authenticate - # TODO: Lazy-load the AWS SDK - require "aws-sdk-sns/message_verifier" - cattr_accessor :verifier, default: Aws::SNS::MessageVerifier.new + cattr_accessor :verifier + + def self.prepare + self.verifier ||= begin + require "aws-sdk-sns/message_verifier" + Aws::SNS::MessageVerifier.new + end + end def create ActionMailbox::InboundEmail.create_and_extract_message_id! params.require(:content) diff --git a/lib/action_mailbox/engine.rb b/lib/action_mailbox/engine.rb index 6a0312c65f..cf438d8f24 100644 --- a/lib/action_mailbox/engine.rb +++ b/lib/action_mailbox/engine.rb @@ -10,10 +10,21 @@ module ActionMailbox initializer "action_mailbox.config" do config.after_initialize do |app| - ActionMailbox.ingress = app.config.action_mailbox.ingress ActionMailbox.logger = app.config.action_mailbox.logger || Rails.logger ActionMailbox.incinerate_after = app.config.action_mailbox.incinerate_after || 30.days end end + + initializer "action_mailbox.ingress" do + config.after_initialize do |app| + if ActionMailbox.ingress = app.config.action_mailbox.ingress.presence + config.to_prepare do + if ingress_controller_class = "ActionMailbox::Ingresses::#{ActionMailbox.ingress.to_s.classify}::InboundEmailsController".safe_constantize + ingress_controller_class.prepare + end + end + end + end + end end end |