summaryrefslogtreecommitdiff
path: root/lib/matrix_app_service_web/set_config_plug.ex
blob: a7fdf89f93414e4b682224897bab5503e7848005 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
defmodule MatrixAppServiceWeb.SetConfigPlug do
  @moduledoc """
  This plug allows to set compile time configuration as private conn parameters.
  """

  @behaviour Plug
  import Plug.Conn
  require Logger

  @doc false
  @impl Plug
  def init(opts) do
    opts
  end

  @doc false
  @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))
  end
end