Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cylc/uiserver/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
from cylc.uiserver.handlers import (
CylcStaticHandler,
CylcVersionHandler,
CylcLabBridgeHandler,
SubscriptionHandler,
UIServerGraphQLHandler,
UserProfileHandler,
Expand Down Expand Up @@ -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()
Expand All @@ -501,6 +507,11 @@ def initialize_handlers(self):
CylcVersionHandler,
{'auth': self.authobj}
),
(
'cylc/lab-bridge/([^/]+)/(.*)',
CylcLabBridgeHandler,
{'auth': self.authobj}
),
(
'cylc/graphql',
UIServerGraphQLHandler,
Expand Down
11 changes: 11 additions & 0 deletions cylc/uiserver/event_schemas/test.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions cylc/uiserver/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import json
import getpass
import os
from pathlib import Path
import re
from typing import TYPE_CHECKING, Callable, Dict

Expand Down Expand Up @@ -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'<pre>{event}</pre>')


class CylcVersionHandler(CylcAppHandler):
"""Renders information about the Cylc environment.

Expand Down
Loading