MRF: add describe() for gathering and describing the MRF configuration
authorAriadne Conill <ariadne@dereferenced.org>
Tue, 13 Aug 2019 21:26:24 +0000 (21:26 +0000)
committerAriadne Conill <ariadne@dereferenced.org>
Tue, 13 Aug 2019 21:26:24 +0000 (21:26 +0000)
lib/pleroma/web/activity_pub/mrf.ex

index caa2a3231a5b5767b9a7dbd8eae05a426a4cf830..d43a8760b9246afbd6ce2de62c9a4136e80b0249 100644 (file)
@@ -35,4 +35,20 @@ defmodule Pleroma.Web.ActivityPub.MRF do
   def subdomain_match?(domains, host) do
     Enum.any?(domains, fn domain -> Regex.match?(domain, host) end)
   end
+
+  @callback describe() :: {:ok | :error, Map.t()}
+
+  def describe(policies) do
+    policies
+    |> Enum.reduce({:ok, %{}}, fn
+      policy, {:ok, data} ->
+        {:ok, policy_data} = policy.describe()
+        {:ok, Map.merge(data, policy_data)}
+
+      _, error ->
+        error
+    end)
+  end
+
+  def describe(), do: get_policies() |> describe()
 end