diff options
Diffstat (limited to 'app/uploaders')
-rw-r--r-- | app/uploaders/job_artifact_uploader.rb | 1 | ||||
-rw-r--r-- | app/uploaders/object_storage/cdn.rb | 10 | ||||
-rw-r--r-- | app/uploaders/object_storage/cdn/google_cdn.rb | 4 | ||||
-rw-r--r-- | app/uploaders/packages/rpm/repository_file_uploader.rb | 33 |
4 files changed, 46 insertions, 2 deletions
diff --git a/app/uploaders/job_artifact_uploader.rb b/app/uploaders/job_artifact_uploader.rb index 83dc1030606..b38e7d93eac 100644 --- a/app/uploaders/job_artifact_uploader.rb +++ b/app/uploaders/job_artifact_uploader.rb @@ -3,6 +3,7 @@ class JobArtifactUploader < GitlabUploader extend Workhorse::UploadPath include ObjectStorage::Concern + include ObjectStorage::CDN::Concern UnknownFileLocationError = Class.new(StandardError) diff --git a/app/uploaders/object_storage/cdn.rb b/app/uploaders/object_storage/cdn.rb index 0711ab0bd28..e49e2780147 100644 --- a/app/uploaders/object_storage/cdn.rb +++ b/app/uploaders/object_storage/cdn.rb @@ -10,6 +10,16 @@ module ObjectStorage include Gitlab::Utils::StrongMemoize + UrlResult = Struct.new(:url, :used_cdn) + + def cdn_enabled_url(project, ip_address) + if Feature.enabled?(:ci_job_artifacts_cdn, project) && use_cdn?(ip_address) + UrlResult.new(cdn_signed_url, true) + else + UrlResult.new(url, false) + end + end + def use_cdn?(request_ip) return false unless cdn_options.is_a?(Hash) && cdn_options['provider'] return false unless cdn_provider diff --git a/app/uploaders/object_storage/cdn/google_cdn.rb b/app/uploaders/object_storage/cdn/google_cdn.rb index ea7683f131c..91bad1f8d6b 100644 --- a/app/uploaders/object_storage/cdn/google_cdn.rb +++ b/app/uploaders/object_storage/cdn/google_cdn.rb @@ -19,7 +19,7 @@ module ObjectStorage ip = IPAddr.new(request_ip) - return false if ip.private? + return false if ip.private? || ip.link_local? || ip.loopback? !GoogleIpCache.google_ip?(request_ip) end @@ -41,7 +41,7 @@ module ObjectStorage private def config_valid? - [key_name, decoded_key, cdn_url].all?(&:present?) + [key_name, decoded_key, cdn_url].all?(&:present?) && cdn_url.start_with?('https://') end def key_name diff --git a/app/uploaders/packages/rpm/repository_file_uploader.rb b/app/uploaders/packages/rpm/repository_file_uploader.rb new file mode 100644 index 00000000000..ff7e2bc719a --- /dev/null +++ b/app/uploaders/packages/rpm/repository_file_uploader.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true +module Packages + module Rpm + class RepositoryFileUploader < GitlabUploader + include ObjectStorage::Concern + + storage_options Gitlab.config.packages + + after :store, :schedule_background_upload + + alias_method :upload, :model + + def filename + model.file_name + end + + def store_dir + dynamic_segment + end + + private + + def dynamic_segment + raise ObjectNotReadyError, 'Repository file model not ready' unless model.id + + Gitlab::HashedPath.new( + 'projects', model.project_id, 'rpm', 'repository_files', model.id, + root_hash: model.project_id + ) + end + end + end +end |