logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

loader.ex (1299B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Config.Loader do
  5. # These modules are only being used as keys here (for equality check),
  6. # so it's okay to use `Module.concat/1` to have the compiler ignore them.
  7. @reject_keys [
  8. Module.concat(["Pleroma.Repo"]),
  9. Module.concat(["Pleroma.Web.Endpoint"]),
  10. :env,
  11. :configurable_from_database,
  12. :database,
  13. :swarm
  14. ]
  15. @reject_groups [
  16. :postgrex,
  17. :tesla
  18. ]
  19. @reader Config.Reader
  20. @spec read(Path.t()) :: keyword()
  21. def read(path), do: @reader.read!(path)
  22. @spec merge(keyword(), keyword()) :: keyword()
  23. def merge(c1, c2), do: @reader.merge(c1, c2)
  24. @spec default_config() :: keyword()
  25. def default_config do
  26. "config/config.exs"
  27. |> read()
  28. |> filter()
  29. end
  30. defp filter(configs) do
  31. configs
  32. |> Keyword.keys()
  33. |> Enum.reduce([], &Keyword.put(&2, &1, filter_group(&1, configs)))
  34. end
  35. @spec filter_group(atom(), keyword()) :: keyword()
  36. def filter_group(group, configs) do
  37. Enum.reject(configs[group], fn {key, _v} ->
  38. key in @reject_keys or group in @reject_groups or
  39. (group == :phoenix and key == :serve_endpoints)
  40. end)
  41. end
  42. end