-
Notifications
You must be signed in to change notification settings - Fork 3
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 #1779 from fractal-analytics-platform/use-new-sett…
…ings Validate SSH user settings in API
- Loading branch information
Showing
11 changed files
with
215 additions
and
15 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
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
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,41 @@ | ||
from fastapi import HTTPException | ||
from fastapi import status | ||
from pydantic import ValidationError | ||
|
||
from fractal_server.app.db import AsyncSession | ||
from fractal_server.app.models import UserOAuth | ||
from fractal_server.app.models import UserSettings | ||
from fractal_server.app.routes.api.v2._aux_functions import logger | ||
from fractal_server.user_settings import SlurmSshUserSettings | ||
|
||
|
||
async def validate_user_settings( | ||
*, user: UserOAuth, backend: str, db: AsyncSession | ||
): | ||
""" | ||
FIXME docstring | ||
""" | ||
# First: check that the foreign-key exists. TODO: remove this check, | ||
# after this column is made required | ||
if user.user_settings_id is None: | ||
raise HTTPException( | ||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, | ||
detail=f"Error: user '{user.email}' has no settings.", | ||
) | ||
|
||
user_settings = await db.get(UserSettings, user.user_settings_id) | ||
|
||
if backend == "slurm_ssh": | ||
try: | ||
SlurmSshUserSettings(**user_settings.model_dump()) | ||
except ValidationError as e: | ||
error_msg = ( | ||
"User settings are not valid for " | ||
f"FRACTAL_RUNNER_BACKEND='{backend}'. " | ||
f"Original error: {str(e)}" | ||
) | ||
logger.warning(error_msg) | ||
raise HTTPException( | ||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, | ||
detail=error_msg, | ||
) |
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,22 @@ | ||
# TODO: move this file to the appropriate path | ||
from pydantic import BaseModel | ||
|
||
|
||
class SlurmSshUserSettings(BaseModel): | ||
""" | ||
Subset of user settings which must be present for task collection and job | ||
execution when using the Slurm-SSH runner. | ||
Attributes: | ||
ssh_host: SSH-reachable host where a SLURM client is available. | ||
ssh_username: User on `ssh_host`. | ||
ssh_private_key_path: Path of private SSH key for `ssh_username`. | ||
ssh_tasks_dir: Task-venvs base folder on `ssh_host`. | ||
ssh_jobs_dir: Jobs base folder on `ssh_host`. | ||
""" | ||
|
||
ssh_host: str | ||
ssh_username: str | ||
ssh_private_key_path: str | ||
ssh_tasks_dir: str | ||
ssh_jobs_dir: str |
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
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
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