2020-01-21 14:49:22 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-01-21 14:49:22 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-01-18 13:55:33 +00:00
|
|
|
defmodule Pleroma.Config.Loader do
|
2021-06-08 21:07:51 +00:00
|
|
|
# These modules are only being used as keys here (for equality check),
|
|
|
|
# so it's okay to use `Module.concat/1` to have the compiler ignore them.
|
|
|
|
@reject_keys [
|
|
|
|
Module.concat(["Pleroma.Repo"]),
|
|
|
|
Module.concat(["Pleroma.Web.Endpoint"]),
|
|
|
|
:env,
|
|
|
|
:configurable_from_database,
|
|
|
|
:database,
|
|
|
|
:swarm
|
|
|
|
]
|
|
|
|
|
|
|
|
@reject_groups [
|
|
|
|
:postgrex,
|
|
|
|
:tesla
|
|
|
|
]
|
2020-07-06 05:48:20 +00:00
|
|
|
|
2022-09-02 20:35:08 +00:00
|
|
|
@reader Config.Reader
|
2020-01-18 13:55:33 +00:00
|
|
|
|
2020-03-11 13:25:53 +00:00
|
|
|
@spec read(Path.t()) :: keyword()
|
2022-09-02 20:35:08 +00:00
|
|
|
def read(path), do: @reader.read!(path)
|
2020-03-11 13:25:53 +00:00
|
|
|
|
|
|
|
@spec merge(keyword(), keyword()) :: keyword()
|
|
|
|
def merge(c1, c2), do: @reader.merge(c1, c2)
|
2020-01-18 13:55:33 +00:00
|
|
|
|
2020-03-11 13:25:53 +00:00
|
|
|
@spec default_config() :: keyword()
|
|
|
|
def default_config do
|
|
|
|
"config/config.exs"
|
|
|
|
|> read()
|
2020-01-21 14:49:22 +00:00
|
|
|
|> filter()
|
2020-01-18 13:55:33 +00:00
|
|
|
end
|
|
|
|
|
2020-01-21 14:49:22 +00:00
|
|
|
defp filter(configs) do
|
|
|
|
configs
|
|
|
|
|> Keyword.keys()
|
|
|
|
|> Enum.reduce([], &Keyword.put(&2, &1, filter_group(&1, configs)))
|
|
|
|
end
|
2020-01-18 13:55:33 +00:00
|
|
|
|
2020-01-21 14:49:22 +00:00
|
|
|
@spec filter_group(atom(), keyword()) :: keyword()
|
|
|
|
def filter_group(group, configs) do
|
|
|
|
Enum.reject(configs[group], fn {key, _v} ->
|
2021-06-08 21:07:51 +00:00
|
|
|
key in @reject_keys or group in @reject_groups or
|
2020-07-06 05:48:20 +00:00
|
|
|
(group == :phoenix and key == :serve_endpoints)
|
2020-01-21 14:49:22 +00:00
|
|
|
end)
|
2020-01-18 13:55:33 +00:00
|
|
|
end
|
|
|
|
end
|