diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-20 21:38:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-20 21:38:24 +0300 |
commit | 983a0bba5d2a042c4a3bbb22432ec192c7501d82 (patch) | |
tree | b153cd387c14ba23bd5a07514c7c01fddf6a78a0 /app/models/terraform | |
parent | a2bddee2cdb38673df0e004d5b32d9f77797de64 (diff) |
Add latest changes from gitlab-org/gitlab@12-10-stable-ee
Diffstat (limited to 'app/models/terraform')
-rw-r--r-- | app/models/terraform/state.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/models/terraform/state.rb b/app/models/terraform/state.rb index 8ca4ee9239a..c4e047ff9d1 100644 --- a/app/models/terraform/state.rb +++ b/app/models/terraform/state.rb @@ -2,14 +2,25 @@ module Terraform class State < ApplicationRecord + 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) } after_save :update_file_store, if: :saved_change_to_file? mount_uploader :file, StateUploader + default_value_for(:file) { CarrierWaveStringFile.new(DEFAULT) } + def update_file_store # The file.object_store is set during `uploader.store!` # which happens after object is inserted/updated @@ -19,5 +30,9 @@ module Terraform def file_store super || StateUploader.default_store end + + def locked? + self.lock_xid.present? + end end end |