Skip to content

Commit

Permalink
Add "support" for Dendrite admin API (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live authored Nov 23, 2023
1 parent adb27ee commit 46e77ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
28 changes: 18 additions & 10 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion matrix/requests_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
}
Expand Down

0 comments on commit 46e77ae

Please sign in to comment.