diff --git a/cylc/uiserver/app.py b/cylc/uiserver/app.py index 9914268a..f14790d0 100644 --- a/cylc/uiserver/app.py +++ b/cylc/uiserver/app.py @@ -95,6 +95,7 @@ from cylc.uiserver.handlers import ( CylcStaticHandler, CylcVersionHandler, + CylcLabBridgeHandler, SubscriptionHandler, UIServerGraphQLHandler, UserProfileHandler, @@ -491,6 +492,11 @@ def initialize_settings(self): self.scan_interval * 1000 ).start() + # register Jupyter Event schemas + self.serverapp.event_logger.register_event_schema( + Path(__file__).parent / 'event_schemas/test.yml' + ) + def initialize_handlers(self): self.authobj = self.set_auth() self.set_sub_server() @@ -501,6 +507,11 @@ def initialize_handlers(self): CylcVersionHandler, {'auth': self.authobj} ), + ( + 'cylc/lab-bridge/([^/]+)/(.*)', + CylcLabBridgeHandler, + {'auth': self.authobj} + ), ( 'cylc/graphql', UIServerGraphQLHandler, diff --git a/cylc/uiserver/event_schemas/test.yml b/cylc/uiserver/event_schemas/test.yml new file mode 100644 index 00000000..191fdd83 --- /dev/null +++ b/cylc/uiserver/event_schemas/test.yml @@ -0,0 +1,11 @@ +$id: http://events.cylc.org/test +version: 1 +title: Test +description: An interesting event to collect +properties: + name: + title: Name of Event + type: string + path: + title: File to open + type: string diff --git a/cylc/uiserver/handlers.py b/cylc/uiserver/handlers.py index ec19029f..fb3caa19 100644 --- a/cylc/uiserver/handlers.py +++ b/cylc/uiserver/handlers.py @@ -18,6 +18,7 @@ import json import getpass import os +from pathlib import Path import re from typing import TYPE_CHECKING, Callable, Dict @@ -206,6 +207,26 @@ def get(self, path): return web.StaticFileHandler.get(self, path) +class CylcLabBridgeHandler(CylcAppHandler): + + @authorised + @web.authenticated + def get(self, event, path): + from urllib.parse import unquote + path = Path(unquote(path)) + if not path.is_absolute(): + path = Path('~', path) + path.expanduser() + path = path.relative_to(Path('~').expanduser()) + + event = {'name': event, 'path': str(path)} + self.serverapp.event_logger.emit( + schema_id='http://events.cylc.org/test', + data=event, + ) + self.write(f'
{event}')
+
+
class CylcVersionHandler(CylcAppHandler):
"""Renders information about the Cylc environment.