2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Serverless
|
|
|
|
class DomainCluster < ApplicationRecord
|
|
|
|
self.table_name = 'serverless_domain_cluster'
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
HEX_REGEXP = %r{\A\h+\z}.freeze
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
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-03-09 13:42:32 +05:30
|
|
|
attr_encrypted :key,
|
|
|
|
mode: :per_attribute_iv,
|
|
|
|
key: Settings.attr_encrypted_db_key_base_truncated,
|
|
|
|
algorithm: 'aes-256-gcm'
|
|
|
|
|
|
|
|
validates :pages_domain, :knative, presence: true
|
2020-04-08 14:13:33 +05:30
|
|
|
validates :uuid, presence: true, uniqueness: true, length: { is: ::Serverless::Domain::UUID_LENGTH },
|
2020-03-09 13:42:32 +05:30
|
|
|
format: { with: HEX_REGEXP, message: 'only allows hex characters' }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
default_value_for(:uuid, allows_nil: false) { ::Serverless::Domain.generate_uuid }
|
2020-03-09 13:42:32 +05:30
|
|
|
|
|
|
|
delegate :domain, to: :pages_domain
|
2020-04-08 14:13:33 +05:30
|
|
|
delegate :cluster, to: :knative
|
|
|
|
|
|
|
|
def self.for_uuid(uuid)
|
|
|
|
joins(:pages_domain, :knative)
|
|
|
|
.includes(:pages_domain, :knative)
|
|
|
|
.find_by(uuid: uuid)
|
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
end
|