diff --git a/app/models/deploy_local.rb b/app/models/deploy_local.rb index 67323a4..7285c73 100644 --- a/app/models/deploy_local.rb +++ b/app/models/deploy_local.rb @@ -59,6 +59,8 @@ class DeployLocal < Deploy 'PATH' => paths.join(':'), 'SPREE_API_KEY' => site.tienda_api_key, 'SPREE_URL' => site.tienda_url, + 'AIRBRAKE_PROJECT_ID' => site.id.to_s, + 'AIRBRAKE_PROJECT_KEY' => site.airbrake_api_key, 'JEKYLL_ENV' => Rails.env, 'LANG' => ENV['LANG'] } diff --git a/app/models/site/api.rb b/app/models/site/api.rb index 0c374f6..aef69bf 100644 --- a/app/models/site/api.rb +++ b/app/models/site/api.rb @@ -4,23 +4,30 @@ class Site module Api extend ActiveSupport::Concern - AIRBRAKE_SECRET = 'an api key for airbrake' - included do encrypts :api_key before_save :add_api_key_if_missing! - # Genera mensajes secretos que podemos usar para la API de cada sitio. + # Genera mensajes secretos que podemos usar para la API de cada + # sitio. + # + # XXX: Si no se configura una API key del sitio o genérica, no + # tenemos forma de verificar los mensajes, pero la generación de + # llaves no va a fallar. def verifier - @verifier ||= ActiveSupport::MessageVerifier.new api_key + @verifier ||= ActiveSupport::MessageVerifier.new(api_key || Rails.application.credentials.api_key || SecureRandom.hex(64)) end def airbrake_api_key - @airbrake_api_key ||= verifier.generate(AIRBRAKE_SECRET, purpose: :airbrake) + @airbrake_api_key ||= verifier.generate(airbrake_secret, purpose: :airbrake) end private + def airbrake_secret + Rails.application.credentials.airbrake || SecureRandom.hex(64) + end + # Asegurarse que el sitio tenga una llave para la API def add_api_key_if_missing! self.api_key ||= SecureRandom.hex(64)