From b859eebff8545eea972d479137e14b917e6519dc Mon Sep 17 00:00:00 2001
From: George Claghorn <george@basecamp.com>
Date: Mon, 5 Nov 2018 12:39:37 -0500
Subject: Only load the AWS SDK when the Amazon ingress is configured

---
 app/controllers/action_mailbox/base_controller.rb             |  4 ++++
 .../ingresses/amazon/inbound_emails_controller.rb             | 11 ++++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

(limited to 'app')

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)
-- 
cgit v1.2.3