Implement GET /rooms/{roomAlias} (#494)
* Query whether a room alias exists on app services Signed-off-by: Andrew Morgan <andrewm@matrix.org> * URL encode room alias before sending to AS * Add /room/ to path * Query AS /alias/ API at a lower level * Don't verify self-signed AS certificates * Don't skip cert validation on appservices, fix logging * Separate req.WithContext * Linting * Do not warn when an AS room alias does not exist
This commit is contained in:
parent
e05a31f4c2
commit
609646c19b
13 changed files with 247 additions and 105 deletions
|
|
@ -18,16 +18,41 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
commonHTTP "github.com/matrix-org/dendrite/common/http"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
// RoomAliasExistsRequest is a request to an application service
|
||||
// about whether a room alias exists
|
||||
type RoomAliasExistsRequest struct {
|
||||
// Alias we want to lookup
|
||||
Alias string `json:"alias"`
|
||||
}
|
||||
|
||||
// RoomAliasExistsResponse is a response from an application service
|
||||
// about whether a room alias exists
|
||||
type RoomAliasExistsResponse struct {
|
||||
AliasExists bool `json:"exists"`
|
||||
}
|
||||
|
||||
// AppServiceQueryAPI is used to query user and room alias data from application
|
||||
// services
|
||||
type AppServiceQueryAPI interface {
|
||||
// TODO: Check whether a room alias exists within any application service namespaces
|
||||
// Check whether a room alias exists within any application service namespaces
|
||||
RoomAliasExists(
|
||||
ctx context.Context,
|
||||
req *RoomAliasExistsRequest,
|
||||
response *RoomAliasExistsResponse,
|
||||
) error
|
||||
// TODO: QueryUserIDExists
|
||||
}
|
||||
|
||||
// AppServiceRoomAliasExistsPath is the HTTP path for the RoomAliasExists API
|
||||
const AppServiceRoomAliasExistsPath = "/api/appservice/RoomAliasExists"
|
||||
|
||||
// httpAppServiceQueryAPI contains the URL to an appservice query API and a
|
||||
// reference to a httpClient used to reach it
|
||||
type httpAppServiceQueryAPI struct {
|
||||
|
|
@ -47,3 +72,16 @@ func NewAppServiceQueryAPIHTTP(
|
|||
}
|
||||
return &httpAppServiceQueryAPI{appserviceURL, httpClient}
|
||||
}
|
||||
|
||||
// RoomAliasExists implements AppServiceQueryAPI
|
||||
func (h *httpAppServiceQueryAPI) RoomAliasExists(
|
||||
ctx context.Context,
|
||||
request *RoomAliasExistsRequest,
|
||||
response *RoomAliasExistsResponse,
|
||||
) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "appserviceRoomAliasExists")
|
||||
defer span.Finish()
|
||||
|
||||
apiURL := h.appserviceURL + AppServiceRoomAliasExistsPath
|
||||
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue