# frozen_string_literal: true module NeetoCommonsBackend module SecretsManagement def neeto_secrets @_neeto_secrets ||= begin secrets = ActiveSupport::OrderedOptions.new secrets.deep_merge! common_secrets secrets.deep_merge! host_app_secrets # Fallback to config.secret_key_base if secrets.secret_key_base isn't set secrets.secret_key_base ||= config.secret_key_base secrets end @secrets = @_neeto_secrets end private def host_app_secrets files = config.paths["config/secrets"].existent files = files.reject { |path| path.end_with?(".enc") } unless config.read_encrypted_secrets _read_secrets files end def common_secrets _read_secrets [File.join(__dir__, "config/secrets.yml")] end def _read_secrets(files) Rails::Secrets.parse(files, env: Rails.env) end end end class Rails::Application include NeetoCommonsBackend::SecretsManagement alias_method :secrets, :neeto_secrets end