Commit 875f66e7 authored by Stan Hu's avatar Stan Hu

Validate connection section in direct upload config

For some reason, `Settingslogic` doesn't always provide the right error
message when the `connection` block is omitted. Sometimes it erroneously
attributes the error section to a different part of the YAML
(e.g. `backup`, `dependency_proxy`).

This commit adds on more information on which `connection` block is
missing from the `gitlab.yml` (e.g. LFS, artifacts, or uploads).

Closes https://gitlab.com/gitlab-org/gitlab/issues/38258
parent 181bb515
---
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