Commit 0b18c956 authored by Stan Hu's avatar Stan Hu

Dynamically load Azure dependency for backups

The `fog/azurerm` gem is not loaded by default in `Gemfile`. To make
backups work, we need to load this dynamically when needed.
parent aa96300a
......@@ -196,8 +196,10 @@ module Backup
end
def connect_to_remote_directory(connection_settings)
settings = connection_settings.symbolize_keys
load_provider(settings)
# our settings use string keys, but Fog expects symbols
connection = ::Fog::Storage.new(connection_settings.symbolize_keys)
connection = ::Fog::Storage.new(settings)
# We only attempt to create the directory for local backups. For AWS
# and other cloud providers, we cannot guarantee the user will have
......@@ -209,6 +211,14 @@ module Backup
end
end
def load_provider(settings)
provider = settings[:provider]
return unless provider.present?
require 'fog/azurerm' if provider == 'AzureRM'
end
def remote_directory
Gitlab.config.backup.upload.remote_directory
end
......
......@@ -416,5 +416,28 @@ RSpec.describe Backup::Manager do
subject.upload
end
end
context 'with AzureRM provider' do
before do
stub_backup_setting(
upload: {
connection: {
provider: 'AzureRM',
azure_storage_account_name: 'test-access-id',
azure_storage_access_key: 'secret'
},
remote_directory: 'directory',
multipart_chunk_size: nil,
encryption: nil,
encryption_key: nil,
storage_class: nil
}
)
end
it 'loads the provider' do
expect { subject.upload }.not_to raise_error
end
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