-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added JWT auth + /pyewatercycle endpoint #29
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanup always good, ewatercycle notebook generation code looks good as well. Tried running locally but got authentication failure. Tried exporting the generated notebook from test to verify, but didn't succeed so far. Couple of comments.
lumped: | ||
type: boolean | ||
description: Whether model is lumped or non-lumped model | ||
default: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps instead of a boolean, we could use something like:
model_type:
type: string
description: Whether model is lumped or gridded (or ...)
default: gridded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can think of a third type then I would switch to an enum. For now boolean is clear enough for me.
forcing: | ||
type: string | ||
description: Directory name of forcing. Directory should contain `ewatercycle_forcing.yaml` file. | ||
example: marrmot-m01_example_1989-1992_buffalo-river |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes that a (basic) forcing exists for each model instance in our explorer. An alternative would be to add a "generate forcing" cell. Not sure if we should support both, though. For now, compromise on having a short example forcing for each model?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would indeed be nice to generate forcings in notebook, for now I created #30 to add it later.
if "forcing" in setup: | ||
forcing = setup["forcing"] | ||
if not forcing.startswith("/"): | ||
forcing = forcing_root_dir + "/" + forcing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it safer to use pathlib here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep will fix. Dont expect many Windows deployments, but better safe then sorry
from ewatercycle_experiment_launcher.process import process_notebook | ||
|
||
|
||
def notebook(setup: dict, forcing_root_dir: str) -> NotebookNode: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is forcing_root_dir a separate parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is set from command line, not from a request body. Also to make testing easier the notebook method is written without any flask globals.
Can be removed once eWaterCycle/ewatercycle#248 is implemented.
|
||
|
||
def check_auth(username, password, required_scopes=None): | ||
def check_basic_auth(username, password, required_scopes=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required_scopes is not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/zalando/connexion/tree/main/examples/openapi3/basicauth used it, but you right also works without.
timestamp = _current_timestamp() | ||
payload = { | ||
"iss": JWT_ISSUER, | ||
"iat": int(timestamp), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is already an integer after L19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, copied it from https://github.com/zalando/connexion/blob/2dfd57dafbedff99c0a32616079f80c21b9de6d9/examples/openapi3/jwt/app.py#L22 which also has double cast
def _current_timestamp() -> int: | ||
return int(time.time()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only used once, perhaps no need for a function?
@@ -84,16 +84,23 @@ To start launcher use | |||
```bash | |||
# JUPYTERHUB_URL is URL where JupyterHub is running. If path like `/jupyter` then origin header is appended. | |||
export JUPYTERHUB_URL=http://172.17.0.1:8000 | |||
# JWT_SECRET is secret with which JWT tokens are encoded/decoded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the sudo on L24 is not needed. Might be better to avoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On L54 I get failed authentication (on WSL2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sudo is needed for nodejs installed with apt. Switched to https://github.com/nvm-sh/nvm
To generate a notebook you need to | ||
1. POST to /auth with Basic authentication to receive a JWT token | ||
2. POST to a notebook path, like /hello, with `Authorization: Bearer <jwt token>` header. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting 401 unauthorized for everything I try (WSL problem?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, JH uses the OS user accounts to authenticated against. Which works on my linux box. Not sure how accounts work in WSL. Mabye add user with sudo useradd someone;sudo passwd someone
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still no luck
Co-authored-by: Peter Kalverla <[email protected]>
Co-authored-by: Peter Kalverla <[email protected]>
SonarCloud Quality Gate failed. |
Refs eWaterCycle/terriajs#8
Refs #27