debian-mirror-gitlab/app/models/ci/instance_variable.rb

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

51 lines
1.2 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Ci
2021-12-11 22:18:48 +05:30
class InstanceVariable < Ci::ApplicationRecord
2020-06-23 00:09:42 +05:30
extend Gitlab::ProcessMemoryCache::Helper
2020-05-24 23:13:21 +05:30
include Ci::NewHasVariable
include Ci::Maskable
2020-06-23 00:09:42 +05:30
include Limitable
self.limit_name = 'ci_instance_level_variables'
self.limit_scope = Limitable::GLOBAL_SCOPE
2020-05-24 23:13:21 +05:30
alias_attribute :secret_value, :value
validates :key, uniqueness: {
2020-10-24 23:57:45 +05:30
message: -> (object, data) { _("(%{value}) has already been taken") }
2020-05-24 23:13:21 +05:30
}
2020-10-24 23:57:45 +05:30
validates :value, length: {
maximum: 10_000,
too_long: -> (object, data) do
_('The value of the provided variable exceeds the %{count} character limit')
end
2020-06-23 00:09:42 +05:30
}
2020-05-24 23:13:21 +05:30
scope :unprotected, -> { where(protected: false) }
2020-06-23 00:09:42 +05:30
after_commit { self.class.invalidate_memory_cache(:ci_instance_variable_data) }
2020-05-24 23:13:21 +05:30
class << self
def all_cached
cached_data[:all]
end
def unprotected_cached
cached_data[:unprotected]
end
private
def cached_data
fetch_memory_cache(:ci_instance_variable_data) do
all_records = unscoped.all.to_a
{ all: all_records, unprotected: all_records.reject(&:protected?) }
end
end
2020-06-23 00:09:42 +05:30
end
2020-05-24 23:13:21 +05:30
end
end