2019-12-14 10:07:56 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Serverless
|
|
|
|
class DomainCluster < ApplicationRecord
|
|
|
|
self.table_name = 'serverless_domain_cluster'
|
|
|
|
|
2020-01-25 04:08:46 -05:00
|
|
|
HEX_REGEXP = %r{\A\h+\z}.freeze
|
|
|
|
|
2019-12-14 10:07:56 -05:00
|
|
|
belongs_to :pages_domain
|
|
|
|
belongs_to :knative, class_name: 'Clusters::Applications::Knative', foreign_key: 'clusters_applications_knative_id'
|
|
|
|
belongs_to :creator, class_name: 'User', optional: true
|
|
|
|
|
2020-02-05 04:08:43 -05:00
|
|
|
attr_encrypted :key,
|
|
|
|
mode: :per_attribute_iv,
|
2021-04-22 17:09:53 -04:00
|
|
|
key: Settings.attr_encrypted_db_key_base_32,
|
2020-02-05 04:08:43 -05:00
|
|
|
algorithm: 'aes-256-gcm'
|
|
|
|
|
2020-01-25 04:08:46 -05:00
|
|
|
validates :pages_domain, :knative, presence: true
|
2020-02-20 10:08:44 -05:00
|
|
|
validates :uuid, presence: true, uniqueness: true, length: { is: ::Serverless::Domain::UUID_LENGTH },
|
2020-01-25 04:08:46 -05:00
|
|
|
format: { with: HEX_REGEXP, message: 'only allows hex characters' }
|
|
|
|
|
2020-02-20 10:08:44 -05:00
|
|
|
default_value_for(:uuid, allows_nil: false) { ::Serverless::Domain.generate_uuid }
|
2020-01-28 10:08:36 -05:00
|
|
|
|
|
|
|
delegate :domain, to: :pages_domain
|
2020-02-20 10:08:44 -05:00
|
|
|
delegate :cluster, to: :knative
|
|
|
|
|
|
|
|
def self.for_uuid(uuid)
|
|
|
|
joins(:pages_domain, :knative)
|
|
|
|
.includes(:pages_domain, :knative)
|
|
|
|
.find_by(uuid: uuid)
|
|
|
|
end
|
2019-12-14 10:07:56 -05:00
|
|
|
end
|
|
|
|
end
|