Class: PlanMyStuff::Webhooks::AwsController

Inherits:
ActionController::API
  • Object
show all
Defined in:
app/controllers/plan_my_stuff/webhooks/aws_controller.rb

Constant Summary collapse

VALID_SNS_MESSAGE_TYPES =
%w[Notification SubscriptionConfirmation UnsubscribeConfirmation].freeze

Instance Method Summary collapse

Instance Method Details

#createObject

POST /webhooks/aws



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/plan_my_stuff/webhooks/aws_controller.rb', line 11

def create
  config = PlanMyStuff.configuration
  message_type = request.headers['x-amz-sns-message-type'].to_s

  unless message_type == 'Notification'
    Rails.logger.info("[PlanMyStuff] SNS #{message_type}: #{sns_params.to_unsafe_h.inspect}")
    head(:ok)

    return
  end

  unless config.process_aws_webhooks
    head(:ok)

    return
  end

  unless matching_service?(config.aws_service_identifier)
    head(:ok)

    return
  end

  case sns_message_params.dig(:detail, :event_name)
  when 'SERVICE_DEPLOYMENT_COMPLETED'
    handle_deployment_completed
  end

  head(:ok)
end