summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrinpatch <rin@patch.cx>2021-04-16 09:50:26 +0000
committerrinpatch <rin@patch.cx>2021-04-16 09:50:26 +0000
commit0ababdc068f0fd7655b5f8440a5a8c9759a32fea (patch)
tree76fb01336d4292d9602b40723d4a07402a1fd3b4
parent152cb3074e855b0b20011eeb309d9ea5393821aa (diff)
parent681a42c359b4fbae74285363c670dff18aac5918 (diff)
Merge branch 'fix/2593-reading-exported-config-file' into 'develop'
Reading the file, instead of config keyword in ReleaseRuntimeProvider Closes #2593 See merge request pleroma/pleroma!3381
-rw-r--r--lib/pleroma/config/release_runtime_provider.ex18
-rw-r--r--mix.exs2
-rw-r--r--test/fixtures/config/temp.exported_from_db.secret.exs5
-rw-r--r--test/pleroma/config/release_runtime_provider_test.exs45
4 files changed, 61 insertions, 9 deletions
diff --git a/lib/pleroma/config/release_runtime_provider.ex b/lib/pleroma/config/release_runtime_provider.ex
index 8227195dc..e5e9d3dcd 100644
--- a/lib/pleroma/config/release_runtime_provider.ex
+++ b/lib/pleroma/config/release_runtime_provider.ex
@@ -1,6 +1,6 @@
defmodule Pleroma.Config.ReleaseRuntimeProvider do
@moduledoc """
- Imports `runtime.exs` and `{env}.exported_from_db.secret.exs` for elixir releases.
+ Imports runtime config and `{env}.exported_from_db.secret.exs` for releases.
"""
@behaviour Config.Provider
@@ -8,10 +8,11 @@ defmodule Pleroma.Config.ReleaseRuntimeProvider do
def init(opts), do: opts
@impl true
- def load(config, _opts) do
+ def load(config, opts) do
with_defaults = Config.Reader.merge(config, Pleroma.Config.Holder.release_defaults())
- config_path = System.get_env("PLEROMA_CONFIG_PATH") || "/etc/pleroma/config.exs"
+ config_path =
+ opts[:config_path] || System.get_env("PLEROMA_CONFIG_PATH") || "/etc/pleroma/config.exs"
with_runtime_config =
if File.exists?(config_path) do
@@ -24,7 +25,7 @@ defmodule Pleroma.Config.ReleaseRuntimeProvider do
warning = [
IO.ANSI.red(),
IO.ANSI.bright(),
- "!!! #{config_path} not found! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file",
+ "!!! Config path is not declared! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file",
IO.ANSI.reset()
]
@@ -33,13 +34,14 @@ defmodule Pleroma.Config.ReleaseRuntimeProvider do
end
exported_config_path =
- config_path
- |> Path.dirname()
- |> Path.join("prod.exported_from_db.secret.exs")
+ opts[:exported_config_path] ||
+ config_path
+ |> Path.dirname()
+ |> Path.join("#{Pleroma.Config.get(:env)}.exported_from_db.secret.exs")
with_exported =
if File.exists?(exported_config_path) do
- exported_config = Config.Reader.read!(with_runtime_config)
+ exported_config = Config.Reader.read!(exported_config_path)
Config.Reader.merge(with_runtime_config, exported_config)
else
with_runtime_config
diff --git a/mix.exs b/mix.exs
index ae74f50a3..fe5d9d963 100644
--- a/mix.exs
+++ b/mix.exs
@@ -38,7 +38,7 @@ defmodule Pleroma.Mixfile do
include_executables_for: [:unix],
applications: [ex_syslogger: :load, syslog: :load, eldap: :transient],
steps: [:assemble, &put_otp_version/1, &copy_files/1, &copy_nginx_config/1],
- config_providers: [{Pleroma.Config.ReleaseRuntimeProvider, nil}]
+ config_providers: [{Pleroma.Config.ReleaseRuntimeProvider, []}]
]
]
]
diff --git a/test/fixtures/config/temp.exported_from_db.secret.exs b/test/fixtures/config/temp.exported_from_db.secret.exs
new file mode 100644
index 000000000..64bee7f32
--- /dev/null
+++ b/test/fixtures/config/temp.exported_from_db.secret.exs
@@ -0,0 +1,5 @@
+use Mix.Config
+
+config :pleroma, exported_config_merged: true
+
+config :pleroma, :first_setting, key: "new value"
diff --git a/test/pleroma/config/release_runtime_provider_test.exs b/test/pleroma/config/release_runtime_provider_test.exs
new file mode 100644
index 000000000..6578d3268
--- /dev/null
+++ b/test/pleroma/config/release_runtime_provider_test.exs
@@ -0,0 +1,45 @@
+defmodule Pleroma.Config.ReleaseRuntimeProviderTest do
+ use ExUnit.Case, async: true
+
+ alias Pleroma.Config.ReleaseRuntimeProvider
+
+ describe "load/2" do
+ test "loads release defaults config and warns about non-existent runtime config" do
+ ExUnit.CaptureIO.capture_io(fn ->
+ merged = ReleaseRuntimeProvider.load([], [])
+ assert merged == Pleroma.Config.Holder.release_defaults()
+ end) =~
+ "!!! Config path is not declared! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file"
+ end
+
+ test "merged runtime config" do
+ merged =
+ ReleaseRuntimeProvider.load([], config_path: "test/fixtures/config/temp.secret.exs")
+
+ assert merged[:pleroma][:first_setting] == [key: "value", key2: [Pleroma.Repo]]
+ assert merged[:pleroma][:second_setting] == [key: "value2", key2: ["Activity"]]
+ end
+
+ test "merged exported config" do
+ ExUnit.CaptureIO.capture_io(fn ->
+ merged =
+ ReleaseRuntimeProvider.load([],
+ exported_config_path: "test/fixtures/config/temp.exported_from_db.secret.exs"
+ )
+
+ assert merged[:pleroma][:exported_config_merged]
+ end) =~
+ "!!! Config path is not declared! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file"
+ end
+
+ test "runtime config is merged with exported config" do
+ merged =
+ ReleaseRuntimeProvider.load([],
+ config_path: "test/fixtures/config/temp.secret.exs",
+ exported_config_path: "test/fixtures/config/temp.exported_from_db.secret.exs"
+ )
+
+ assert merged[:pleroma][:first_setting] == [key2: [Pleroma.Repo], key: "new value"]
+ end
+ end
+end