Merge branch 'service-origin' into 'main'

Allow configuring the origin of the service actor

See merge request soapbox-pub/rebased!298
This commit is contained in:
Alex Gleason 2023-12-25 14:01:41 +00:00
commit 833e59fec3
4 changed files with 30 additions and 7 deletions

View file

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

View file

@ -334,8 +334,16 @@ def relay(conn, _params) do
|> represent_service_actor(conn)
end
def internal_fetch(conn, _params) do
InternalFetchActor.get_actor()
def internal_fetch(%Plug.Conn{host: host} = conn, _params) do
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)
end

View file

@ -11,10 +11,24 @@ def init do
# Wait for everything to settle.
Process.sleep(1000 * 5)
get_actor()
get_actor(Pleroma.Web.Endpoint.url())
end
def get_actor do
"#{Pleroma.Web.Endpoint.url()}/internal/fetch"
|> User.get_or_create_service_actor_by_ap_id("internal.fetch")
def get_actor(origin) do
%URI{host: host} = URI.parse(origin)
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

View file

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