Welcome to mirror list, hosted at ThFree Co, Russian Federation.

state.rb « terraform « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c50b9da1310990f740356e8c20e8999579182b7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

module Terraform
  class State < ApplicationRecord
    include UsageStatistics
    include FileStoreMounter

    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) }

    mount_file_store_uploader StateUploader

    default_value_for(:file) { CarrierWaveStringFile.new(DEFAULT) }

    def file_store
      super || StateUploader.default_store
    end

    def local?
      file_store == ObjectStorage::Store::LOCAL
    end

    def locked?
      self.lock_xid.present?
    end
  end
end

Terraform::State.prepend_if_ee('EE::Terraform::State')