-
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 #1780 from fractal-analytics-platform/user-setting…
…s-api User Settings API
- Loading branch information
Showing
8 changed files
with
323 additions
and
6 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
from .user import * # noqa: F401, F403 | ||
from .user_group import * # noqa: F401, F403 | ||
from .user_settings import * # noqa: F401, F403 |
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,93 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
from pydantic import validator | ||
from pydantic.types import StrictStr | ||
|
||
from ._validators import val_absolute_path | ||
from ._validators import val_unique_list | ||
from ._validators import valstr | ||
from fractal_server.string_tools import validate_cmd | ||
|
||
__all__ = ( | ||
"UserSettingsRead", | ||
"UserSettingsReadStrict", | ||
"UserSettingsUpdate", | ||
"UserSettingsUpdateStrict", | ||
) | ||
|
||
|
||
class UserSettingsRead(BaseModel): | ||
id: int | ||
# SSH-SLURM | ||
ssh_host: Optional[str] = None | ||
ssh_username: Optional[str] = None | ||
ssh_private_key_path: Optional[str] = None | ||
ssh_tasks_dir: Optional[str] = None | ||
ssh_jobs_dir: Optional[str] = None | ||
# SUDO-SLURM | ||
slurm_user: Optional[str] = None | ||
slurm_accounts: list[str] | ||
cache_dir: Optional[str] = None | ||
|
||
|
||
class UserSettingsReadStrict(BaseModel): | ||
# SUDO-SLURM | ||
slurm_user: Optional[str] = None | ||
slurm_accounts: list[str] | ||
cache_dir: Optional[str] = None | ||
|
||
|
||
class UserSettingsUpdate(BaseModel): | ||
# SSH-SLURM | ||
ssh_host: Optional[str] = None | ||
ssh_username: Optional[str] = None | ||
ssh_private_key_path: Optional[str] = None | ||
ssh_tasks_dir: Optional[str] = None | ||
ssh_jobs_dir: Optional[str] = None | ||
# SUDO-SLURM | ||
slurm_user: Optional[str] = None | ||
slurm_accounts: Optional[list[StrictStr]] = None | ||
cache_dir: Optional[str] = None | ||
|
||
_ssh_host = validator("ssh_host", allow_reuse=True)(valstr("ssh_host")) | ||
_ssh_username = validator("ssh_username", allow_reuse=True)( | ||
valstr("ssh_username") | ||
) | ||
_ssh_private_key_path = validator( | ||
"ssh_private_key_path", allow_reuse=True | ||
)(val_absolute_path("ssh_private_key_path")) | ||
|
||
_ssh_tasks_dir = validator("ssh_tasks_dir", allow_reuse=True)( | ||
val_absolute_path("ssh_tasks_dir") | ||
) | ||
_ssh_jobs_dir = validator("ssh_jobs_dir", allow_reuse=True)( | ||
val_absolute_path("ssh_jobs_dir") | ||
) | ||
|
||
_slurm_user = validator("slurm_user", allow_reuse=True)( | ||
valstr("slurm_user") | ||
) | ||
_slurm_accounts = validator("slurm_accounts", allow_reuse=True)( | ||
val_unique_list("slurm_accounts") | ||
) | ||
|
||
@validator("cache_dir") | ||
def cache_dir_validator(cls, value): | ||
validate_cmd(value) | ||
return val_absolute_path("cache_dir")(value) | ||
|
||
|
||
class UserSettingsUpdateStrict(BaseModel): | ||
# SUDO-SLURM | ||
slurm_accounts: Optional[list[StrictStr]] = None | ||
cache_dir: Optional[str] = None | ||
|
||
_slurm_accounts = validator("slurm_accounts", allow_reuse=True)( | ||
val_unique_list("slurm_accounts") | ||
) | ||
|
||
@validator("cache_dir") | ||
def cache_dir_validator(cls, value): | ||
validate_cmd(value) | ||
return val_absolute_path("cache_dir")(value) |
52 changes: 52 additions & 0 deletions
52
fractal_server/migrations/versions/e1575a65e853_new_user_settings_columns.py
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 @@ | ||
"""new user settings columns | ||
Revision ID: e1575a65e853 | ||
Revises: dfbe4f3a7bc4 | ||
Create Date: 2024-09-19 12:14:38.481210 | ||
""" | ||
import sqlalchemy as sa | ||
import sqlmodel | ||
from alembic import op | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "e1575a65e853" | ||
down_revision = "dfbe4f3a7bc4" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("user_settings", schema=None) as batch_op: | ||
batch_op.add_column( | ||
sa.Column( | ||
"slurm_user", sqlmodel.sql.sqltypes.AutoString(), nullable=True | ||
) | ||
) | ||
batch_op.add_column( | ||
sa.Column( | ||
"slurm_accounts", | ||
sa.JSON(), | ||
server_default="[]", | ||
nullable=False, | ||
) | ||
) | ||
batch_op.add_column( | ||
sa.Column( | ||
"cache_dir", sqlmodel.sql.sqltypes.AutoString(), nullable=True | ||
) | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("user_settings", schema=None) as batch_op: | ||
batch_op.drop_column("cache_dir") | ||
batch_op.drop_column("slurm_accounts") | ||
batch_op.drop_column("slurm_user") | ||
|
||
# ### end Alembic commands ### |
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