initial commit

This commit is contained in:
Alex Turchyn committed 2023-06-01 00:00:58 +03:00
commit 97c462ead2
159 files changed
+10987

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
# frozen_string_literal: true
module LoadActiveStorageConfigs
STORAGE_YML_PATH = Rails.root.join('config/storage.yml')
module_function
def call
reload unless loaded?
end
def loaded?
@loaded
end
def reload
encrypted_config = EncryptedConfig.find_by(key: EncryptedConfig::FILES_STORAGE_KEY)
return unless encrypted_config
service, configs = encrypted_config.value.values_at('service', 'configs')
service_configurations = ActiveSupport::ConfigurationFile.parse(STORAGE_YML_PATH)
service_configurations[service].merge!(configs) if configs.present?
service_configurations[service][:force_path_style] = true if configs&.dig('endpoint').present?
if service == 'google'
service_configurations[service][:credentials] = JSON.parse(configs.fetch('credentials', '{}'))
end
ActiveStorage::Blob.services = ActiveStorage::Service::Registry.new(service_configurations)
ActiveStorage::Blob.service = ActiveStorage::Blob.services.fetch(service.to_sym)
ensure
@loaded = true
end
end