Allow configuring the origin of the service actor

This commit is contained in:
Alex Gleason 2023-12-23 23:07:35 -06:00
parent 491f84f284
commit 2eb5c453ad
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
4 changed files with 30 additions and 7 deletions

View file

@ -375,7 +375,8 @@
follow_handshake_timeout: 500, follow_handshake_timeout: 500,
note_replies_output_limit: 5, note_replies_output_limit: 5,
sign_object_fetches: true, sign_object_fetches: true,
authorized_fetch_mode: false authorized_fetch_mode: false,
fetch_actor_origin: nil
config :pleroma, :streamer, config :pleroma, :streamer,
workers: 3, workers: 3,

View file

@ -334,8 +334,16 @@ def relay(conn, _params) do
|> represent_service_actor(conn) |> represent_service_actor(conn)
end end
def internal_fetch(conn, _params) do def internal_fetch(%Plug.Conn{host: host} = conn, _params) do
InternalFetchActor.get_actor() with fetch_actor_origin when is_binary(fetch_actor_origin) <-
Pleroma.Config.get([:activitypub, :fetch_actor_origin]),
%URI{host: fetch_actor_host} <- URI.parse(fetch_actor_origin),
true <- host == fetch_actor_host do
fetch_actor_origin
else
_ -> Pleroma.Web.Endpoint.url()
end
|> InternalFetchActor.get_actor()
|> represent_service_actor(conn) |> represent_service_actor(conn)
end end

View file

@ -11,10 +11,24 @@ def init do
# Wait for everything to settle. # Wait for everything to settle.
Process.sleep(1000 * 5) Process.sleep(1000 * 5)
get_actor() get_actor()
get_actor(Pleroma.Web.Endpoint.url())
end end
def get_actor do def get_actor(origin) do
"#{Pleroma.Web.Endpoint.url()}/internal/fetch" %URI{host: host} = URI.parse(origin)
|> User.get_or_create_service_actor_by_ap_id("internal.fetch")
nickname =
cond do
host == Pleroma.Web.Endpoint.host() -> "internal.fetch"
true -> "internal.fetch@#{host}"
end
"#{origin}/internal/fetch"
|> User.get_or_create_service_actor_by_ap_id(nickname)
end
def get_actor() do
(Pleroma.Config.get([:activitypub, :fetch_actor_origin]) || Pleroma.Web.Endpoint.url())
|> get_actor()
end end
end end

View file

@ -75,7 +75,7 @@ test "it returns the internal fetch user", %{conn: conn} do
|> get(activity_pub_path(conn, :internal_fetch)) |> get(activity_pub_path(conn, :internal_fetch))
|> json_response(200) |> json_response(200)
assert res["id"] =~ "/fetch" assert res["id"] =~ "http://localhost:4001/internal/fetch"
end end
test "on non-federating instance, it returns 404", %{conn: conn} do test "on non-federating instance, it returns 404", %{conn: conn} do