refactor(activitypub): handle failure finding public key in actor keys
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -112,19 +112,11 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
|
||||
},
|
||||
"discoverable" => actor.visibility == :public,
|
||||
"openness" => actor.openness,
|
||||
"manuallyApprovesFollowers" => actor.manually_approves_followers,
|
||||
"publicKey" => %{
|
||||
"id" => "#{actor.url}#main-key",
|
||||
"owner" => actor.url,
|
||||
"publicKeyPem" =>
|
||||
if(is_nil(actor.domain) and not is_nil(actor.keys),
|
||||
do: Utils.pem_to_public_key_pem(actor.keys),
|
||||
else: actor.keys
|
||||
)
|
||||
}
|
||||
"manuallyApprovesFollowers" => actor.manually_approves_followers
|
||||
}
|
||||
|
||||
actor_data
|
||||
|> add_keys(actor)
|
||||
|> add_endpoints(actor)
|
||||
|> maybe_add_members(actor)
|
||||
|> maybe_add_avatar_picture(actor)
|
||||
@@ -132,6 +124,28 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
|
||||
|> maybe_add_physical_address(actor)
|
||||
end
|
||||
|
||||
@spec add_keys(map(), ActorModel.t()) :: map()
|
||||
defp add_keys(actor_data, %ActorModel{} = actor) do
|
||||
keys =
|
||||
if is_nil(actor.domain) and not is_nil(actor.keys) do
|
||||
case Utils.pem_to_public_key_pem(actor.keys) do
|
||||
{:error, :no_publickey_found} ->
|
||||
raise "No publickey found in private keys"
|
||||
|
||||
public_key when is_binary(public_key) ->
|
||||
public_key
|
||||
end
|
||||
else
|
||||
actor.keys
|
||||
end
|
||||
|
||||
Map.put(actor_data, "publicKey", %{
|
||||
"id" => "#{actor.url}#main-key",
|
||||
"owner" => actor.url,
|
||||
"publicKeyPem" => keys
|
||||
})
|
||||
end
|
||||
|
||||
defp add_endpoints(%{"endpoints" => endpoints} = actor_data, %ActorModel{} = actor) do
|
||||
new_endpoints = %{
|
||||
"members" => actor.members_url,
|
||||
|
||||
Reference in New Issue
Block a user