dynamic_configuration renaming
and moving it from instance settings
This commit is contained in:
parent
958d0452e4
commit
7d128ca208
13 changed files with 59 additions and 53 deletions
|
@ -269,7 +269,6 @@ config :pleroma, :instance,
|
|||
remote_post_retention_days: 90,
|
||||
skip_thread_containment: true,
|
||||
limit_to_local_content: :unauthenticated,
|
||||
dynamic_configuration: false,
|
||||
user_bio_length: 5000,
|
||||
user_name_length: 100,
|
||||
max_account_fields: 10,
|
||||
|
@ -623,6 +622,8 @@ config :pleroma, :web_cache_ttl,
|
|||
|
||||
config :pleroma, :modules, runtime_dir: "instance/modules"
|
||||
|
||||
config :pleroma, configurable_from_database: false
|
||||
|
||||
config :swarm, node_blacklist: [~r/myhtml_.*$/]
|
||||
# Import environment specific config. This must remain at the bottom
|
||||
# of this file so it overrides the configuration defined above.
|
||||
|
|
|
@ -867,12 +867,6 @@ config :pleroma, :config_description, [
|
|||
false
|
||||
]
|
||||
},
|
||||
%{
|
||||
key: :dynamic_configuration,
|
||||
type: :boolean,
|
||||
description:
|
||||
"Allow transferring configuration to DB with the subsequent customization from Admin api. Defaults to `false`"
|
||||
},
|
||||
%{
|
||||
key: :max_account_fields,
|
||||
type: :integer,
|
||||
|
@ -3111,5 +3105,18 @@ config :pleroma, :config_description, [
|
|||
description: "A path to custom Elixir modules (such as MRF policies)."
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
group: :pleroma,
|
||||
type: :group,
|
||||
description: "Allow instance configuration from database.",
|
||||
children: [
|
||||
%{
|
||||
key: :configurable_from_database,
|
||||
type: :boolean,
|
||||
description:
|
||||
"Allow transferring configuration to DB with the subsequent customization from Admin api. Defaults to `false`"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -684,7 +684,7 @@ Copies all settings from database to `config/{env}.exported_from_db.secret.exs`
|
|||
|
||||
### Get saved config settings
|
||||
|
||||
**Only works when `:dynamic_configuration` is `true`.**
|
||||
**Only works when configuration from database is enabled.**
|
||||
|
||||
- Params: none
|
||||
- Response:
|
||||
|
@ -708,7 +708,7 @@ Copies all settings from database to `config/{env}.exported_from_db.secret.exs`
|
|||
|
||||
### Update config settings
|
||||
|
||||
**Only works when `:dynamic_configuration` is `true`.**
|
||||
**Only works when configuration from database is enabled.**
|
||||
|
||||
Some modifications are necessary to save the config settings correctly:
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
# Configuring instance
|
||||
You can configure your instance from admin interface. You need account with admin rights and little change in config file, which will allow settings dynamic configuration from database.
|
||||
You can configure your instance from admin interface. You need account with admin rights and little change in config file, which will allow settings configuration from database.
|
||||
|
||||
```elixir
|
||||
config :pleroma, :instance,
|
||||
dynamic_configuration: true
|
||||
config :pleroma, configurable_from_database: true
|
||||
```
|
||||
|
||||
## How it works
|
||||
|
@ -48,10 +47,9 @@ rm -rf config/prod.exported_from_db.exs
|
|||
```
|
||||
*If you don't want to backup settings, you can skip step with `cp` command.*
|
||||
|
||||
3. Set dynamic configuration to `false`.
|
||||
3. Set configurable_from_database to `false`.
|
||||
```elixir
|
||||
config :pleroma, :instance,
|
||||
dynamic_configuration: false
|
||||
config :pleroma, configurable_from_database: false
|
||||
```
|
||||
4. Restart pleroma instance
|
||||
```bash
|
||||
|
|
|
@ -70,11 +70,6 @@ You shouldn't edit the base config directly to avoid breakages and merge conflic
|
|||
* `account_field_value_length`: An account field value maximum length (default: `2048`).
|
||||
* `external_user_synchronization`: Enabling following/followers counters synchronization for external users.
|
||||
|
||||
!!! danger
|
||||
This is a Work In Progress, not usable just yet
|
||||
|
||||
* `dynamic_configuration`: Allow transferring configuration to DB with the subsequent customization from Admin api.
|
||||
|
||||
## Federation
|
||||
### MRF policies
|
||||
|
||||
|
@ -841,3 +836,7 @@ config :auto_linker,
|
|||
## Custom Runtime Modules (`:modules`)
|
||||
|
||||
* `runtime_dir`: A path to custom Elixir modules (such as MRF policies).
|
||||
|
||||
|
||||
## :configurable_from_database
|
||||
Enable/disable configuration from database.
|
||||
|
|
|
@ -30,7 +30,7 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||
def run(["migrate_to_db"]) do
|
||||
start_pleroma()
|
||||
|
||||
if Pleroma.Config.get([:instance, :dynamic_configuration]) do
|
||||
if Pleroma.Config.get([:configurable_from_database]) do
|
||||
Enum.each(@groups, &load_and_create(&1))
|
||||
else
|
||||
Mix.shell().info(
|
||||
|
@ -48,7 +48,8 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||
aliases: [d: :delete_from_db]
|
||||
)
|
||||
|
||||
with {:active?, true} <- {:active?, Pleroma.Config.get([:instance, :dynamic_configuration])},
|
||||
with {:active?, true} <-
|
||||
{:active?, Pleroma.Config.get([:configurable_from_database])},
|
||||
env_path when is_binary(env_path) <- opts[:env],
|
||||
config_path <- "config/#{env_path}.exported_from_db.secret.exs",
|
||||
{:ok, file} <- File.open(config_path, [:write, :utf8]) do
|
||||
|
|
|
@ -17,7 +17,7 @@ defmodule Pleroma.Config.TransferTask do
|
|||
end
|
||||
|
||||
def load_and_update_env do
|
||||
with true <- Pleroma.Config.get([:instance, :dynamic_configuration]),
|
||||
with true <- Pleroma.Config.get([:configurable_from_database]),
|
||||
true <- Ecto.Adapters.SQL.table_exists?(Repo, "config"),
|
||||
started_applications <- Application.started_applications() do
|
||||
# We need to restart applications for loaded settings take effect
|
||||
|
|
|
@ -785,7 +785,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
end
|
||||
|
||||
def migrate_from_db(conn, _params) do
|
||||
with :ok <- check_dynamic_configuration(conn) do
|
||||
with :ok <- configurable_from_database(conn) do
|
||||
Mix.Tasks.Pleroma.Config.run([
|
||||
"migrate_from_db",
|
||||
"--env",
|
||||
|
@ -798,7 +798,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
end
|
||||
|
||||
def config_show(conn, _params) do
|
||||
with :ok <- check_dynamic_configuration(conn) do
|
||||
with :ok <- configurable_from_database(conn) do
|
||||
configs = Pleroma.Repo.all(Config)
|
||||
|
||||
if configs == [] do
|
||||
|
@ -812,7 +812,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
end
|
||||
|
||||
def config_update(conn, %{"configs" => configs}) do
|
||||
with :ok <- check_dynamic_configuration(conn) do
|
||||
with :ok <- configurable_from_database(conn) do
|
||||
updated =
|
||||
Enum.map(configs, fn
|
||||
%{"group" => group, "key" => key, "delete" => true} = params ->
|
||||
|
@ -843,8 +843,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
end
|
||||
end
|
||||
|
||||
defp check_dynamic_configuration(conn) do
|
||||
if Pleroma.Config.get([:instance, :dynamic_configuration]) do
|
||||
defp configurable_from_database(conn) do
|
||||
if Pleroma.Config.get([:configurable_from_database]) do
|
||||
:ok
|
||||
else
|
||||
errors(conn, {:error, "To use this endpoint you need to enable dynamic configuration."})
|
||||
|
|
|
@ -20,8 +20,7 @@ config :pleroma, :instance,
|
|||
email: "<%= email %>",
|
||||
notify_email: "<%= notify_email %>",
|
||||
limit: 5000,
|
||||
registrations_open: true,
|
||||
dynamic_configuration: <%= db_configurable? %>
|
||||
registrations_open: true
|
||||
|
||||
config :pleroma, :media_proxy,
|
||||
enabled: false,
|
||||
|
@ -70,3 +69,5 @@ config :pleroma, Pleroma.Uploaders.Local, uploads: "<%= uploads_dir %>"
|
|||
# host: "s3.wasabisys.com"
|
||||
|
||||
config :joken, default_signer: "<%= jwt_secret %>"
|
||||
|
||||
config :pleroma, configurable_from_database: <%= db_configurable? %>
|
||||
|
|
|
@ -7,8 +7,8 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
|
||||
alias Pleroma.Web.AdminAPI.Config
|
||||
|
||||
clear_config([:instance, :dynamic_configuration]) do
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||
clear_config([:configurable_from_database]) do
|
||||
Pleroma.Config.put([:configurable_from_database], true)
|
||||
end
|
||||
|
||||
test "transfer config values from db to env" do
|
||||
|
|
|
@ -19,8 +19,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config_all([:instance, :dynamic_configuration]) do
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||
clear_config_all([:configurable_from_database]) do
|
||||
Pleroma.Config.put([:configurable_from_database], true)
|
||||
end
|
||||
|
||||
test "settings are migrated to db" do
|
||||
|
@ -127,7 +127,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
remote_post_retention_days: 90,
|
||||
skip_thread_containment: true,
|
||||
limit_to_local_content: :unauthenticated,
|
||||
dynamic_configuration: false,
|
||||
user_bio_length: 5000,
|
||||
user_name_length: 100,
|
||||
max_account_fields: 10,
|
||||
|
@ -157,7 +156,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
{:ok, file} = File.read(temp_file)
|
||||
|
||||
assert file ==
|
||||
"use Mix.Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n no_attachment_links: true,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n dynamic_configuration: false,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
|
||||
"use Mix.Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n no_attachment_links: true,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -78,7 +78,7 @@ defmodule Pleroma.InstanceTest do
|
|||
assert generated_config =~ "database: \"dbname\""
|
||||
assert generated_config =~ "username: \"dbuser\""
|
||||
assert generated_config =~ "password: \"dbpass\""
|
||||
assert generated_config =~ "dynamic_configuration: true"
|
||||
assert generated_config =~ "configurable_from_database: true"
|
||||
assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]"
|
||||
assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
|
||||
end
|
||||
|
|
|
@ -584,7 +584,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
assert json_response(conn, :no_content)
|
||||
|
||||
token_record = List.last(Pleroma.Repo.all(Pleroma.UserInviteToken))
|
||||
token_record = List.last(Repo.all(Pleroma.UserInviteToken))
|
||||
assert token_record
|
||||
refute token_record.used
|
||||
|
||||
|
@ -1929,8 +1929,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/config" do
|
||||
clear_config([:instance, :dynamic_configuration]) do
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||
clear_config([:configurable_from_database]) do
|
||||
Pleroma.Config.put([:configurable_from_database], true)
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
|
@ -1940,9 +1940,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "when dynamic configuration is off", %{conn: conn} do
|
||||
initial = Pleroma.Config.get([:instance, :dynamic_configuration])
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], false)
|
||||
on_exit(fn -> Pleroma.Config.put([:instance, :dynamic_configuration], initial) end)
|
||||
initial = Pleroma.Config.get([:configurable_from_database])
|
||||
Pleroma.Config.put([:configurable_from_database], false)
|
||||
on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end)
|
||||
conn = get(conn, "/api/pleroma/admin/config")
|
||||
|
||||
assert json_response(conn, 400) ==
|
||||
|
@ -2016,8 +2016,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
%{conn: assign(conn, :user, admin)}
|
||||
end
|
||||
|
||||
clear_config([:instance, :dynamic_configuration]) do
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||
clear_config([:configurable_from_database]) do
|
||||
Pleroma.Config.put([:configurable_from_database], true)
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
|
@ -2908,8 +2908,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
%{conn: assign(conn, :user, admin)}
|
||||
end
|
||||
|
||||
clear_config([:instance, :dynamic_configuration]) do
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], true)
|
||||
clear_config([:configurable_from_database]) do
|
||||
Pleroma.Config.put([:configurable_from_database], true)
|
||||
end
|
||||
|
||||
clear_config([:feed, :post_title]) do
|
||||
|
@ -2918,20 +2918,20 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
test "transfer settings to DB and to file", %{conn: conn} do
|
||||
on_exit(fn -> :ok = File.rm("config/test.exported_from_db.secret.exs") end)
|
||||
assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
|
||||
assert Repo.all(Pleroma.Web.AdminAPI.Config) == []
|
||||
Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
|
||||
assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) > 0
|
||||
assert Repo.aggregate(Pleroma.Web.AdminAPI.Config, :count, :id) > 0
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/config/migrate_from_db")
|
||||
|
||||
assert json_response(conn, 200) == %{}
|
||||
assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
|
||||
assert Repo.all(Pleroma.Web.AdminAPI.Config) == []
|
||||
end
|
||||
|
||||
test "returns error if dynamic configuration is off", %{conn: conn} do
|
||||
initial = Pleroma.Config.get([:instance, :dynamic_configuration])
|
||||
on_exit(fn -> Pleroma.Config.put([:instance, :dynamic_configuration], initial) end)
|
||||
Pleroma.Config.put([:instance, :dynamic_configuration], false)
|
||||
initial = Pleroma.Config.get([:configurable_from_database])
|
||||
on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end)
|
||||
Pleroma.Config.put([:configurable_from_database], false)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/config/migrate_from_db")
|
||||
|
||||
|
|
Loading…
Reference in a new issue