Commit 2112aeb4 authored by Stan Hu's avatar Stan Hu

Clean up dynamic loading of object storage gems

parent b221a58d
......@@ -17,7 +17,7 @@ class DirectUploadsValidator
raise ValidationError, "No provider configured for '#{uploader_type}'. #{supported_provider_text}" if provider.blank?
return if provider_loaded?(provider)
return if provider_supported?(provider)
raise ValidationError, "Object storage provider '#{provider}' is not supported " \
"when 'direct_upload' is used for '#{uploader_type}'. #{supported_provider_text}"
......@@ -25,12 +25,8 @@ class DirectUploadsValidator
private
def provider_loaded?(provider)
return false unless SUPPORTED_DIRECT_UPLOAD_PROVIDERS.include?(provider)
require 'fog/azurerm' if provider == ObjectStorage::Config::AZURE_PROVIDER
true
def provider_supported?(provider)
SUPPORTED_DIRECT_UPLOAD_PROVIDERS.include?(provider)
end
def supported_provider_text
......
......@@ -210,9 +210,7 @@ module Backup
def object_storage_config
@object_storage_config ||= begin
config = ObjectStorage::Config.new(Gitlab.config.backup.upload)
config.load_provider
config
ObjectStorage::Config.new(Gitlab.config.backup.upload)
end
end
......
......@@ -12,16 +12,6 @@ module ObjectStorage
@options = options.to_hash.deep_symbolize_keys
end
def load_provider
if aws?
require 'fog/aws'
elsif google?
require 'fog/google'
elsif azure?
require 'fog/azurerm'
end
end
def credentials
@credentials ||= options[:connection] || {}
end
......
......@@ -15,9 +15,6 @@ RSpec.describe 'CarrierWave::Storage::Fog::File' do
subject { CarrierWave::Storage::Fog::File.new(uploader, storage, test_filename) }
before do
require 'fog/azurerm'
require 'fog/aws'
stub_object_storage(connection_params: connection_options, remote_directory: bucket_name)
allow(uploader).to receive(:fog_directory).and_return(bucket_name)
......
......@@ -36,46 +36,6 @@ RSpec.describe ObjectStorage::Config do
subject { described_class.new(raw_config.as_json) }
describe '#load_provider' do
before do
subject.load_provider
end
context 'with AWS' do
it 'registers AWS as a provider' do
expect(Fog.providers.keys).to include(:aws)
end
end
context 'with Google' do
let(:credentials) do
{
provider: 'Google',
google_storage_access_key_id: 'GOOGLE_ACCESS_KEY_ID',
google_storage_secret_access_key: 'GOOGLE_SECRET_ACCESS_KEY'
}
end
it 'registers Google as a provider' do
expect(Fog.providers.keys).to include(:google)
end
end
context 'with Azure' do
let(:credentials) do
{
provider: 'AzureRM',
azure_storage_account_name: 'azuretest',
azure_storage_access_key: 'ABCD1234'
}
end
it 'registers AzureRM as a provider' do
expect(Fog.providers.keys).to include(:azurerm)
end
end
end
describe '#credentials' do
it { expect(subject.credentials).to eq(credentials) }
end
......
......@@ -201,10 +201,6 @@ RSpec.describe ObjectStorage::DirectUpload do
end
shared_examples 'a valid AzureRM upload' do
before do
require 'fog/azurerm'
end
it_behaves_like 'a valid upload'
it 'enables the Workhorse client' do
......
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