Skip to content
Snippets Groups Projects
Commit eea26a93 authored by Kamil Trzcińśki's avatar Kamil Trzcińśki
Browse files

Update validator

parent b8370c9f
No related branches found
No related tags found
No related merge requests found
SUPPORTED_DIRECT_UPLOAD_PROVIDERS = %w(Google AWS).freeze
class DirectUploadsValidator
SUPPORTED_DIRECT_UPLOAD_PROVIDERS = %w(Google AWS).freeze
 
def verify_provider_support!(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)
ValidationError = Class.new(StandardError)
 
raise "Only #{SUPPORTED_DIRECT_UPLOAD_PROVIDERS.join(',')} are supported as a object storage provider when 'direct_upload' is used"
def verify!(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"
end
end
 
verify_provider_support!(Gitlab.config.artifacts.object_store)
verify_provider_support!(Gitlab.config.uploads.object_store)
verify_provider_support!(Gitlab.config.lfs.object_store)
DirectUploadsValidator.new.tap do |validator|
[Gitlab.config.artifacts, Gitlab.config.uploads, Gitlab.config.lfs].each do |uploader|
validator.verify!(uploader.object_store)
end
end
Loading
Loading
@@ -2,7 +2,7 @@ module ObjectStorage
#
# The DirectUpload c;ass generates a set of presigned URLs
# that can be used to upload data to object storage from untrusted component: Workhorse, Runner?
#
#
# For Google it assumes that the platform supports variable Content-Length.
#
# For AWS it initiates Multipart Upload and presignes a set of part uploads.
Loading
Loading
Loading
Loading
@@ -6,7 +6,7 @@ describe 'Direct upload support' do
end
 
where(:config_name) do
['lfs', 'artifacts', 'uploads']
%w(lfs artifacts uploads)
end
 
with_them do
Loading
Loading
@@ -23,8 +23,9 @@ describe 'Direct upload support' do
end
 
before do
allow(Gitlab.config).to receive_messages(to_settings(
config_name => { object_store: object_store }))
allow(Gitlab.config).to receive_messages(to_settings(config_name => {
object_store: object_store
}))
end
 
context 'when object storage is enabled' do
Loading
Loading
Loading
Loading
@@ -161,28 +161,4 @@ describe ObjectStorage::DirectUpload do
end
end
end
describe '#get_url' do
# this method can only be tested with integration tests
end
describe '#delete_url' do
# this method can only be tested with integration tests
end
describe '#store_url' do
# this method can only be tested with integration tests
end
describe '#multipart_part_upload_url' do
# this method can only be tested with integration tests
end
describe '#multipart_complete_url' do
# this method can only be tested with integration tests
end
describe '#multipart_abort_url' do
# this method can only be tested with integration tests
end
end
Loading
Loading
@@ -47,8 +47,8 @@ module StubObjectStorage
end
 
def stub_object_storage_multipart_init(endpoint, upload_id = "upload_id")
stub_request(:post, %r{\A#{endpoint}tmp/uploads/[a-z0-9-]*\?uploads\z}).
to_return status: 200, body: <<-EOS.strip_heredoc
stub_request(:post, %r{\A#{endpoint}tmp/uploads/[a-z0-9-]*\?uploads\z})
.to_return status: 200, body: <<-EOS.strip_heredoc
<?xml version="1.0" encoding="UTF-8"?>
<InitiateMultipartUploadResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Bucket>example-bucket</Bucket>
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment