summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre de Lacroix <pierre@pdelacroix.com>2021-08-27 16:23:22 +0200
committerPierre de Lacroix <pierre@pdelacroix.com>2021-08-27 16:23:22 +0200
commitf7fc5d48505bd41ddf41197c1d22213232b77892 (patch)
tree49a144e2325b93e5939bca0c5d79901887aecdc1
parentremove production config (diff)
allow fetching config from env even when passed in parameter
-rw-r--r--lib/matrix_app_service_web/auth_plug.ex4
-rw-r--r--lib/matrix_app_service_web/set_config_plug.ex22
2 files changed, 19 insertions, 7 deletions
diff --git a/lib/matrix_app_service_web/auth_plug.ex b/lib/matrix_app_service_web/auth_plug.ex
index 4a0b386..b3965ad 100644
--- a/lib/matrix_app_service_web/auth_plug.ex
+++ b/lib/matrix_app_service_web/auth_plug.ex
@@ -27,6 +27,10 @@ defmodule MatrixAppServiceWeb.AuthPlug do
verify_access_token(conn, homeserver_token.())
end
+ def call(%Plug.Conn{params: %{"access_token" => _access_token}} = conn, :config) do
+ verify_access_token(conn, Application.fetch_env!(:matrix_app_service, :app_service)[:homeserver_token])
+ end
+
def call(conn, _opts) do
Logger.warn("No homeserver token provided")
diff --git a/lib/matrix_app_service_web/set_config_plug.ex b/lib/matrix_app_service_web/set_config_plug.ex
index a7fdf89..b8dd9fa 100644
--- a/lib/matrix_app_service_web/set_config_plug.ex
+++ b/lib/matrix_app_service_web/set_config_plug.ex
@@ -17,12 +17,20 @@ defmodule MatrixAppServiceWeb.SetConfigPlug do
@impl Plug
def call(conn, opts) do
conn
- |> put_private(:transaction_adapter, Keyword.fetch!(opts, :transaction_adapter))
- |> put_private(:room_adapter, Keyword.fetch!(opts, :room_adapter))
- |> put_private(:user_adapter, Keyword.fetch!(opts, :user_adapter))
- |> put_private(:homeserver_token, Keyword.fetch!(opts, :homeserver_token))
- |> put_private(:access_token, Keyword.fetch!(opts, :access_token))
- |> put_private(:base_url, Keyword.fetch!(opts, :base_url))
- |> put_private(:path, Keyword.fetch!(opts, :path))
+ |> put_config(:transaction_adapter, Keyword.fetch!(opts, :transaction_adapter))
+ |> put_config(:room_adapter, Keyword.fetch!(opts, :room_adapter))
+ |> put_config(:user_adapter, Keyword.fetch!(opts, :user_adapter))
+ |> put_config(:homeserver_token, Keyword.fetch!(opts, :homeserver_token))
+ |> put_config(:access_token, Keyword.fetch!(opts, :access_token))
+ |> put_config(:base_url, Keyword.fetch!(opts, :base_url))
+ |> put_config(:path, Keyword.fetch!(opts, :path))
+ end
+
+ defp put_config(conn, key, :config) do
+ value = Application.fetch_env!(:matrix_app_service, :app_service)[:key]
+ put_private(conn, key, value)
+ end
+ defp put_config(conn, key, value) do
+ put_private(conn, key, value)
end
end