debian-mirror-gitlab/app/uploaders/terraform/state_uploader.rb

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

61 lines
1.7 KiB
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
module Terraform
class StateUploader < GitlabUploader
include ObjectStorage::Concern
storage_options Gitlab.config.terraform_state
2021-03-11 19:13:27 +05:30
# TODO: Remove this line
# See https://gitlab.com/gitlab-org/gitlab/-/issues/232917
alias_method :upload, :model
2021-02-22 17:27:13 +05:30
delegate :terraform_state, :project_id, to: :model
2020-04-22 19:07:51 +05:30
# Use Lockbox to encrypt/decrypt the stored file (registers CarrierWave callbacks)
encrypt(key: :key)
def filename
2021-02-22 17:27:13 +05:30
# This check is required to maintain backwards compatibility with
# states that were created prior to versioning being supported.
# This can be removed in 14.0 when support for these states is dropped.
# See https://gitlab.com/gitlab-org/gitlab/-/issues/258960
if terraform_state.versioning_enabled?
"#{model.version}.tfstate"
else
"#{model.uuid}.tfstate"
end
2020-04-22 19:07:51 +05:30
end
def store_dir
2021-02-22 17:27:13 +05:30
# This check is required to maintain backwards compatibility with
# states that were created prior to versioning being supported.
# This can be removed in 14.0 when support for these states is dropped.
# See https://gitlab.com/gitlab-org/gitlab/-/issues/258960
if terraform_state.versioning_enabled?
Gitlab::HashedPath.new(model.uuid, root_hash: project_id)
else
project_id.to_s
end
2020-04-22 19:07:51 +05:30
end
def key
OpenSSL::HMAC.digest('SHA256', Gitlab::Application.secrets.db_key_base, project_id.to_s)
end
class << self
def direct_upload_enabled?
false
end
def proxy_download_enabled?
true
end
def default_store
object_store_enabled? ? ObjectStorage::Store::REMOTE : ObjectStorage::Store::LOCAL
end
end
end
end