Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
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.

62 lines
1.5KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 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. if Code.ensure_loaded?(Config.Reader) do
  20. @reader Config.Reader
  21. def read(path), do: @reader.read!(path)
  22. else
  23. # support for Elixir less than 1.9
  24. @reader Mix.Config
  25. def read(path) do
  26. path
  27. |> @reader.eval!()
  28. |> elem(0)
  29. end
  30. end
  31. @spec read(Path.t()) :: keyword()
  32. @spec merge(keyword(), keyword()) :: keyword()
  33. def merge(c1, c2), do: @reader.merge(c1, c2)
  34. @spec default_config() :: keyword()
  35. def default_config do
  36. "config/config.exs"
  37. |> read()
  38. |> filter()
  39. end
  40. defp filter(configs) do
  41. configs
  42. |> Keyword.keys()
  43. |> Enum.reduce([], &Keyword.put(&2, &1, filter_group(&1, configs)))
  44. end
  45. @spec filter_group(atom(), keyword()) :: keyword()
  46. def filter_group(group, configs) do
  47. Enum.reject(configs[group], fn {key, _v} ->
  48. key in @reject_keys or group in @reject_groups or
  49. (group == :phoenix and key == :serve_endpoints)
  50. end)
  51. end
  52. end