Commit 13406da8 authored by Michael Kozono's avatar Michael Kozono

Merge branch 'sh-validate-direct-upload-config' into 'master'

Validate connection section in direct upload config

Closes #38258

See merge request gitlab-org/gitlab!21270
parents 4aabfd47 875f66e7
---
title: Validate connection section in direct upload config
merge_request: 21270
author:
type: fixed
......@@ -3,17 +3,35 @@ class DirectUploadsValidator
ValidationError = Class.new(StandardError)
def verify!(object_store)
def verify!(uploader_type, object_store)
return unless object_store.enabled
return unless object_store.direct_upload
return if SUPPORTED_DIRECT_UPLOAD_PROVIDERS.include?(object_store.connection&.provider.to_s)
raise ValidationError, "Only #{SUPPORTED_DIRECT_UPLOAD_PROVIDERS.join(',')} are supported as a object storage provider when 'direct_upload' is used"
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?
return if SUPPORTED_DIRECT_UPLOAD_PROVIDERS.include?(provider)
raise ValidationError, "Object storage provider '#{provider}' is not supported " \
"when 'direct_upload' is used for '#{uploader_type}'. #{supported_provider_text}"
end
def supported_provider_text
"Only #{SUPPORTED_DIRECT_UPLOAD_PROVIDERS.join(', ')} are supported."
end
end
DirectUploadsValidator.new.tap do |validator|
[Gitlab.config.artifacts, Gitlab.config.uploads, Gitlab.config.lfs].each do |uploader|
validator.verify!(uploader.object_store)
CONFIGS = {
artifacts: Gitlab.config.artifacts,
uploads: Gitlab.config.uploads,
lfs: Gitlab.config.lfs
}.freeze
CONFIGS.each do |uploader_type, uploader|
validator.verify!(uploader_type, uploader.object_store)
end
end
......@@ -56,7 +56,7 @@ describe 'Direct upload support' do
let(:connection) { nil }
it 'raises an error' do
expect { subject }.to raise_error /are supported as a object storage provider when 'direct_upload' is used/
expect { subject }.to raise_error "No provider configured for '#{config_name}'. Only Google, AWS are supported."
end
end
......@@ -64,7 +64,20 @@ describe 'Direct upload support' do
let(:provider) { 'Rackspace' }
it 'raises an error' do
expect { subject }.to raise_error /are supported as a object storage provider when 'direct_upload' is used/
expect { subject }.to raise_error /Object storage provider '#{provider}' is not supported when 'direct_upload' is used for '#{config_name}'/
end
end
context 'when connection is omitted' do
let(:object_store) do
{
enabled: enabled,
direct_upload: direct_upload
}
end
it 'raises an error' do
expect { subject }.to raise_error /the 'connection' section is missing/
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment