diff options
Diffstat (limited to 'app/uploaders')
-rw-r--r-- | app/uploaders/ci/pipeline_artifact_uploader.rb | 21 | ||||
-rw-r--r-- | app/uploaders/job_artifact_uploader.rb | 7 | ||||
-rw-r--r-- | app/uploaders/object_storage.rb | 16 | ||||
-rw-r--r-- | app/uploaders/packages/package_file_uploader.rb | 7 |
4 files changed, 33 insertions, 18 deletions
diff --git a/app/uploaders/ci/pipeline_artifact_uploader.rb b/app/uploaders/ci/pipeline_artifact_uploader.rb new file mode 100644 index 00000000000..d3a83c5d633 --- /dev/null +++ b/app/uploaders/ci/pipeline_artifact_uploader.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Ci + class PipelineArtifactUploader < GitlabUploader + include ObjectStorage::Concern + + storage_options Gitlab.config.artifacts + + alias_method :upload, :model + + def store_dir + dynamic_segment + end + + private + + def dynamic_segment + Gitlab::HashedPath.new('pipelines', model.pipeline_id, 'artifacts', model.id, root_hash: model.project_id) + end + end +end diff --git a/app/uploaders/job_artifact_uploader.rb b/app/uploaders/job_artifact_uploader.rb index 400f0b3dcc6..47976c909e8 100644 --- a/app/uploaders/job_artifact_uploader.rb +++ b/app/uploaders/job_artifact_uploader.rb @@ -36,15 +36,10 @@ class JobArtifactUploader < GitlabUploader end def hashed_path - File.join(disk_hash[0..1], disk_hash[2..3], disk_hash, - model.created_at.utc.strftime('%Y_%m_%d'), model.job_id.to_s, model.id.to_s) + Gitlab::HashedPath.new(model.created_at.utc.strftime('%Y_%m_%d'), model.job_id, model.id, root_hash: model.project_id) end def legacy_path File.join(model.created_at.utc.strftime('%Y_%m'), model.project_id.to_s, model.job_id.to_s) end - - def disk_hash - @disk_hash ||= Digest::SHA2.hexdigest(model.project_id.to_s) - end end diff --git a/app/uploaders/object_storage.rb b/app/uploaders/object_storage.rb index 63b6197a04d..ac1f022c63f 100644 --- a/app/uploaders/object_storage.rb +++ b/app/uploaders/object_storage.rb @@ -169,10 +169,6 @@ module ObjectStorage object_store_options.connection.to_hash.deep_symbolize_keys end - def consolidated_settings? - object_store_options.fetch('consolidated_settings', false) - end - def remote_store_path object_store_options.remote_directory end @@ -193,14 +189,18 @@ module ObjectStorage File.join(self.root, TMP_UPLOAD_PATH) end + def object_store_config + ObjectStorage::Config.new(object_store_options) + end + def workhorse_remote_upload_options(has_length:, maximum_size: nil) return unless self.object_store_enabled? return unless self.direct_upload_enabled? id = [CarrierWave.generate_cache_id, SecureRandom.hex].join('-') upload_path = File.join(TMP_UPLOAD_PATH, id) - direct_upload = ObjectStorage::DirectUpload.new(self.object_store_credentials, remote_store_path, upload_path, - has_length: has_length, maximum_size: maximum_size, consolidated_settings: consolidated_settings?) + direct_upload = ObjectStorage::DirectUpload.new(self.object_store_config, upload_path, + has_length: has_length, maximum_size: maximum_size) direct_upload.to_hash.merge(ID: id) end @@ -283,6 +283,10 @@ module ObjectStorage self.class.object_store_credentials end + def fog_attributes + @fog_attributes ||= self.class.object_store_config.fog_attributes + end + # Set ACL of uploaded objects to not-public (fog-aws)[1] or no ACL at all # (fog-google). Value is ignored by other supported backends (fog-aliyun, # fog-openstack, fog-rackspace) diff --git a/app/uploaders/packages/package_file_uploader.rb b/app/uploaders/packages/package_file_uploader.rb index 20fcf0a7a32..28545b9fcdf 100644 --- a/app/uploaders/packages/package_file_uploader.rb +++ b/app/uploaders/packages/package_file_uploader.rb @@ -20,11 +20,6 @@ class Packages::PackageFileUploader < GitlabUploader private def dynamic_segment - File.join(disk_hash[0..1], disk_hash[2..3], disk_hash, - 'packages', model.package.id.to_s, 'files', model.id.to_s) - end - - def disk_hash - @disk_hash ||= Digest::SHA2.hexdigest(model.package.project_id.to_s) + Gitlab::HashedPath.new('packages', model.package.id, 'files', model.id, root_hash: model.package.project_id) end end |