diff options
author | Alexander Strizhakov <alex.strizhakov@gmail.com> | 2020-01-17 16:28:44 +0300 |
---|---|---|
committer | Alexander Strizhakov <alex.strizhakov@gmail.com> | 2020-01-17 16:28:44 +0300 |
commit | 7676ed82397d73a20aad1ae4b47690923ddfb162 (patch) | |
tree | 8e0e0ab17107d3a41122d5b13415118cb91c8608 /lib/pleroma | |
parent | ce027fd0ef1080b03e7982e5939b0c7db6e3b783 (diff) | |
download | pleroma-7676ed82397d73a20aad1ae4b47690923ddfb162.tar.gz |
some clean up
Diffstat (limited to 'lib/pleroma')
-rw-r--r-- | lib/pleroma/config/config_db.ex | 17 | ||||
-rw-r--r-- | lib/pleroma/config/holder.ex | 17 | ||||
-rw-r--r-- | lib/pleroma/config/transfer_task.ex | 15 | ||||
-rw-r--r-- | lib/pleroma/docs/json.ex | 2 |
4 files changed, 33 insertions, 18 deletions
diff --git a/lib/pleroma/config/config_db.ex b/lib/pleroma/config/config_db.ex index 294fbc3f0..6d48e0300 100644 --- a/lib/pleroma/config/config_db.ex +++ b/lib/pleroma/config/config_db.ex @@ -192,7 +192,6 @@ defmodule Pleroma.ConfigDB do } end - defp do_convert({:dispatch, [entity]}), do: %{"tuple" => [":dispatch", [inspect(entity)]]} # TODO: will become useless after removing hackney defp do_convert({:partial_chain, entity}), do: %{"tuple" => [":partial_chain", inspect(entity)]} @@ -229,14 +228,13 @@ defmodule Pleroma.ConfigDB do {:proxy_url, {do_transform_string(type), parse_host(host), port}} end - defp do_transform(%{"tuple" => [":dispatch", [entity]]}) do - {dispatch_settings, []} = do_eval(entity) - {:dispatch, [dispatch_settings]} - end - # TODO: will become useless after removing hackney defp do_transform(%{"tuple" => [":partial_chain", entity]}) do - {partial_chain, []} = do_eval(entity) + {partial_chain, []} = + entity + |> String.replace(~r/[^\w|^{:,[|^,|^[|^\]^}|^\/|^\.|^"]^\s/, "") + |> Code.eval_string() + {:partial_chain, partial_chain} end @@ -322,9 +320,4 @@ defmodule Pleroma.ConfigDB do Regex.match?(~r/^(Pleroma|Phoenix|Tesla|Quack)\./, string) or string in ["Oban", "Ueberauth", "ExSyslogger"] end - - defp do_eval(entity) do - cleaned_string = String.replace(entity, ~r/[^\w|^{:,[|^,|^[|^\]^}|^\/|^\.|^"]^\s/, "") - Code.eval_string(cleaned_string) - end end diff --git a/lib/pleroma/config/holder.ex b/lib/pleroma/config/holder.ex index c8badc52c..0d9cfef66 100644 --- a/lib/pleroma/config/holder.ex +++ b/lib/pleroma/config/holder.ex @@ -3,20 +3,29 @@ defmodule Pleroma.Config.Loader do if Code.ensure_loaded?(Config.Reader) do @spec load() :: map() def load do - config = Config.Reader.read!("config/config.exs") - env_config = Config.Reader.read!("config/#{Mix.env()}.exs") + config = load("config/config.exs") + env_config = load("config/#{Mix.env()}.exs") Config.Reader.merge(config, env_config) end + + @spec load(Path.t()) :: keyword() + def load(path), do: Config.Reader.read!(path) else # support for Elixir less than 1.9 @spec load() :: map() def load do - {config, _paths} = Mix.Config.eval!("config/config.exs") - {env_config, _paths} = Mix.Config.eval!("config/#{Mix.env()}.exs") + {config, _paths} = load("config/config.exs") + {env_config, _paths} = load("config/#{Mix.env()}.exs") Mix.Config.merge(config, env_config) end + + @spec load(Path.t()) :: keyword() + def load(path) do + {config, _paths} = Mix.Config.eval!(path) + config + end end end diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex index 828a297de..70b51cb4d 100644 --- a/lib/pleroma/config/transfer_task.ex +++ b/lib/pleroma/config/transfer_task.ex @@ -48,7 +48,20 @@ defmodule Pleroma.Config.TransferTask do end :ok = Application.put_env(group, key, merged_value) - group + + if group != :logger do + group + else + # change logger configuration in runtime, without restart + if Keyword.keyword?(merged_value) and + key not in [:compile_time_application, :backends, :compile_time_purge_matching] do + Logger.configure_backend(key, merged_value) + else + Logger.configure([{key, merged_value}]) + end + + nil + end end rescue e -> diff --git a/lib/pleroma/docs/json.ex b/lib/pleroma/docs/json.ex index f191b6013..6508a7bdb 100644 --- a/lib/pleroma/docs/json.ex +++ b/lib/pleroma/docs/json.ex @@ -15,7 +15,7 @@ defmodule Pleroma.Docs.JSON do end def compile do - with {config, _paths} <- Mix.Config.eval!("config/description.exs") do + with config <- Pleroma.Config.Loader.load("config/description.exs") do config[:pleroma][:config_description] |> Pleroma.Docs.Generator.convert_to_strings() |> Jason.encode!() |