2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'securerandom'
|
|
|
|
|
|
|
|
module Alerting
|
|
|
|
class ProjectAlertingSetting < ApplicationRecord
|
|
|
|
belongs_to :project
|
|
|
|
|
|
|
|
validates :token, presence: true
|
|
|
|
|
|
|
|
attr_encrypted :token,
|
|
|
|
mode: :per_attribute_iv,
|
2021-06-08 01:23:25 +05:30
|
|
|
key: Settings.attr_encrypted_db_key_base_32,
|
2020-04-22 19:07:51 +05:30
|
|
|
algorithm: 'aes-256-gcm'
|
|
|
|
|
|
|
|
before_validation :ensure_token
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ensure_token
|
|
|
|
self.token ||= generate_token
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_token
|
|
|
|
SecureRandom.hex
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|