Skip to content
Draft

Jwt #70

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
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Reana JupyterLab plugin provides a set of tools to interact with the [Reana](htt
## Installation guide for users
To install the extension, run the following command:
```bash
pip install reana-jupyterlab
python -m pip install reana-jupyterlab
```

In case you want to run the tests, install the extension with the following command:
```bash
pip install reana-jupyterlab[dev]
python -m pip install reana-jupyterlab[dev]
```

### Docker image
Expand All @@ -52,17 +52,18 @@ Build the extension
jlpm run build
```

Install the extension (including the testing dependencies)
Install the extension in editable mode and include the development dependencies:
```bash
python -m pip install .[dev]
python -m pip install -e .
python -m pip install ".[dev]"
```

Enable the server extension
```bash
jupyter server extension enable --py reana_jupyterlab
python -m jupyter server extension enable --py reana_jupyterlab.server
```

Finally, open a JupyterLab instance. The extension should be available in the JupyterLab sidebar.
```bash
jupyter lab
```
python -m jupyter lab
```
9 changes: 8 additions & 1 deletion reana_jupyterlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ def _jupyter_labextension_paths():
def _jupyter_server_extension_points(): # pragma: no cover
return [{
"module": "reana_jupyterlab.server"
}]
}]

# Import and expose the server extension loading function for backward compatibility
# Fixes `X Validation failed: validation failed` error

from .server import _load_jupyter_server_extension

load_jupyter_server_extension = _load_jupyter_server_extension
37 changes: 37 additions & 0 deletions reana_jupyterlab/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import requests

class ReanaAPIClient:
def __init__(self):
self.server_url = os.getenv('REANA_SERVER_URL', '')
self.access_token = os.getenv('REANA_ACCESS_TOKEN', '')

def _get_headers(self):
return {
'Authorization': f'Bearer {self.access_token}'
}

def get(self, endpoint, params=None):
if params is None:
params = {}

headers = self._get_headers()
response = requests.get(
f"{self.server_url}/api/{endpoint}",
headers=headers,
params=params
)
return response

def post(self, endpoint, json=None, params=None):
if params is None:
params = {}

headers = self._get_headers()
response = requests.post(
f"{self.server_url}/api/{endpoint}",
headers=headers,
json=json,
params=params
)
return response
2 changes: 1 addition & 1 deletion reana_jupyterlab/handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .handlers import *
from .handlers import *
50 changes: 0 additions & 50 deletions reana_jupyterlab/handlers/connection.py

This file was deleted.

13 changes: 6 additions & 7 deletions reana_jupyterlab/handlers/handlers.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
from jupyter_server.utils import url_path_join
from jupyter_server.serverapp import ServerApp
from .connection import EnvVariablesHandler
from jupyter_server.utils import url_path_join
from .files import FileBrowserHandler

from .workflows import (
WorkflowsHandler,
WorkflowLogsHandler,
WorkflowWorkspaceHandler,
WorkflowLogsHandler,
WorkflowWorkspaceHandler,
WorkflowSpecificationHandler,
WorkspaceFilesHandler,
WorkflowCreateHandler,
WorkflowValidateHandler,
WorkflowValidateHandler
)

def setup_handlers(server_app: ServerApp) -> None:
web_app = server_app.web_app
host_pattern = ".*$"
base_url = url_path_join(web_app.settings["base_url"], "reana_jupyterlab")
handlers = [
(url_path_join(base_url, "env"), EnvVariablesHandler),
(url_path_join(base_url, "workflows", "([^/]+)", "workspace", "([^/]+)"), WorkspaceFilesHandler),
(url_path_join(base_url, "workflows", "([^/]+)", "workspace"), WorkflowWorkspaceHandler),
(url_path_join(base_url, "workflows", "([^/]+)", "logs"), WorkflowLogsHandler),
Expand All @@ -27,4 +26,4 @@ def setup_handlers(server_app: ServerApp) -> None:
(url_path_join(base_url, "validate"), WorkflowValidateHandler),
(url_path_join(base_url, "files"), FileBrowserHandler),
]
web_app.add_handlers(host_pattern, handlers)
web_app.add_handlers(host_pattern, handlers)
Loading
Loading