10
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
|
# File 'app/controllers/ses_dashboard/webhooks_controller.rb', line 10
def create
project = Project.find_by!(token: params[:project_token])
request.body.rewind
body = request.body.read
sns = parse_sns_json(body)
verify_sns_signature!(sns) if sns && SesDashboard.configuration.verify_sns_signature
result = WebhookProcessor.new(body).process
case result.action
when :confirm_subscription
confirm_subscription(result.subscribe_url)
when :process_event
WebhookEventPersistor.new(project, result).persist
end
head :ok
rescue ActiveRecord::RecordNotFound
head :not_found
rescue SnsSignatureVerifier::VerificationError => e
Rails.logger.warn("[SesDashboard] SNS signature rejected: #{e.message}") if defined?(Rails)
head :forbidden
rescue => e
Rails.logger.error("[SesDashboard] Webhook error: #{e.message}") if defined?(Rails)
head :unprocessable_entity
end
|