From e99a13a391bc55ab3c78411b28249182d6016940 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 5 Jan 2023 00:27:29 +0200 Subject: [PATCH] Drop support for custom API paths Changing the base public URL is still possible (which may be useful if someone wants to use a reverse proxy without adding subdomains). Fixes #195 --- maubot/config.py | 2 -- maubot/example-config.yaml | 4 ---- maubot/management/api/client_auth.py | 3 +-- maubot/management/api/middleware.py | 2 +- maubot/management/frontend/src/pages/Main.js | 5 ++--- maubot/server.py | 10 +++------- 6 files changed, 7 insertions(+), 19 deletions(-) diff --git a/maubot/config.py b/maubot/config.py index e11fe1c..c5368cd 100644 --- a/maubot/config.py +++ b/maubot/config.py @@ -52,11 +52,9 @@ class Config(BaseFileConfig): copy("server.port") copy("server.public_url") copy("server.listen") - copy("server.base_path") copy("server.ui_base_path") copy("server.plugin_base_path") copy("server.override_resource_path") - copy("server.appservice_base_path") shared_secret = self["server.unshared_secret"] if shared_secret is None or shared_secret == "generate": base["server.unshared_secret"] = self._new_token() diff --git a/maubot/example-config.yaml b/maubot/example-config.yaml index d157269..0181846 100644 --- a/maubot/example-config.yaml +++ b/maubot/example-config.yaml @@ -55,8 +55,6 @@ server: port: 29316 # Public base URL where the server is visible. public_url: https://example.com - # The base management API path. - base_path: /_matrix/maubot/v1 # The base path for the UI. ui_base_path: /_matrix/maubot # The base path for plugin endpoints. The instance ID will be appended directly. @@ -64,8 +62,6 @@ server: # Override path from where to load UI resources. # Set to false to using pkg_resources to find the path. override_resource_path: false - # The base appservice API path. Use / for legacy appservice API and /_matrix/app/v1 for v1. - appservice_base_path: /_matrix/app/v1 # The shared secret to sign API access tokens. # Set to "generate" to generate and save a new token at startup. unshared_secret: generate diff --git a/maubot/management/api/client_auth.py b/maubot/management/api/client_auth.py index f630931..4e5e201 100644 --- a/maubot/management/api/client_auth.py +++ b/maubot/management/api/client_auth.py @@ -184,8 +184,7 @@ async def _do_sso(req: AuthRequestInfo) -> web.Response: cfg = get_config() public_url = ( URL(cfg["server.public_url"]) - / cfg["server.base_path"].lstrip("/") - / "client/auth_external_sso/complete" + / "_matrix/maubot/v1/client/auth_external_sso/complete" / waiter_id ) sso_url = req.client.api.base_url.with_path(str(Path.v3.login.sso.redirect)).with_query( diff --git a/maubot/management/api/middleware.py b/maubot/management/api/middleware.py index 0ecb681..17141fa 100644 --- a/maubot/management/api/middleware.py +++ b/maubot/management/api/middleware.py @@ -29,7 +29,7 @@ log = logging.getLogger("maubot.server") @web.middleware async def auth(request: web.Request, handler: Handler) -> web.Response: - subpath = request.path[len(get_config()["server.base_path"]) :] + subpath = request.path[len("/_matrix/maubot/v1") :] if ( subpath.startswith("/auth/") or subpath.startswith("/client/auth_external_sso/complete/") diff --git a/maubot/management/frontend/src/pages/Main.js b/maubot/management/frontend/src/pages/Main.js index fb650b6..5ee374e 100644 --- a/maubot/management/frontend/src/pages/Main.js +++ b/maubot/management/frontend/src/pages/Main.js @@ -45,9 +45,8 @@ class Main extends Component { const resp = await fetch(process.env.PUBLIC_URL + "/paths.json", { headers: { "Content-Type": "application/json" }, }) - const apiPathJson = await resp.json() - const apiPath = apiPathJson.api_path - api.setBasePath(`${apiPath}`) + const apiPaths = await resp.json() + api.setBasePath(apiPaths.api_path) } catch (err) { console.error("Failed to get API path:", err) } diff --git a/maubot/server.py b/maubot/server.py index d70ae7e..ac3132d 100644 --- a/maubot/server.py +++ b/maubot/server.py @@ -52,7 +52,7 @@ class MaubotServer: self.config = config self.setup_appservice() - self.app.add_subapp(config["server.base_path"], management_api) + self.app.add_subapp("/_matrix/maubot/v1", management_api) self.setup_instance_subapps() self.setup_management_ui() @@ -93,7 +93,7 @@ class MaubotServer: self.app.router.register_resource(resource) def setup_appservice(self) -> None: - as_path = PathBuilder(self.config["server.appservice_base_path"]) + as_path = PathBuilder("/_matrix/appservice/v1") self.add_route(Method.PUT, as_path.transactions, self.handle_transaction) def setup_management_ui(self) -> None: @@ -140,16 +140,12 @@ class MaubotServer: f"{ui_base}/{file}", lambda _: web.Response(body=data, content_type=mime) ) - # also set up a resource path for the public url path prefix config - # cut the prefix path from public_url public_url = self.config["server.public_url"] - base_path = self.config["server.base_path"] public_url_path = "" if public_url: public_url_path = URL(public_url).path.rstrip("/") - # assemble with base_path - api_path = f"{public_url_path}{base_path}" + api_path = f"{public_url_path}/_matrix/maubot/v1" path_prefix_response_body = json.dumps({"api_path": api_path.rstrip("/")}) self.app.router.add_get(