Skip to content

Commit

Permalink
merge master into bugfix-healthcheck-rabbitmq-cancelled-connection
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Nov 14, 2024
2 parents bad9eda + 0781e63 commit b537757
Show file tree
Hide file tree
Showing 159 changed files with 3,524 additions and 1,909 deletions.
22 changes: 22 additions & 0 deletions api/specs/web-server/_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ async def list_folders(
...


@router.get(
"/folders:search",
response_model=Envelope[list[FolderGet]],
)
async def list_folders_full_search(
params: Annotated[PageQueryParameters, Depends()],
text: str | None = None,
order_by: Annotated[
Json,
Query(
description="Order by field (modified_at|name|description) and direction (asc|desc). The default sorting order is ascending.",
example='{"field": "name", "direction": "desc"}',
),
] = '{"field": "modified_at", "direction": "desc"}',
filters: Annotated[
Json | None,
Query(description=FolderFilters.schema_json(indent=1)),
] = None,
):
...


@router.get(
"/folders/{folder_id}",
response_model=Envelope[FolderGet],
Expand Down
2 changes: 0 additions & 2 deletions packages/aws-library/requirements/_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ arrow==1.3.0
# -r requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/../../../packages/service-library/requirements/_base.in
# -r requirements/_base.in
async-timeout==4.0.3
# via redis
attrs==24.2.0
# via
# aiohttp
Expand Down
42 changes: 39 additions & 3 deletions packages/models-library/src/models_library/folders.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
from datetime import datetime
from enum import auto
from typing import TypeAlias

from models_library.users import GroupID, UserID
from models_library.workspaces import WorkspaceID
from pydantic import BaseModel, Field, PositiveInt
from pydantic import BaseModel, Field, PositiveInt, validator

from .access_rights import AccessRights
from .users import GroupID, UserID
from .utils.enums import StrAutoEnum
from .workspaces import WorkspaceID

FolderID: TypeAlias = PositiveInt


class FolderScope(StrAutoEnum):
ROOT = auto()
SPECIFIC = auto()
ALL = auto()


class FolderQuery(BaseModel):
folder_scope: FolderScope
folder_id: PositiveInt | None = None

@validator("folder_id", pre=True, always=True)
@classmethod
def validate_folder_id(cls, value, values):
scope = values.get("folder_scope")
if scope == FolderScope.SPECIFIC and value is None:
raise ValueError(
"folder_id must be provided when folder_scope is SPECIFIC."
)
if scope != FolderScope.SPECIFIC and value is not None:
raise ValueError(
"folder_id should be None when folder_scope is not SPECIFIC."
)
return value


#
# DB
#
Expand Down Expand Up @@ -38,3 +67,10 @@ class FolderDB(BaseModel):

class Config:
orm_mode = True


class UserFolderAccessRightsDB(FolderDB):
my_access_rights: AccessRights

class Config:
orm_mode = True
34 changes: 31 additions & 3 deletions packages/models-library/src/models_library/workspaces.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
from datetime import datetime
from enum import auto
from typing import TypeAlias

from models_library.access_rights import AccessRights
from models_library.users import GroupID
from pydantic import BaseModel, Field, PositiveInt
from pydantic import BaseModel, Field, PositiveInt, validator

from .access_rights import AccessRights
from .users import GroupID
from .utils.enums import StrAutoEnum

WorkspaceID: TypeAlias = PositiveInt


class WorkspaceScope(StrAutoEnum):
PRIVATE = auto()
SHARED = auto()
ALL = auto()


class WorkspaceQuery(BaseModel):
workspace_scope: WorkspaceScope
workspace_id: PositiveInt | None = None

@validator("workspace_id", pre=True, always=True)
@classmethod
def validate_workspace_id(cls, value, values):
scope = values.get("workspace_scope")
if scope == WorkspaceScope.SHARED and value is None:
raise ValueError(
"workspace_id must be provided when workspace_scope is SHARED."
)
if scope != WorkspaceScope.SHARED and value is not None:
raise ValueError(
"workspace_id should be None when workspace_scope is not SHARED."
)
return value


#
# DB
#
Expand Down
27 changes: 27 additions & 0 deletions packages/notifications-library/requirements/_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ attrs==24.2.0
# referencing
click==8.1.7
# via typer
deprecated==1.2.14
# via
# opentelemetry-api
# opentelemetry-semantic-conventions
dnspython==2.6.1
# via email-validator
email-validator==2.2.0
Expand All @@ -26,6 +30,8 @@ idna==3.10
# via
# email-validator
# yarl
importlib-metadata==8.5.0
# via opentelemetry-api
jinja2==3.1.4
# via
# -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
Expand Down Expand Up @@ -54,13 +60,28 @@ mdurl==0.1.2
# via markdown-it-py
multidict==6.1.0
# via yarl
opentelemetry-api==1.28.1
# via
# opentelemetry-instrumentation
# opentelemetry-instrumentation-asyncpg
# opentelemetry-semantic-conventions
opentelemetry-instrumentation==0.49b1
# via opentelemetry-instrumentation-asyncpg
opentelemetry-instrumentation-asyncpg==0.49b1
# via -r requirements/../../../packages/postgres-database/requirements/_base.in
opentelemetry-semantic-conventions==0.49b1
# via
# opentelemetry-instrumentation
# opentelemetry-instrumentation-asyncpg
orjson==3.10.7
# via
# -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/postgres-database/requirements/../../../requirements/constraints.txt
# -c requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
# -c requirements/../../../requirements/constraints.txt
# -r requirements/../../../packages/models-library/requirements/_base.in
packaging==24.2
# via opentelemetry-instrumentation
psycopg2-binary==2.9.9
# via sqlalchemy
pydantic==1.10.18
Expand Down Expand Up @@ -109,5 +130,11 @@ typing-extensions==4.12.2
# alembic
# pydantic
# typer
wrapt==1.16.0
# via
# deprecated
# opentelemetry-instrumentation
yarl==1.12.1
# via -r requirements/../../../packages/postgres-database/requirements/_base.in
zipp==3.21.0
# via importlib-metadata
3 changes: 2 additions & 1 deletion packages/notifications-library/requirements/_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ mypy==1.12.0
# via sqlalchemy
mypy-extensions==1.0.0
# via mypy
packaging==24.1
packaging==24.2
# via
# -c requirements/_base.txt
# pytest
# pytest-sugar
pluggy==1.5.0
Expand Down
3 changes: 2 additions & 1 deletion packages/notifications-library/requirements/_tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ mypy-extensions==1.0.0
# mypy
nodeenv==1.9.1
# via pre-commit
packaging==24.1
packaging==24.2
# via
# -c requirements/_base.txt
# -c requirements/_test.txt
# black
# build
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""add cancellation mark
Revision ID: 8bfe65a5e294
Revises: 5ad02358751a
Create Date: 2024-11-08 14:40:59.266181+00:00
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "8bfe65a5e294"
down_revision = "5ad02358751a"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"comp_runs", sa.Column("cancelled", sa.DateTime(timezone=True), nullable=True)
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("comp_runs", "cancelled")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
nullable=True,
doc="When the run was finished",
),
sa.Column(
"cancelled",
sa.DateTime(timezone=True),
nullable=True,
doc="If filled, when cancellation was requested",
),
sa.Column("metadata", JSONB, nullable=True, doc="the run optional metadata"),
sa.Column(
"use_on_demand_clusters",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def assemble_array_groups(user_group_ids: list[int]) -> str:
return (
"array[]::text[]"
if len(user_group_ids) == 0
else f"""array[{', '.join(f"'{group_id}'" for group_id in user_group_ids)}]"""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from simcore_postgres_database.models.groups import user_to_groups
from simcore_postgres_database.models.workspaces_access_rights import (
workspaces_access_rights,
)
from sqlalchemy import func
from sqlalchemy.dialects.postgresql import BOOLEAN, INTEGER
from sqlalchemy.sql import Subquery, select


def create_my_workspace_access_rights_subquery(user_id: int) -> Subquery:
return (
select(
workspaces_access_rights.c.workspace_id,
func.json_build_object(
"read",
func.max(workspaces_access_rights.c.read.cast(INTEGER)).cast(BOOLEAN),
"write",
func.max(workspaces_access_rights.c.write.cast(INTEGER)).cast(BOOLEAN),
"delete",
func.max(workspaces_access_rights.c.delete.cast(INTEGER)).cast(BOOLEAN),
).label("my_access_rights"),
)
.select_from(
workspaces_access_rights.join(
user_to_groups, user_to_groups.c.gid == workspaces_access_rights.c.gid
)
)
.where(user_to_groups.c.uid == user_id)
.group_by(workspaces_access_rights.c.workspace_id)
).subquery("my_workspace_access_rights_subquery")
2 changes: 0 additions & 2 deletions packages/service-library/requirements/_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ arrow==1.3.0
# via
# -r requirements/../../../packages/models-library/requirements/_base.in
# -r requirements/_base.in
async-timeout==4.0.3
# via redis
attrs==24.2.0
# via
# aiohttp
Expand Down
1 change: 1 addition & 0 deletions packages/service-library/requirements/_fastapi.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
fastapi
httpx
opentelemetry-instrumentation-fastapi
opentelemetry-instrumentation-httpx
prometheus-client
prometheus-fastapi-instrumentator
uvicorn
6 changes: 6 additions & 0 deletions packages/service-library/requirements/_fastapi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,29 @@ opentelemetry-api==1.27.0
# opentelemetry-instrumentation
# opentelemetry-instrumentation-asgi
# opentelemetry-instrumentation-fastapi
# opentelemetry-instrumentation-httpx
# opentelemetry-semantic-conventions
opentelemetry-instrumentation==0.48b0
# via
# opentelemetry-instrumentation-asgi
# opentelemetry-instrumentation-fastapi
# opentelemetry-instrumentation-httpx
opentelemetry-instrumentation-asgi==0.48b0
# via opentelemetry-instrumentation-fastapi
opentelemetry-instrumentation-fastapi==0.48b0
# via -r requirements/_fastapi.in
opentelemetry-instrumentation-httpx==0.48b0
# via -r requirements/_fastapi.in
opentelemetry-semantic-conventions==0.48b0
# via
# opentelemetry-instrumentation-asgi
# opentelemetry-instrumentation-fastapi
# opentelemetry-instrumentation-httpx
opentelemetry-util-http==0.48b0
# via
# opentelemetry-instrumentation-asgi
# opentelemetry-instrumentation-fastapi
# opentelemetry-instrumentation-httpx
prometheus-client==0.21.0
# via
# -r requirements/_fastapi.in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from httpx import AsyncClient, ConnectError, HTTPError, PoolTimeout, Response
from httpx._types import TimeoutTypes, URLTypes
from pydantic.errors import PydanticErrorMixin
from servicelib.fastapi.tracing import setup_httpx_client_tracing
from settings_library.tracing import TracingSettings
from tenacity import RetryCallState
from tenacity.asyncio import AsyncRetrying
from tenacity.before_sleep import before_sleep_log
Expand Down Expand Up @@ -201,6 +203,7 @@ def __init__(
base_url: URLTypes | None = None,
default_http_client_timeout: TimeoutTypes | None = None,
extra_allowed_method_names: set[str] | None = None,
tracing_settings: TracingSettings | None,
) -> None:
_assert_public_interface(self, extra_allowed_method_names)

Expand All @@ -220,7 +223,10 @@ def __init__(
if default_http_client_timeout:
client_args["timeout"] = default_http_client_timeout

super().__init__(client=AsyncClient(**client_args))
client = AsyncClient(**client_args)
if tracing_settings:
setup_httpx_client_tracing(client)
super().__init__(client=client)

async def __aenter__(self):
await self.setup_client()
Expand Down
Loading

0 comments on commit b537757

Please sign in to comment.