debian-mirror-gitlab/app/models/terraform/state.rb

40 lines
983 B
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
module Terraform
class State < ApplicationRecord
2020-06-23 00:09:42 +05:30
include UsageStatistics
2020-10-24 23:57:45 +05:30
include FileStoreMounter
2020-06-23 00:09:42 +05:30
2020-04-22 19:07:51 +05:30
DEFAULT = '{"version":1}'.freeze
HEX_REGEXP = %r{\A\h+\z}.freeze
UUID_LENGTH = 32
belongs_to :project
belongs_to :locked_by_user, class_name: 'User'
validates :project_id, presence: true
validates :uuid, presence: true, uniqueness: true, length: { is: UUID_LENGTH },
format: { with: HEX_REGEXP, message: 'only allows hex characters' }
default_value_for(:uuid, allows_nil: false) { SecureRandom.hex(UUID_LENGTH / 2) }
2020-10-24 23:57:45 +05:30
mount_file_store_uploader StateUploader
2020-04-22 19:07:51 +05:30
default_value_for(:file) { CarrierWaveStringFile.new(DEFAULT) }
def file_store
super || StateUploader.default_store
end
2020-10-24 23:57:45 +05:30
def local?
file_store == ObjectStorage::Store::LOCAL
end
2020-04-22 19:07:51 +05:30
def locked?
self.lock_xid.present?
end
end
end
2020-10-24 23:57:45 +05:30
Terraform::State.prepend_if_ee('EE::Terraform::State')