From 8138fd1c76937c915b9cdeac8f2bc16337b995f7 Mon Sep 17 00:00:00 2001 From: Aad Versteden Date: Mon, 12 Apr 2021 12:54:31 +0200 Subject: [PATCH] Blind development of mu-call-scope-id This is a PoC showing how the mu-call-scope-id could work. It has an extra header available to you and it's positioned in the body too. --- lib/delta/delta.ex | 6 ++++-- lib/delta/message.ex | 9 +++++++-- lib/delta/messenger.ex | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/delta/delta.ex b/lib/delta/delta.ex index ef37f83..a502d14 100644 --- a/lib/delta/delta.ex +++ b/lib/delta/delta.ex @@ -43,10 +43,12 @@ defmodule Delta do |> Kernel.++(Plug.Conn.get_req_header(conn, "mu-call-id")) |> Poison.encode!() + mu_call_scope_id = Plug.Conn.get_req_header(conn, "mu-call-scope-id") + delta - |> Delta.Message.construct(authorization_groups, origin) + |> Delta.Message.construct(authorization_groups, origin, mu_call_scope_id) |> Logging.EnvLog.inspect(:log_delta_messages, label: "Constructed body for clients") - |> Delta.Messenger.inform_clients(mu_call_id_trail: mu_call_id_trail) + |> Delta.Messenger.inform_clients(mu_call_id_trail: mu_call_id_trail, mu_call_scope_id: mu_call_scope_id) delta end diff --git a/lib/delta/message.ex b/lib/delta/message.ex index a453b61..8f57c2d 100644 --- a/lib/delta/message.ex +++ b/lib/delta/message.ex @@ -17,9 +17,9 @@ defmodule Delta.Message do Constructs a new message which can be sent to the clients based on a quad delta. """ - @spec construct(Delta.delta(), AccessGroupSupport.decoded_json_access_groups(), String.t()) :: + @spec construct(Delta.delta(), AccessGroupSupport.decoded_json_access_groups(), String.t(), String.t()) :: Delta.Message.t() - def construct(delta, access_groups, origin) do + def construct(delta, access_groups, origin, call_scope) do # TODO we should include the current access rigths and an # identifier for the originating service. This would help # services ignore content which came from their end and would @@ -33,6 +33,7 @@ defmodule Delta.Message do |> convert_delta_item |> add_allowed_groups(access_groups) |> add_origin(origin) + |> add_call_scope(call_scope) end) } @@ -62,6 +63,10 @@ defmodule Delta.Message do Map.put(map, "origin", origin) end + defp add_call_scope(map, call_scope) do + Map.put(map, "call-scope", call_scope) + end + defp convert_quad(%Quad{graph: graph, subject: subject, predicate: predicate, object: object}) do [g, s, p, o] = Enum.map( diff --git a/lib/delta/messenger.ex b/lib/delta/messenger.ex index 12e05dc..84059b4 100644 --- a/lib/delta/messenger.ex +++ b/lib/delta/messenger.ex @@ -35,6 +35,7 @@ defmodule Delta.Messenger do # backoff if the sending of the message failed. headers = [ {"Content-Type", "application/json"}, + {"mu-call-scope-id", options[:mu_call_scope_id]}, {"mu-call-id", Integer.to_string(Enum.random(0..1_000_000_000_000))}, {"mu-call-id-trail", options[:mu_call_id_trail]} ]