tesla adapter can't be changed in adminFE

This commit is contained in:
Alexander Strizhakov 2020-03-10 15:31:44 +03:00
parent d9f8941dac
commit 426f5ee48a
No known key found for this signature in database
GPG key ID: 022896A53AEF1381
2 changed files with 31 additions and 48 deletions

View file

@ -20,8 +20,7 @@ defmodule Pleroma.Config.TransferTask do
{:pleroma, :markup},
{:pleroma, :streamer},
{:pleroma, :pools},
{:pleroma, :connections_pool},
{:tesla, :adapter}
{:pleroma, :connections_pool}
]
@reboot_time_subkeys [
@ -35,8 +34,6 @@ defmodule Pleroma.Config.TransferTask do
{:pleroma, :gopher, [:enabled]}
]
@reject [nil, :prometheus]
def start_link(_) do
load_and_update_env()
if Pleroma.Config.get(:env) == :test, do: Ecto.Adapters.SQL.Sandbox.checkin(Repo)
@ -45,35 +42,30 @@ def start_link(_) do
@spec load_and_update_env([ConfigDB.t()]) :: :ok | false
def load_and_update_env(deleted \\ [], restart_pleroma? \\ true) do
with {:configurable, true} <-
{:configurable, Pleroma.Config.get(:configurable_from_database)},
true <- Ecto.Adapters.SQL.table_exists?(Repo, "config"),
started_applications <- Application.started_applications() do
with {_, true} <- {:configurable, Pleroma.Config.get(:configurable_from_database)} do
# We need to restart applications for loaded settings take effect
in_db = Repo.all(ConfigDB)
with_deleted = in_db ++ deleted
reject_for_restart = if restart_pleroma?, do: @reject, else: [:pleroma | @reject]
# TODO: some problem with prometheus after restart!
reject = [nil, :prometheus]
applications =
with_deleted
|> Enum.map(&merge_and_update(&1))
|> Enum.uniq()
# TODO: some problem with prometheus after restart!
|> Enum.reject(&(&1 in reject_for_restart))
# to be ensured that pleroma will be restarted last
applications =
if :pleroma in applications do
List.delete(applications, :pleroma) ++ [:pleroma]
reject_for_restart =
if restart_pleroma? do
reject
else
Restarter.Pleroma.rebooted()
applications
[:pleroma | reject]
end
Enum.each(applications, &restart(started_applications, &1, Pleroma.Config.get(:env)))
started_applications = Application.started_applications()
with_deleted
|> Enum.map(&merge_and_update(&1))
|> Enum.uniq()
|> Enum.reject(&(&1 in reject_for_restart))
|> maybe_set_pleroma_last()
|> Enum.each(&restart(started_applications, &1, Pleroma.Config.get(:env)))
:ok
else
@ -81,6 +73,18 @@ def load_and_update_env(deleted \\ [], restart_pleroma? \\ true) do
end
end
defp maybe_set_pleroma_last(apps) do
# to be ensured that pleroma will be restarted last
if :pleroma in apps do
apps
|> List.delete(:pleroma)
|> List.insert_at(-1, :pleroma)
else
Restarter.Pleroma.rebooted()
apps
end
end
defp group_for_restart(:logger, key, _, merged_value) do
# change logger configuration in runtime, without restart
if Keyword.keyword?(merged_value) and
@ -93,14 +97,10 @@ defp group_for_restart(:logger, key, _, merged_value) do
nil
end
defp group_for_restart(:tesla, _, _, _), do: :pleroma
defp group_for_restart(group, _, _, _) when group != :pleroma, do: group
defp group_for_restart(group, key, value, _) do
if pleroma_need_restart?(group, key, value) do
group
end
if pleroma_need_restart?(group, key, value), do: group
end
defp merge_and_update(setting) do

View file

@ -2513,8 +2513,7 @@ test "saving full setting if value is not keyword", %{conn: conn} do
"value" => "Tesla.Adapter.Httpc",
"db" => [":adapter"]
}
],
"need_reboot" => true
]
}
end
@ -2586,9 +2585,6 @@ test "update config setting & delete with fallback to default value", %{
end
test "common config example", %{conn: conn} do
adapter = Application.get_env(:tesla, :adapter)
on_exit(fn -> Application.put_env(:tesla, :adapter, adapter) end)
conn =
post(conn, "/api/pleroma/admin/config", %{
configs: [
@ -2607,16 +2603,10 @@ test "common config example", %{conn: conn} do
%{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]},
%{"tuple" => [":name", "Pleroma"]}
]
},
%{
"group" => ":tesla",
"key" => ":adapter",
"value" => "Tesla.Adapter.Httpc"
}
]
})
assert Application.get_env(:tesla, :adapter) == Tesla.Adapter.Httpc
assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
assert json_response(conn, 200) == %{
@ -2648,15 +2638,8 @@ test "common config example", %{conn: conn} do
":regex4",
":name"
]
},
%{
"group" => ":tesla",
"key" => ":adapter",
"value" => "Tesla.Adapter.Httpc",
"db" => [":adapter"]
}
],
"need_reboot" => true
]
}
end