Add warning for disallowed keys
This commit is contained in:
parent
7e1732c654
commit
2500cca3ce
3 changed files with 45 additions and 2 deletions
|
@ -85,14 +85,20 @@ defmodule Pleroma.Config.ConfigurableFromDatabase do
|
|||
|
||||
def enabled, do: Config.get(:configurable_from_database)
|
||||
|
||||
# the whitelist check can be called from either the loader or the
|
||||
# doc generator, which is spitting out strings
|
||||
defp maybe_stringified_atom_equal(a, b) do
|
||||
a == inspect(b) || a == b
|
||||
end
|
||||
|
||||
def whitelisted_config?(group, key) do
|
||||
allowed_groups()
|
||||
|> Enum.any?(fn
|
||||
{whitelisted_group} ->
|
||||
group == inspect(whitelisted_group)
|
||||
maybe_stringified_atom_equal(group, whitelisted_group)
|
||||
|
||||
{whitelisted_group, whitelisted_key} ->
|
||||
group == inspect(whitelisted_group) && key == inspect(whitelisted_key)
|
||||
maybe_stringified_atom_equal(group, whitelisted_group) && maybe_stringified_atom_equal(key, whitelisted_key)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Config.TransferTask do
|
|||
alias Pleroma.Config
|
||||
alias Pleroma.ConfigDB
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Config.ConfigurableFromDatabase
|
||||
|
||||
require Logger
|
||||
|
||||
|
@ -91,6 +92,17 @@ defmodule Pleroma.Config.TransferTask do
|
|||
defp invalid_key_or_group(_), do: false
|
||||
|
||||
defp merge_with_default(%{group: group, key: key, value: value} = setting) do
|
||||
if !ConfigurableFromDatabase.whitelisted_config?(setting) do
|
||||
Logger.warning(~s[
|
||||
config #{inspect(group)}, #{inspect(key)} is set in the database,
|
||||
but it is not explicitly allowed to be there. Consider removing it
|
||||
with
|
||||
MIX: mix pleroma.config delete #{group} #{key}
|
||||
OTP: ./bin/pleroma_ctl config delete #{group} #{key}
|
||||
and setting it in your .exs file instead
|
||||
])
|
||||
end
|
||||
|
||||
default =
|
||||
if group == :pleroma do
|
||||
Config.get([key], Config.Holder.default_config(group, key))
|
||||
|
|
|
@ -93,6 +93,31 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
assert assets_env[:mascots] == [a: 1, b: 2]
|
||||
end
|
||||
|
||||
test "transfer config values that are not explicitly whitelisted" do
|
||||
insert(:config, key: :whoops, value: [not_allowed: true])
|
||||
|
||||
log =
|
||||
capture_log(fn ->
|
||||
TransferTask.start_link([])
|
||||
end)
|
||||
|
||||
assert log =~ "config :pleroma, :whoops is set in the database"
|
||||
assert log =~ "Consider removing it"
|
||||
assert log =~ "mix pleroma.config delete pleroma whoops"
|
||||
end
|
||||
|
||||
test "transferring whitelisted values should not warn" do
|
||||
insert(:config, key: :emoji, value: [allowed: true])
|
||||
insert(:config, key: Pleroma.Workers.PurgeExpiredActivity, value: [allowed: true])
|
||||
|
||||
log =
|
||||
capture_log(fn ->
|
||||
TransferTask.start_link([])
|
||||
end)
|
||||
|
||||
refute log =~ "Consider removing it"
|
||||
end
|
||||
|
||||
describe "pleroma restart" do
|
||||
setup do
|
||||
on_exit(fn ->
|
||||
|
|
Loading…
Reference in a new issue