From d5bd0af29f489593288d71c9693451889024764f Mon Sep 17 00:00:00 2001 From: Evgeniy Sukhanov Date: Thu, 1 Sep 2016 15:05:52 +0500 Subject: [PATCH 1/4] Rails 5 support --- lib/griddler/ses/railtie.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/griddler/ses/railtie.rb b/lib/griddler/ses/railtie.rb index 4527d43..060dd6a 100644 --- a/lib/griddler/ses/railtie.rb +++ b/lib/griddler/ses/railtie.rb @@ -2,7 +2,14 @@ module Griddler module Ses class Railtie < Rails::Railtie initializer "griddler_ses.configure_rails_initialization" do |app| - Rails.application.middleware.insert_before ActionDispatch::ParamsParser, Griddler::Ses::Middleware + if ::Rails::VERSION::MAJOR >= 5 + # Rails 5 no longer instantiates ActionDispatch::ParamsParser + # https://github.com/rails/rails/commit/a1ced8b52ce60d0634e65aa36cb89f015f9f543d + Rails.application.middleware.use Middleware + Rails.application.middleware.use Griddler::Ses::Middleware + else + Rails.application.middleware.insert_before ActionDispatch::ParamsParser, Griddler::Ses::Middleware + end end end end From 22aec033801c3ccaabae2677a9d583d60ae0e4ba Mon Sep 17 00:00:00 2001 From: Jim Durand Date: Mon, 24 Oct 2016 12:44:22 +0100 Subject: [PATCH 2/4] Remove naive middleware check for a griddler path 1. Mounting Griddler is not a requirement: https://github.com/thoughtbot/griddler#installation 2. The check didn't take domains/subdomains into account 3. Checking for the HTTP_X_AMZ_SNS_MESSAGE_TYPE header is sufficient --- lib/griddler/ses/middleware.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/griddler/ses/middleware.rb b/lib/griddler/ses/middleware.rb index 3538ec4..703fe91 100644 --- a/lib/griddler/ses/middleware.rb +++ b/lib/griddler/ses/middleware.rb @@ -9,7 +9,7 @@ def call(env) # a bug on the AWS side doesn't set the content type to application/json type properly, # so we have to intercept and do this in order for Griddler's controller to correctly # parse the parameters (see https://forums.aws.amazon.com/thread.jspa?messageID=418160) - if is_griddler_request?(env) && is_aws_sns_request?(env) + if is_aws_sns_request?(env) env['CONTENT_TYPE'] = 'application/json; charset=UTF-8' end @@ -17,14 +17,6 @@ def call(env) end private - def griddler_path - @griddler_path ||= Rails.application.routes.url_helpers.url_for(controller: 'griddler/emails', action: 'create', only_path: true) - end - - def is_griddler_request?(request) - request['REQUEST_PATH'] == griddler_path - end - def is_aws_sns_request?(request) request['HTTP_X_AMZ_SNS_MESSAGE_TYPE'].present? end From ba8026a9f8897baf705fec0ab5783ab03f228629 Mon Sep 17 00:00:00 2001 From: Jim Durand Date: Mon, 24 Oct 2016 12:52:06 +0100 Subject: [PATCH 3/4] Remove undesired constraint --- lib/griddler/ses/adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/griddler/ses/adapter.rb b/lib/griddler/ses/adapter.rb index b09cf85..0fe581e 100644 --- a/lib/griddler/ses/adapter.rb +++ b/lib/griddler/ses/adapter.rb @@ -19,7 +19,7 @@ def self.normalize_params(params) def normalize_params # use sns_endpoint to parse and validate the sns message sns_msg = SnsEndpoint::AWS::SNS::Message.new sns_json - raise "Invalid SNS message" unless sns_msg.authentic? && sns_msg.topic_arn.end_with?('griddler') + raise "Invalid SNS message" unless sns_msg.authentic? case sns_msg.type when :SubscriptionConfirmation From e19981e1c3378c1f0b72163156064f8fd4566deb Mon Sep 17 00:00:00 2001 From: Jim Durand Date: Tue, 20 Jun 2017 11:26:20 -0400 Subject: [PATCH 4/4] Fix CI build --- griddler-ses.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/griddler-ses.gemspec b/griddler-ses.gemspec index b18f45b..8cc1757 100644 --- a/griddler-ses.gemspec +++ b/griddler-ses.gemspec @@ -24,5 +24,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.11" spec.add_development_dependency "rake", "~> 10.0" + spec.add_development_dependency "sinatra", "~> 1.4" spec.add_development_dependency "rspec", "~> 3.0" end