Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

60 рядки
1.3KB

  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. @reject_keys [
  6. Pleroma.Repo,
  7. Pleroma.Web.Endpoint,
  8. :env,
  9. :configurable_from_database,
  10. :database,
  11. :swarm
  12. ]
  13. @reject_groups [
  14. :postgrex,
  15. :tesla
  16. ]
  17. if Code.ensure_loaded?(Config.Reader) do
  18. @reader Config.Reader
  19. def read(path), do: @reader.read!(path)
  20. else
  21. # support for Elixir less than 1.9
  22. @reader Mix.Config
  23. def read(path) do
  24. path
  25. |> @reader.eval!()
  26. |> elem(0)
  27. end
  28. end
  29. @spec read(Path.t()) :: keyword()
  30. @spec merge(keyword(), keyword()) :: keyword()
  31. def merge(c1, c2), do: @reader.merge(c1, c2)
  32. @spec default_config() :: keyword()
  33. def default_config do
  34. "config/config.exs"
  35. |> read()
  36. |> filter()
  37. end
  38. defp filter(configs) do
  39. configs
  40. |> Keyword.keys()
  41. |> Enum.reduce([], &Keyword.put(&2, &1, filter_group(&1, configs)))
  42. end
  43. @spec filter_group(atom(), keyword()) :: keyword()
  44. def filter_group(group, configs) do
  45. Enum.reject(configs[group], fn {key, _v} ->
  46. key in @reject_keys or group in @reject_groups or
  47. (group == :phoenix and key == :serve_endpoints)
  48. end)
  49. end
  50. end