From 46e77aee07fbb5787fce71fc67999cf0a278c4bf Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 22 Nov 2023 20:47:56 -0700 Subject: [PATCH] Add "support" for Dendrite admin API (#502) --- config.sample.yaml | 28 ++++++++++++++++++---------- matrix/requests_admin.go | 6 +++++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/config.sample.yaml b/config.sample.yaml index 83797959..98d278a5 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -73,16 +73,24 @@ database: # The configuration for the homeservers this media repository is known to control. Servers # not listed here will not be able to upload media. homeservers: - - name: example.org # This should match the server_name of your homeserver, and the Host header - # provided to the media repo. - csApi: "https://example.org/" # The base URL to where the homeserver can actually be reached - backoffAt: 10 # The number of consecutive failures in calling this homeserver before the - # media repository will start backing off. This defaults to 10 if not given. - adminApiKind: "matrix" # The kind of admin API the homeserver supports. If set to "matrix", - # the media repo will use the Synapse-defined endpoints under the - # unstable client-server API. When this is "synapse", the new /_synapse - # endpoints will be used instead. Unknown values are treated as the - # default, "matrix". + - # Keep the dash from this line. + + # This should match the server_name of your homeserver, and the Host header + # provided to the media repo. + name: example.org + + # The base URL to where the homeserver can actually be reached by MMR. + csApi: "https://example.org/" + + # The number of consecutive failures in calling this homeserver before the + # media repository will start backing off. This defaults to 10 if not given. + backoffAt: 10 + + # The admin API interface supported by the homeserver. MMR uses a subset of the admin API + # during certain operations, like attempting to purge media from a room or validating server + # admin status. This should be set to one of "synapse", "dendrite", or "matrix". When set + # to "matrix", most functionality requiring the admin API will not work. + adminApiKind: "synapse" # Options for controlling how access tokens work with the media repo. It is recommended that if # you are going to use these options that the `/logout` and `/logout/all` client-server endpoints diff --git a/matrix/requests_admin.go b/matrix/requests_admin.go index e8a005df..273cf44c 100644 --- a/matrix/requests_admin.go +++ b/matrix/requests_admin.go @@ -18,8 +18,9 @@ func IsUserAdmin(ctx rcontext.RequestContext, serverName string, accessToken str var replyError error replyError = cb.CallContext(ctx, func() error { response := &whoisResponse{} + // the whois endpoint is part of the spec, meaning we can avoid per-homeserver support path := fmt.Sprintf("/_matrix/client/v3/admin/whois/%s", url.PathEscape(fakeUser)) - if hs.AdminApiKind == "synapse" { + if hs.AdminApiKind == "synapse" { // synapse is special, dendrite is not path = fmt.Sprintf("/_synapse/admin/v1/whois/%s", url.PathEscape(fakeUser)) } urlStr := util.MakeUrl(hs.ClientServerApi, path) @@ -46,6 +47,9 @@ func ListMedia(ctx rcontext.RequestContext, serverName string, accessToken strin if hs.AdminApiKind == "synapse" { path = fmt.Sprintf("/_synapse/admin/v1/room/%s/media", url.PathEscape(roomId)) } + if hs.AdminApiKind == "dendrite" { + return errors.New("this function is not supported when backed by Dendrite") + } if path == "" { return errors.New("unable to query media for homeserver: wrong or incompatible adminApiKind") }