Remove use of atoms in MRF.UserAllowListPolicy
[akkoma] / lib / pleroma / config / loader.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Config.Loader do
6 @reject_keys [
7 Pleroma.Repo,
8 Pleroma.Web.Endpoint,
9 :env,
10 :configurable_from_database,
11 :database,
12 :swarm
13 ]
14
15 if Code.ensure_loaded?(Config.Reader) do
16 @reader Config.Reader
17
18 def read(path), do: @reader.read!(path)
19 else
20 # support for Elixir less than 1.9
21 @reader Mix.Config
22 def read(path) do
23 path
24 |> @reader.eval!()
25 |> elem(0)
26 end
27 end
28
29 @spec read(Path.t()) :: keyword()
30
31 @spec merge(keyword(), keyword()) :: keyword()
32 def merge(c1, c2), do: @reader.merge(c1, c2)
33
34 @spec default_config() :: keyword()
35 def default_config do
36 "config/config.exs"
37 |> read()
38 |> filter()
39 end
40
41 defp filter(configs) do
42 configs
43 |> Keyword.keys()
44 |> Enum.reduce([], &Keyword.put(&2, &1, filter_group(&1, configs)))
45 end
46
47 @spec filter_group(atom(), keyword()) :: keyword()
48 def filter_group(group, configs) do
49 Enum.reject(configs[group], fn {key, _v} ->
50 key in @reject_keys or (group == :phoenix and key == :serve_endpoints)
51 end)
52 end
53 end