extend reject MRF to check if originating instance is blocked
[akkoma] / lib / pleroma / config / release_runtime_provider.ex
1 defmodule Pleroma.Config.ReleaseRuntimeProvider do
2 @moduledoc """
3 Imports runtime config and `{env}.exported_from_db.secret.exs` for releases.
4 """
5 @behaviour Config.Provider
6
7 @impl true
8 def init(opts), do: opts
9
10 @impl true
11 def load(config, opts) do
12 with_defaults = Config.Reader.merge(config, Pleroma.Config.Holder.release_defaults())
13
14 config_path =
15 cond do
16 opts[:config_path] -> opts[:config_path]
17 System.get_env("AKKOMA_CONFIG_PATH") -> System.get_env("AKKOMA_CONFIG_PATH")
18 System.get_env("PLEROMA_CONFIG_PATH") -> System.get_env("PLEROMA_CONFIG_PATH")
19 File.exists?("/etc/pleroma/config.exs") -> "/etc/pleroma/config.exs"
20 true -> "/etc/akkoma/config.exs"
21 end
22
23 with_runtime_config =
24 if File.exists?(config_path) do
25 runtime_config = Config.Reader.read!(config_path)
26
27 with_defaults
28 |> Config.Reader.merge(pleroma: [config_path: config_path])
29 |> Config.Reader.merge(runtime_config)
30 else
31 warning = [
32 IO.ANSI.red(),
33 IO.ANSI.bright(),
34 "!!! Config path is not declared! Please ensure it exists and that AKKOMA_CONFIG_PATH and/or PLEROMA_CONFIG_PATH is unset or points to an existing file",
35 IO.ANSI.reset()
36 ]
37
38 IO.puts(warning)
39 with_defaults
40 end
41
42 exported_config_path =
43 opts[:exported_config_path] ||
44 config_path
45 |> Path.dirname()
46 |> Path.join("#{Pleroma.Config.get(:env)}.exported_from_db.secret.exs")
47
48 with_exported =
49 if File.exists?(exported_config_path) do
50 exported_config = Config.Reader.read!(exported_config_path)
51 Config.Reader.merge(with_runtime_config, exported_config)
52 else
53 with_runtime_config
54 end
55
56 with_exported
57 end
58 end