debian-mirror-gitlab/app/models/serverless/domain_cluster.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
Ruby
Raw Normal View History

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-13 15:44:24 +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-13 15:44:24 +05:30
attr_encrypted :key,
mode: :per_attribute_iv,
2021-06-08 01:23:25 +05:30
key: Settings.attr_encrypted_db_key_base_32,
2020-03-13 15:44:24 +05:30
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 },
2022-08-27 11:52:29 +05:30
format: { with: HEX_REGEXP, message: 'only allows hex characters' }
2020-03-13 15:44:24 +05:30
2023-01-13 00:05:48 +05:30
after_initialize :set_uuid, if: :new_record?
2020-03-13 15:44:24 +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
2023-01-13 00:05:48 +05:30
private
def set_uuid
self.uuid = ::Serverless::Domain.generate_uuid
end
2020-01-01 13:55:28 +05:30
end
end