debian-mirror-gitlab/config/initializers/direct_upload_support.rb

50 lines
1.6 KiB
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
class DirectUploadsValidator
2020-11-24 15:15:51 +05:30
SUPPORTED_DIRECT_UPLOAD_PROVIDERS = [ObjectStorage::Config::GOOGLE_PROVIDER,
ObjectStorage::Config::AWS_PROVIDER,
ObjectStorage::Config::AZURE_PROVIDER].freeze
2018-11-08 19:23:39 +05:30
ValidationError = Class.new(StandardError)
2020-01-01 13:55:28 +05:30
def verify!(uploader_type, object_store)
2018-11-08 19:23:39 +05:30
return unless object_store.enabled
return unless object_store.direct_upload
2020-01-01 13:55:28 +05:30
raise ValidationError, "Object storage is configured for '#{uploader_type}', but the 'connection' section is missing" unless object_store.key?('connection')
provider = object_store.connection&.provider.to_s
raise ValidationError, "No provider configured for '#{uploader_type}'. #{supported_provider_text}" if provider.blank?
2020-10-24 23:57:45 +05:30
return if provider_loaded?(provider)
2020-01-01 13:55:28 +05:30
raise ValidationError, "Object storage provider '#{provider}' is not supported " \
"when 'direct_upload' is used for '#{uploader_type}'. #{supported_provider_text}"
end
2020-10-24 23:57:45 +05:30
private
def provider_loaded?(provider)
return false unless SUPPORTED_DIRECT_UPLOAD_PROVIDERS.include?(provider)
2020-11-24 15:15:51 +05:30
require 'fog/azurerm' if provider == ObjectStorage::Config::AZURE_PROVIDER
2020-10-24 23:57:45 +05:30
true
end
2020-01-01 13:55:28 +05:30
def supported_provider_text
2020-10-24 23:57:45 +05:30
"Only #{SUPPORTED_DIRECT_UPLOAD_PROVIDERS.to_sentence} are supported."
2018-11-08 19:23:39 +05:30
end
end
DirectUploadsValidator.new.tap do |validator|
2020-01-01 13:55:28 +05:30
CONFIGS = {
artifacts: Gitlab.config.artifacts,
2020-10-24 23:57:45 +05:30
lfs: Gitlab.config.lfs,
uploads: Gitlab.config.uploads
2020-01-01 13:55:28 +05:30
}.freeze
CONFIGS.each do |uploader_type, uploader|
validator.verify!(uploader_type, uploader.object_store)
2018-11-08 19:23:39 +05:30
end
end