diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2020-05-22 11:43:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 11:43:17 +0100 |
commit | fe82e1f7255c05e0bc7a7872a53cf2a1a78ffaa0 (patch) | |
tree | 84661722411a9098f1925d2a5192e4c40d0a1122 /roomserver | |
parent | f223da2f35e690e80c6e3d8c1050f0984ab33a2f (diff) |
Separate muxes for public and internal APIs (#1056)
* Separate muxes for public and internal APIs
* Update client-api-proxy and federation-api-proxy so they don't add /api to the path
* Tidy up
* Consistent HTTP setup
* Set up prefixes properly
Diffstat (limited to 'roomserver')
-rw-r--r-- | roomserver/api/alias.go | 10 | ||||
-rw-r--r-- | roomserver/api/input.go | 2 | ||||
-rw-r--r-- | roomserver/api/perform.go | 4 | ||||
-rw-r--r-- | roomserver/api/query.go | 24 | ||||
-rw-r--r-- | roomserver/internal/api.go | 43 | ||||
-rw-r--r-- | roomserver/roomserver.go | 6 |
6 files changed, 43 insertions, 46 deletions
diff --git a/roomserver/api/alias.go b/roomserver/api/alias.go index 93975d36..54d2c633 100644 --- a/roomserver/api/alias.go +++ b/roomserver/api/alias.go @@ -85,19 +85,19 @@ type RemoveRoomAliasRequest struct { type RemoveRoomAliasResponse struct{} // RoomserverSetRoomAliasPath is the HTTP path for the SetRoomAlias API. -const RoomserverSetRoomAliasPath = "/api/roomserver/setRoomAlias" +const RoomserverSetRoomAliasPath = "/roomserver/setRoomAlias" // RoomserverGetRoomIDForAliasPath is the HTTP path for the GetRoomIDForAlias API. -const RoomserverGetRoomIDForAliasPath = "/api/roomserver/GetRoomIDForAlias" +const RoomserverGetRoomIDForAliasPath = "/roomserver/GetRoomIDForAlias" // RoomserverGetAliasesForRoomIDPath is the HTTP path for the GetAliasesForRoomID API. -const RoomserverGetAliasesForRoomIDPath = "/api/roomserver/GetAliasesForRoomID" +const RoomserverGetAliasesForRoomIDPath = "/roomserver/GetAliasesForRoomID" // RoomserverGetCreatorIDForAliasPath is the HTTP path for the GetCreatorIDForAlias API. -const RoomserverGetCreatorIDForAliasPath = "/api/roomserver/GetCreatorIDForAlias" +const RoomserverGetCreatorIDForAliasPath = "/roomserver/GetCreatorIDForAlias" // RoomserverRemoveRoomAliasPath is the HTTP path for the RemoveRoomAlias API. -const RoomserverRemoveRoomAliasPath = "/api/roomserver/removeRoomAlias" +const RoomserverRemoveRoomAliasPath = "/roomserver/removeRoomAlias" // SetRoomAlias implements RoomserverAliasAPI func (h *httpRoomserverInternalAPI) SetRoomAlias( diff --git a/roomserver/api/input.go b/roomserver/api/input.go index f1eec75a..d35ead76 100644 --- a/roomserver/api/input.go +++ b/roomserver/api/input.go @@ -103,7 +103,7 @@ type InputRoomEventsResponse struct { } // RoomserverInputRoomEventsPath is the HTTP path for the InputRoomEvents API. -const RoomserverInputRoomEventsPath = "/api/roomserver/inputRoomEvents" +const RoomserverInputRoomEventsPath = "/roomserver/inputRoomEvents" // InputRoomEvents implements RoomserverInputAPI func (h *httpRoomserverInternalAPI) InputRoomEvents( diff --git a/roomserver/api/perform.go b/roomserver/api/perform.go index 93f36f45..c98f91fb 100644 --- a/roomserver/api/perform.go +++ b/roomserver/api/perform.go @@ -10,10 +10,10 @@ import ( const ( // RoomserverPerformJoinPath is the HTTP path for the PerformJoin API. - RoomserverPerformJoinPath = "/api/roomserver/performJoin" + RoomserverPerformJoinPath = "/roomserver/performJoin" // RoomserverPerformLeavePath is the HTTP path for the PerformLeave API. - RoomserverPerformLeavePath = "/api/roomserver/performLeave" + RoomserverPerformLeavePath = "/roomserver/performLeave" ) type PerformJoinRequest struct { diff --git a/roomserver/api/query.go b/roomserver/api/query.go index 98f46c77..916ecb36 100644 --- a/roomserver/api/query.go +++ b/roomserver/api/query.go @@ -273,40 +273,40 @@ type QueryRoomVersionForRoomResponse struct { } // RoomserverQueryLatestEventsAndStatePath is the HTTP path for the QueryLatestEventsAndState API. -const RoomserverQueryLatestEventsAndStatePath = "/api/roomserver/queryLatestEventsAndState" +const RoomserverQueryLatestEventsAndStatePath = "/roomserver/queryLatestEventsAndState" // RoomserverQueryStateAfterEventsPath is the HTTP path for the QueryStateAfterEvents API. -const RoomserverQueryStateAfterEventsPath = "/api/roomserver/queryStateAfterEvents" +const RoomserverQueryStateAfterEventsPath = "/roomserver/queryStateAfterEvents" // RoomserverQueryEventsByIDPath is the HTTP path for the QueryEventsByID API. -const RoomserverQueryEventsByIDPath = "/api/roomserver/queryEventsByID" +const RoomserverQueryEventsByIDPath = "/roomserver/queryEventsByID" // RoomserverQueryMembershipForUserPath is the HTTP path for the QueryMembershipForUser API. -const RoomserverQueryMembershipForUserPath = "/api/roomserver/queryMembershipForUser" +const RoomserverQueryMembershipForUserPath = "/roomserver/queryMembershipForUser" // RoomserverQueryMembershipsForRoomPath is the HTTP path for the QueryMembershipsForRoom API -const RoomserverQueryMembershipsForRoomPath = "/api/roomserver/queryMembershipsForRoom" +const RoomserverQueryMembershipsForRoomPath = "/roomserver/queryMembershipsForRoom" // RoomserverQueryInvitesForUserPath is the HTTP path for the QueryInvitesForUser API -const RoomserverQueryInvitesForUserPath = "/api/roomserver/queryInvitesForUser" +const RoomserverQueryInvitesForUserPath = "/roomserver/queryInvitesForUser" // RoomserverQueryServerAllowedToSeeEventPath is the HTTP path for the QueryServerAllowedToSeeEvent API -const RoomserverQueryServerAllowedToSeeEventPath = "/api/roomserver/queryServerAllowedToSeeEvent" +const RoomserverQueryServerAllowedToSeeEventPath = "/roomserver/queryServerAllowedToSeeEvent" // RoomserverQueryMissingEventsPath is the HTTP path for the QueryMissingEvents API -const RoomserverQueryMissingEventsPath = "/api/roomserver/queryMissingEvents" +const RoomserverQueryMissingEventsPath = "/roomserver/queryMissingEvents" // RoomserverQueryStateAndAuthChainPath is the HTTP path for the QueryStateAndAuthChain API -const RoomserverQueryStateAndAuthChainPath = "/api/roomserver/queryStateAndAuthChain" +const RoomserverQueryStateAndAuthChainPath = "/roomserver/queryStateAndAuthChain" // RoomserverQueryBackfillPath is the HTTP path for the QueryBackfillPath API -const RoomserverQueryBackfillPath = "/api/roomserver/queryBackfill" +const RoomserverQueryBackfillPath = "/roomserver/queryBackfill" // RoomserverQueryRoomVersionCapabilitiesPath is the HTTP path for the QueryRoomVersionCapabilities API -const RoomserverQueryRoomVersionCapabilitiesPath = "/api/roomserver/queryRoomVersionCapabilities" +const RoomserverQueryRoomVersionCapabilitiesPath = "/roomserver/queryRoomVersionCapabilities" // RoomserverQueryRoomVersionForRoomPath is the HTTP path for the QueryRoomVersionForRoom API -const RoomserverQueryRoomVersionForRoomPath = "/api/roomserver/queryRoomVersionForRoom" +const RoomserverQueryRoomVersionForRoomPath = "/roomserver/queryRoomVersionForRoom" // QueryLatestEventsAndState implements RoomserverQueryAPI func (h *httpRoomserverInternalAPI) QueryLatestEventsAndState( diff --git a/roomserver/internal/api.go b/roomserver/internal/api.go index 4d223cf3..248e457d 100644 --- a/roomserver/internal/api.go +++ b/roomserver/internal/api.go @@ -6,6 +6,7 @@ import ( "sync" "github.com/Shopify/sarama" + "github.com/gorilla/mux" fsAPI "github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/internal/caching" @@ -32,8 +33,8 @@ type RoomserverInternalAPI struct { // SetupHTTP adds the RoomserverInternalAPI handlers to the http.ServeMux. // nolint: gocyclo -func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { - servMux.Handle(api.RoomserverInputRoomEventsPath, +func (r *RoomserverInternalAPI) SetupHTTP(internalAPIMux *mux.Router) { + internalAPIMux.Handle(api.RoomserverInputRoomEventsPath, internal.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse { var request api.InputRoomEventsRequest var response api.InputRoomEventsResponse @@ -46,7 +47,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle(api.RoomserverPerformJoinPath, + internalAPIMux.Handle(api.RoomserverPerformJoinPath, internal.MakeInternalAPI("performJoin", func(req *http.Request) util.JSONResponse { var request api.PerformJoinRequest var response api.PerformJoinResponse @@ -59,7 +60,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle(api.RoomserverPerformLeavePath, + internalAPIMux.Handle(api.RoomserverPerformLeavePath, internal.MakeInternalAPI("performLeave", func(req *http.Request) util.JSONResponse { var request api.PerformLeaveRequest var response api.PerformLeaveResponse @@ -72,7 +73,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryLatestEventsAndStatePath, internal.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse { var request api.QueryLatestEventsAndStateRequest @@ -86,7 +87,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryStateAfterEventsPath, internal.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse { var request api.QueryStateAfterEventsRequest @@ -100,7 +101,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryEventsByIDPath, internal.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse { var request api.QueryEventsByIDRequest @@ -114,7 +115,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryMembershipForUserPath, internal.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse { var request api.QueryMembershipForUserRequest @@ -128,7 +129,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryMembershipsForRoomPath, internal.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse { var request api.QueryMembershipsForRoomRequest @@ -142,7 +143,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryInvitesForUserPath, internal.MakeInternalAPI("queryInvitesForUser", func(req *http.Request) util.JSONResponse { var request api.QueryInvitesForUserRequest @@ -156,7 +157,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryServerAllowedToSeeEventPath, internal.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse { var request api.QueryServerAllowedToSeeEventRequest @@ -170,7 +171,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryMissingEventsPath, internal.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse { var request api.QueryMissingEventsRequest @@ -184,7 +185,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryStateAndAuthChainPath, internal.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse { var request api.QueryStateAndAuthChainRequest @@ -198,7 +199,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryBackfillPath, internal.MakeInternalAPI("QueryBackfill", func(req *http.Request) util.JSONResponse { var request api.QueryBackfillRequest @@ -212,7 +213,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryRoomVersionCapabilitiesPath, internal.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse { var request api.QueryRoomVersionCapabilitiesRequest @@ -226,7 +227,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverQueryRoomVersionForRoomPath, internal.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse { var request api.QueryRoomVersionForRoomRequest @@ -240,7 +241,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverSetRoomAliasPath, internal.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse { var request api.SetRoomAliasRequest @@ -254,7 +255,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverGetRoomIDForAliasPath, internal.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse { var request api.GetRoomIDForAliasRequest @@ -268,7 +269,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverGetCreatorIDForAliasPath, internal.MakeInternalAPI("GetCreatorIDForAlias", func(req *http.Request) util.JSONResponse { var request api.GetCreatorIDForAliasRequest @@ -282,7 +283,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverGetAliasesForRoomIDPath, internal.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse { var request api.GetAliasesForRoomIDRequest @@ -296,7 +297,7 @@ func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) - servMux.Handle( + internalAPIMux.Handle( api.RoomserverRemoveRoomAliasPath, internal.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse { var request api.RemoveRoomAliasRequest diff --git a/roomserver/roomserver.go b/roomserver/roomserver.go index 07250e7c..82934d50 100644 --- a/roomserver/roomserver.go +++ b/roomserver/roomserver.go @@ -15,8 +15,6 @@ package roomserver import ( - "net/http" - "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" @@ -51,9 +49,7 @@ func SetupRoomServerComponent( KeyRing: keyRing, } - if base.EnableHTTPAPIs { - internalAPI.SetupHTTP(http.DefaultServeMux) - } + internalAPI.SetupHTTP(base.InternalAPIMux) return &internalAPI } |