Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-07 06:07:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-07 06:07:43 +0300
commitdc87c6514746996c8d720527c10102d42809804b (patch)
tree7a2b99f7237c674da2176d5d297daf1af6d9b89f
parent4e375367b78bb44bd00957522cd9fc3e6d403fef (diff)
Add latest changes from gitlab-org/gitlab@master
-rw-r--r--changelogs/unreleased/sh-validate-direct-upload-config.yml5
-rw-r--r--config/initializers/direct_upload_support.rb28
-rw-r--r--spec/initializers/direct_upload_support_spec.rb17
3 files changed, 43 insertions, 7 deletions
diff --git a/changelogs/unreleased/sh-validate-direct-upload-config.yml b/changelogs/unreleased/sh-validate-direct-upload-config.yml
new file mode 100644
index 00000000000..15216f8d13a
--- /dev/null
+++ b/changelogs/unreleased/sh-validate-direct-upload-config.yml
@@ -0,0 +1,5 @@
+---
+title: Validate connection section in direct upload config
+merge_request: 21270
+author:
+type: fixed
diff --git a/config/initializers/direct_upload_support.rb b/config/initializers/direct_upload_support.rb
index 32fc8c8bc69..0fc6e82207e 100644
--- a/config/initializers/direct_upload_support.rb
+++ b/config/initializers/direct_upload_support.rb
@@ -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
diff --git a/spec/initializers/direct_upload_support_spec.rb b/spec/initializers/direct_upload_support_spec.rb
index 4b3fe871cef..7db40f4b5ab 100644
--- a/spec/initializers/direct_upload_support_spec.rb
+++ b/spec/initializers/direct_upload_support_spec.rb
@@ -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