mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 04:31:41 +00:00
31 lines
701 B
Ruby
31 lines
701 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
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.
|
||
|
def verifier
|
||
|
@verifier ||= ActiveSupport::MessageVerifier.new api_key
|
||
|
end
|
||
|
|
||
|
def airbrake_api_key
|
||
|
@airbrake_api_key ||= verifier.generate(AIRBRAKE_SECRET, purpose: :airbrake)
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
# Asegurarse que el sitio tenga una llave para la API
|
||
|
def add_api_key_if_missing!
|
||
|
self.api_key ||= SecureRandom.hex(64)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|