5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-04 19:15:44 +00:00
panel/app/models/site/api.rb

31 lines
701 B
Ruby
Raw Normal View History

# 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