From dd97565dd5c59dcbb15edfb103cd00cc4149b57a Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 29 Mar 2022 11:33:09 +0200 Subject: [PATCH] Give extra content to Sentry when creating a signature Signed-off-by: Thomas Citharel --- lib/federation/http_signatures/signature.ex | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/federation/http_signatures/signature.ex b/lib/federation/http_signatures/signature.ex index 0427a63e..cebcfb27 100644 --- a/lib/federation/http_signatures/signature.ex +++ b/lib/federation/http_signatures/signature.ex @@ -102,14 +102,18 @@ defmodule Mobilizon.Federation.HTTPSignatures.Signature do end @spec sign(Actor.t(), map()) :: String.t() | {:error, :pem_decode_error} | no_return - def sign(%Actor{domain: domain, keys: keys} = actor, headers) when is_nil(domain) do - Logger.debug("Signing a payload on behalf of #{actor.url}") + def sign(%Actor{domain: domain, keys: keys, url: url} = actor, headers) when is_nil(domain) do + Logger.debug("Signing a payload on behalf of #{url}") Logger.debug("headers") Logger.debug(inspect(headers)) case prepare_public_key(keys) do {:ok, key} -> - HTTPSignatures.sign(key, actor.url <> "#main-key", headers) + if Application.get_env(:sentry, :dsn) != nil do + Sentry.Context.set_extra_context(%{"actor_url" => url}) + end + + HTTPSignatures.sign(key, url <> "#main-key", headers) {:error, :pem_decode_error} -> raise ArgumentError, message: "Failed to prepare public keys for #{actor.url}"