Make ObjectStoreSettings use more explicit and add specs
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
a3f1592b89
commit
edf1c1fccf
3 changed files with 37 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
require_relative '../settings'
|
||||
require_relative '../object_store_settings'
|
||||
|
||||
# Default settings
|
||||
Settings['ldap'] ||= Settingslogic.new({})
|
||||
|
@ -170,8 +171,6 @@ Settings.gitlab_ci['url'] ||= Settings.__send__(:build_gitlab_ci
|
|||
Settings['incoming_email'] ||= Settingslogic.new({})
|
||||
Settings.incoming_email['enabled'] = false if Settings.incoming_email['enabled'].nil?
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Build Artifacts
|
||||
#
|
||||
|
@ -181,8 +180,7 @@ Settings.artifacts['storage_path'] = Settings.absolute(Settings.artifacts.values
|
|||
# Settings.artifact['path'] is deprecated, use `storage_path` instead
|
||||
Settings.artifacts['path'] = Settings.artifacts['storage_path']
|
||||
Settings.artifacts['max_size'] ||= 100 # in megabytes
|
||||
ObjectStoreSettings.new(Settings.artifacts['object_store'])
|
||||
|
||||
Settings.artifacts['object_store'] = ObjectStoreSettings.parse(Settings.artifacts['object_store'])
|
||||
|
||||
#
|
||||
# Registry
|
||||
|
@ -221,7 +219,7 @@ Settings.pages.admin['certificate'] ||= ''
|
|||
Settings['lfs'] ||= Settingslogic.new({})
|
||||
Settings.lfs['enabled'] = true if Settings.lfs['enabled'].nil?
|
||||
Settings.lfs['storage_path'] = Settings.absolute(Settings.lfs['storage_path'] || File.join(Settings.shared['path'], "lfs-objects"))
|
||||
ObjectStoreSettings.new(Settings.lfs['object_store'])
|
||||
Settings.lfs['object_store'] = ObjectStoreSettings.parse(Settings.lfs['object_store'])
|
||||
|
||||
#
|
||||
# Uploads
|
||||
|
@ -229,7 +227,8 @@ ObjectStoreSettings.new(Settings.lfs['object_store'])
|
|||
Settings['uploads'] ||= Settingslogic.new({})
|
||||
Settings.uploads['storage_path'] = Settings.absolute(Settings.uploads['storage_path'] || 'public')
|
||||
Settings.uploads['base_dir'] = Settings.uploads['base_dir'] || 'uploads/-/system'
|
||||
ObjectStoreSettings.new(Settings.uploads['object_store'])
|
||||
Settings.uploads['object_store'] = ObjectStoreSettings.parse(Settings.uploads['object_store'])
|
||||
Settings.uploads['object_store']['remote_directory'] ||= 'uploads'
|
||||
|
||||
#
|
||||
# Mattermost
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
# Set default values for object_store settings
|
||||
class ObjectStoreSettings
|
||||
def initialize(object_store)
|
||||
def self.parse(object_store)
|
||||
object_store ||= Settingslogic.new({})
|
||||
object_store['enabled'] = false if object_store['enabled'].nil?
|
||||
object_store['remote_directory'] ||= nil
|
||||
object_store['direct_upload'] = false if object_store['direct_upload'].nil?
|
||||
object_store['background_upload'] = true if object_store['background_upload'].nil?
|
||||
object_store['proxy_download'] = false if object_store['proxy_download'].nil?
|
||||
|
||||
# Convert upload connection settings to use string keys, to make Fog happy
|
||||
object_store['connection']&.deep_stringify_keys!
|
||||
object_store
|
||||
end
|
||||
end
|
||||
|
|
29
spec/config/object_store_settings_spec.rb
Normal file
29
spec/config/object_store_settings_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'spec_helper'
|
||||
require Rails.root.join('config', 'object_store_settings.rb')
|
||||
|
||||
describe ObjectStoreSettings do
|
||||
describe '.parse' do
|
||||
it 'should set correct default values' do
|
||||
settings = described_class.parse(nil)
|
||||
|
||||
expect(settings['enabled']).to be false
|
||||
expect(settings['direct_upload']).to be false
|
||||
expect(settings['background_upload']).to be true
|
||||
expect(settings['remote_directory']).to be nil
|
||||
end
|
||||
|
||||
it 'respects original values' do
|
||||
original_settings = Settingslogic.new({
|
||||
'enabled' => true,
|
||||
'remote_directory' => 'artifacts'
|
||||
})
|
||||
|
||||
settings = described_class.parse(original_settings)
|
||||
|
||||
expect(settings['enabled']).to be true
|
||||
expect(settings['direct_upload']).to be false
|
||||
expect(settings['background_upload']).to be true
|
||||
expect(settings['remote_directory']).to eq 'artifacts'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue