diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /app/uploaders/object_storage/cdn.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'app/uploaders/object_storage/cdn.rb')
-rw-r--r-- | app/uploaders/object_storage/cdn.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/uploaders/object_storage/cdn.rb b/app/uploaders/object_storage/cdn.rb new file mode 100644 index 00000000000..0711ab0bd28 --- /dev/null +++ b/app/uploaders/object_storage/cdn.rb @@ -0,0 +1,46 @@ +# rubocop:disable Naming/FileName +# frozen_string_literal: true + +require_relative 'cdn/google_cdn' + +module ObjectStorage + module CDN + module Concern + extend ActiveSupport::Concern + + include Gitlab::Utils::StrongMemoize + + def use_cdn?(request_ip) + return false unless cdn_options.is_a?(Hash) && cdn_options['provider'] + return false unless cdn_provider + + cdn_provider.use_cdn?(request_ip) + end + + def cdn_signed_url + cdn_provider&.signed_url(path) + end + + private + + def cdn_provider + strong_memoize(:cdn_provider) do + provider = cdn_options['provider']&.downcase + + next unless provider + next GoogleCDN.new(cdn_options) if provider == 'google' + + raise "Unknown CDN provider: #{provider}" + end + end + + def cdn_options + return {} unless options.object_store.key?('cdn') + + options.object_store.cdn + end + end + end +end + +# rubocop:enable Naming/FileName |