2020-01-21 07:49:22 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-01-18 06:55:33 -07:00
|
|
|
defmodule Pleroma.Config.Loader do
|
2020-01-21 07:49:22 -07:00
|
|
|
@reject_keys [
|
|
|
|
Pleroma.Repo,
|
|
|
|
Pleroma.Web.Endpoint,
|
|
|
|
:env,
|
|
|
|
:configurable_from_database,
|
|
|
|
:database,
|
|
|
|
:swarm
|
|
|
|
]
|
|
|
|
|
2020-01-18 06:55:33 -07:00
|
|
|
if Code.ensure_loaded?(Config.Reader) do
|
|
|
|
@spec load(Path.t()) :: keyword()
|
|
|
|
def load(path), do: Config.Reader.read!(path)
|
|
|
|
|
|
|
|
defp do_merge(conf1, conf2), do: Config.Reader.merge(conf1, conf2)
|
|
|
|
else
|
|
|
|
# support for Elixir less than 1.9
|
|
|
|
@spec load(Path.t()) :: keyword()
|
|
|
|
def load(path) do
|
2020-01-21 07:49:22 -07:00
|
|
|
path
|
|
|
|
|> Mix.Config.eval!()
|
|
|
|
|> elem(0)
|
2020-01-18 06:55:33 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
defp do_merge(conf1, conf2), do: Mix.Config.merge(conf1, conf2)
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec load_and_merge() :: keyword()
|
|
|
|
def load_and_merge do
|
|
|
|
all_paths =
|
|
|
|
if Pleroma.Config.get(:release),
|
2020-01-25 08:42:04 -07:00
|
|
|
do: ["config/config.exs", "config/releases.exs"],
|
|
|
|
else: ["config/config.exs"]
|
2020-01-18 06:55:33 -07:00
|
|
|
|
|
|
|
all_paths
|
|
|
|
|> Enum.map(&load(&1))
|
2020-01-21 07:49:22 -07:00
|
|
|
|> Enum.reduce([], &do_merge(&2, &1))
|
|
|
|
|> filter()
|
2020-01-18 06:55:33 -07:00
|
|
|
end
|
|
|
|
|
2020-01-21 07:49:22 -07:00
|
|
|
defp filter(configs) do
|
|
|
|
configs
|
|
|
|
|> Keyword.keys()
|
|
|
|
|> Enum.reduce([], &Keyword.put(&2, &1, filter_group(&1, configs)))
|
|
|
|
end
|
2020-01-18 06:55:33 -07:00
|
|
|
|
2020-01-21 07:49:22 -07:00
|
|
|
@spec filter_group(atom(), keyword()) :: keyword()
|
|
|
|
def filter_group(group, configs) do
|
|
|
|
Enum.reject(configs[group], fn {key, _v} ->
|
|
|
|
key in @reject_keys or (group == :phoenix and key == :serve_endpoints)
|
|
|
|
end)
|
2020-01-18 06:55:33 -07:00
|
|
|
end
|
|
|
|
end
|