2020-12-07 16:21:46 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
# Recibe notificaciones desde Airbrake
|
|
|
|
class NoticesController < BaseController
|
|
|
|
skip_before_action :verify_authenticity_token
|
|
|
|
|
|
|
|
# Generar un stacktrace en segundo plano y enviarlo por correo
|
|
|
|
# solo si la API key es verificable. Del otro lado siempre
|
|
|
|
# respondemos con lo mismo.
|
|
|
|
def create
|
2021-02-02 21:52:54 +00:00
|
|
|
if site&.airbrake_valid? airbrake_token
|
2020-12-07 16:21:46 +00:00
|
|
|
BacktraceJob.perform_later site_id: params[:site_id],
|
2020-12-07 18:27:24 +00:00
|
|
|
params: airbrake_params.to_h
|
2020-12-07 16:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
render status: 201, json: { id: 1, url: root_url }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# XXX: Por alguna razón Airbrake envía los datos con Content-Type:
|
|
|
|
# text/plain.
|
|
|
|
def airbrake_params
|
2020-12-07 18:27:24 +00:00
|
|
|
@airbrake_params ||= params.merge!(FastJsonparser.parse(request.raw_post) || {}).permit!
|
2020-12-07 16:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def site
|
|
|
|
@site ||= Site.find(params[:site_id])
|
2020-12-08 21:51:41 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2020-12-07 16:21:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def airbrake_token
|
|
|
|
@airbrake_token ||= params[:key]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|