-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from Lull3rSkat3r/issue-135-add-swagger-spec
[Issue 135]: Add swagger specs for jupyter-websocket mode
- Loading branch information
Showing
11 changed files
with
1,047 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,7 @@ | ||
## `jupyter-websocket` Mode | ||
|
||
The `KernelGatewayApp.api` command line argument defaults to | ||
`jupyter-websocket`. In this mode, the kernel gateway defines the following | ||
web resources: | ||
|
||
* `/api` (metadata) | ||
* `/api/kernelspecs` (what kernels are available) | ||
* `/api/kernels` (kernel CRUD, with discovery disabled by default, | ||
see `--list_kernels`) | ||
* `/api/kernels/:kernel_id/channels` (Websocket-to-[ZeroMQ](http://zeromq.org/) | ||
transformer for the [Jupyter kernel protocol](http://jupyter-client.readthedocs.org/en/latest/messaging.html)) | ||
* `/api/sessions` (session CRUD, for associating information with kernels, | ||
discovery disabled by default, see `--list_kernels`) | ||
* `/_api/activity` (activity metrics for all running kernels, enabled with | ||
`--list_kernels`) | ||
|
||
Discounting features of the kernel gateway (e.g., token auth), the behavior | ||
of these resources is equivalent to that found in the Jupyter Notebook server. | ||
The kernel gateway simply imports and extends the handler classes from | ||
the Jupyter Notebook. | ||
The `KernelGatewayApp.api` command line argument defaults to | ||
`jupyter-websocket`. The API exposed in this mode can be viewed | ||
in the [swagger ui.](http://petstore.swagger.io) by entering | ||
the link to the [swagger spec](https://raw.githubusercontent.com/jupyter/kernel_gateway/master/kernel_gateway/services/api/swagger.json) | ||
of kernel gateway. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
"""Tornado handlers for kernel specs.""" | ||
|
||
from tornado import web | ||
from ...mixins import TokenAuthorizationMixin, CORSMixin, JSONErrorsMixin | ||
import os | ||
|
||
class BaseSpecHandler(CORSMixin, web.StaticFileHandler): | ||
"""Exposes the ability to return specifications from static files""" | ||
@staticmethod | ||
def get_resource_metadata(): | ||
"""Returns the (resource, mime-type) for the handlers spec. | ||
""" | ||
pass | ||
|
||
def initialize(self): | ||
"""Initializes the instance of this class to serve files. | ||
The handler is initialized to server files from the directory | ||
where this module is defined. | ||
""" | ||
web.StaticFileHandler.initialize(self, path=os.path.dirname(__file__)) | ||
|
||
def get(self): | ||
"""Handler for a get on a specific handler | ||
""" | ||
resource_name, content_type = self.get_resource_metadata() | ||
self.set_header('Content-Type', content_type) | ||
return web.StaticFileHandler.get(self, resource_name) | ||
|
||
def options(self, **kwargs): | ||
"""Method for properly handling CORS pre-flight""" | ||
self.finish() | ||
|
||
class SpecJsonHandler(BaseSpecHandler): | ||
"""Exposes a JSON swagger specification""" | ||
@staticmethod | ||
def get_resource_metadata(): | ||
return ('swagger.json','application/json') | ||
|
||
class APIYamlHandler(BaseSpecHandler): | ||
"""Exposes a YAML swagger specification""" | ||
@staticmethod | ||
def get_resource_metadata(): | ||
return ('swagger.yaml', 'text/x-yaml') | ||
|
||
|
||
default_handlers = [ | ||
('/api/{}'.format(SpecJsonHandler.get_resource_metadata()[0]), SpecJsonHandler), | ||
('/api/{}'.format(APIYamlHandler.get_resource_metadata()[0]), APIYamlHandler) | ||
] |
Oops, something went wrong.