From f73c93e4bee4c4653dae2303fae600153f02f8cd Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Sun, 24 Jul 2022 17:27:03 +0100 Subject: [PATCH 1/2] extend custom runtime system also expose some user stuff for custom authenticators --- lib/pleroma/utils.ex | 15 ++++++++++++++- test/fixtures/runtime_modules/first.ex | 2 ++ test/fixtures/runtime_modules/nope.exs | 1 + test/fixtures/runtime_modules/subdir/second.ex | 2 ++ test/pleroma/utils_test.exs | 7 +++++++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/runtime_modules/first.ex create mode 100644 test/fixtures/runtime_modules/nope.exs create mode 100644 test/fixtures/runtime_modules/subdir/second.ex diff --git a/lib/pleroma/utils.ex b/lib/pleroma/utils.ex index a446d3ae6..bd9939c9f 100644 --- a/lib/pleroma/utils.ex +++ b/lib/pleroma/utils.ex @@ -14,10 +14,23 @@ defmodule Pleroma.Utils do @repo_timeout Pleroma.Config.get([Pleroma.Repo, :timeout], 15_000) def compile_dir(dir) when is_binary(dir) do + dir + |> elixir_files() + |> Kernel.ParallelCompiler.compile() + end + + defp elixir_files(dir) when is_binary(dir) do dir |> File.ls!() |> Enum.map(&Path.join(dir, &1)) - |> Kernel.ParallelCompiler.compile() + |> Enum.flat_map(fn path -> + if File.dir?(path) do + elixir_files(path) + else + [path] + end + end) + |> Enum.filter(fn path -> String.ends_with?(path, ".ex") end) end @doc """ diff --git a/test/fixtures/runtime_modules/first.ex b/test/fixtures/runtime_modules/first.ex new file mode 100644 index 000000000..2b663a1b0 --- /dev/null +++ b/test/fixtures/runtime_modules/first.ex @@ -0,0 +1,2 @@ +defmodule DynamicModule.First do +end diff --git a/test/fixtures/runtime_modules/nope.exs b/test/fixtures/runtime_modules/nope.exs new file mode 100644 index 000000000..8fe676af6 --- /dev/null +++ b/test/fixtures/runtime_modules/nope.exs @@ -0,0 +1 @@ +def thisisnotloaded diff --git a/test/fixtures/runtime_modules/subdir/second.ex b/test/fixtures/runtime_modules/subdir/second.ex new file mode 100644 index 000000000..22dc046c6 --- /dev/null +++ b/test/fixtures/runtime_modules/subdir/second.ex @@ -0,0 +1,2 @@ +defmodule DynamicModule.Second do +end diff --git a/test/pleroma/utils_test.exs b/test/pleroma/utils_test.exs index c593a9490..e21573679 100644 --- a/test/pleroma/utils_test.exs +++ b/test/pleroma/utils_test.exs @@ -12,4 +12,11 @@ test "returns unique temporary directory" do File.rm_rf(path) end end + + describe "compile_dir/1" do + test "recursively compiles directories" do + {:ok, [DynamicModule.First, DynamicModule.Second], []} = + Pleroma.Utils.compile_dir("test/fixtures/runtime_modules") + end + end end -- 2.43.0 From 67b235f20c28eb8f8f9b7456a9a50152b9c7f550 Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Sun, 24 Jul 2022 17:42:22 +0100 Subject: [PATCH 2/2] document runtime modules --- CHANGELOG.md | 5 ++++- docs/docs/configuration/cheatsheet.md | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22644b03c..d6dd4dd4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added +- extended runtime module support, see config cheatsheet + ### Fixed - Updated mastoFE path, for the newer version @@ -18,7 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `/api/v1/notifications/dismiss` - `/api/v1/search` - `/api/v1/statuses/{id}/card` -- LDAP authenticator +- LDAP authenticator (use the akkoma-contrib-authenticator-ldap runtime module) - Chats, they were half-baked. Just use PMs. - Prometheus, it causes massive slowdown diff --git a/docs/docs/configuration/cheatsheet.md b/docs/docs/configuration/cheatsheet.md index fdbfb1a3e..7b0934fcf 100644 --- a/docs/docs/configuration/cheatsheet.md +++ b/docs/docs/configuration/cheatsheet.md @@ -1012,7 +1012,22 @@ config :pleroma, Pleroma.Formatter, ## Custom Runtime Modules (`:modules`) -* `runtime_dir`: A path to custom Elixir modules (such as MRF policies). +* `runtime_dir`: A path to custom Elixir modules, such as MRF policies or + custom authenticators. These modules will be loaded on boot, and can be + contained in subdirectories. It is advised to use version-controlled + subdirectories to make management of them a bit easier. Note that only + files with the extension `.ex` will be loaded. + +```elixir +config :pleroma, :modules, runtime_dir: "instance/modules" +``` + +### Adding a module + +```bash +cd instance/modules/ +git clone +``` ## :configurable_from_database -- 2.43.0