Some checks failed
Build and Publish / build-release (push) Failing after 5s
23 lines
579 B
Elixir
23 lines
579 B
Elixir
defmodule ProviderServiceWeb.Plugs.ExtractOrganizationId do
|
|
@moduledoc """
|
|
Extract `X-Organization-Id` request header.
|
|
|
|
Stores the organization identifier in conn.private[__MODULE__] for downstream authorization checks.
|
|
"""
|
|
|
|
@behaviour Plug
|
|
|
|
import Plug.Conn, only: [get_req_header: 2, put_private: 3]
|
|
|
|
@impl Plug
|
|
def init(_opts), do: %{}
|
|
|
|
@impl Plug
|
|
def call(conn, _opts) do
|
|
case get_req_header(conn, "x-organization-id") do
|
|
[org_id | _rest] -> put_private(conn, __MODULE__, org_id)
|
|
[] -> put_private(conn, __MODULE__, nil)
|
|
end
|
|
end
|
|
end
|