Give extra content to Sentry when creating a signature

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-03-29 11:33:09 +02:00
parent 4a8064f24f
commit dd97565dd5
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -102,14 +102,18 @@ defmodule Mobilizon.Federation.HTTPSignatures.Signature do
end end
@spec sign(Actor.t(), map()) :: String.t() | {:error, :pem_decode_error} | no_return @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 def sign(%Actor{domain: domain, keys: keys, url: url} = actor, headers) when is_nil(domain) do
Logger.debug("Signing a payload on behalf of #{actor.url}") Logger.debug("Signing a payload on behalf of #{url}")
Logger.debug("headers") Logger.debug("headers")
Logger.debug(inspect(headers)) Logger.debug(inspect(headers))
case prepare_public_key(keys) do case prepare_public_key(keys) do
{:ok, key} -> {: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} -> {:error, :pem_decode_error} ->
raise ArgumentError, message: "Failed to prepare public keys for #{actor.url}" raise ArgumentError, message: "Failed to prepare public keys for #{actor.url}"