You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
akkoma-cachapa/lib/pleroma/config/loader.ex

60 lines
1.3 KiB

# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
5 years ago
defmodule Pleroma.Config.Loader do
@reject_keys [
Pleroma.Repo,
Pleroma.Web.Endpoint,
:env,
:configurable_from_database,
:database,
:swarm
]
@reject_groups [
:postgrex,
:tesla
]
5 years ago
if Code.ensure_loaded?(Config.Reader) do
@reader Config.Reader
5 years ago
def read(path), do: @reader.read!(path)
5 years ago
else
# support for Elixir less than 1.9
@reader Mix.Config
5 years ago
def read(path) do
path
|> @reader.eval!()
|> elem(0)
end
5 years ago
end
@spec read(Path.t()) :: keyword()
@spec merge(keyword(), keyword()) :: keyword()
def merge(c1, c2), do: @reader.merge(c1, c2)
5 years ago
@spec default_config() :: keyword()
def default_config do
"config/config.exs"
|> read()
|> filter()
5 years ago
end
defp filter(configs) do
configs
|> Keyword.keys()
|> Enum.reduce([], &Keyword.put(&2, &1, filter_group(&1, configs)))
end
5 years ago
@spec filter_group(atom(), keyword()) :: keyword()
def filter_group(group, configs) do
Enum.reject(configs[group], fn {key, _v} ->
key in @reject_keys or group in @reject_groups or
(group == :phoenix and key == :serve_endpoints)
end)
5 years ago
end
end