Skip to content

Commit

Permalink
Merge branch 'master' into upgrade-api-server-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis authored Dec 3, 2024
2 parents 3a9f368 + dfd1463 commit e6fcbed
Show file tree
Hide file tree
Showing 146 changed files with 7,286 additions and 2,195 deletions.
9 changes: 2 additions & 7 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,20 @@ parallel = True

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

exclude_also =
# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
if __name__ == __main__.:
class .*\bProtocol\):
# Don't complain about abstract methods, they aren't run:
@(abc\.)?abstract(((class|static)?method)|property)

# Don't complain about type checking
if TYPE_CHECKING:

Expand Down
2 changes: 1 addition & 1 deletion .env-devel
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ EFS_GROUP_NAME=efs-group
EFS_DNS_NAME=fs-xxx.efs.us-east-1.amazonaws.com
EFS_MOUNTED_PATH=/tmp/efs
EFS_PROJECT_SPECIFIC_DATA_DIRECTORY=project-specific-data
EFS_ONLY_ENABLED_FOR_USERIDS=[]
EFS_GUARDIAN_TRACING={}
EFS_DEFAULT_USER_SERVICE_SIZE_BYTES=10000

# DATCORE_ADAPTER
DATCORE_ADAPTER_TRACING={}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
from pathlib import Path

import jsonref
from common_library.json_serialization import json_dumps
from models_library.services import ServiceMetaDataPublished

CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent


if __name__ == "__main__":
with Path.open(CURRENT_DIR.parent / "node-meta-v0.0.1-pydantic.json", "w") as f:
schema = ServiceMetaDataPublished.schema_json()
schema = json_dumps(ServiceMetaDataPublished.model_json_schema())
schema_without_ref = jsonref.loads(schema)

json.dump(schema_without_ref, f, indent=2)
3 changes: 2 additions & 1 deletion api/specs/director/schemas/scripts/create_project-schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path

import jsonref
from common_library.json_serialization import json_dumps
from models_library.projects import Project

CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
Expand All @@ -17,7 +18,7 @@
with Path.open(
CURRENT_DIR.parent / "common/schemas/project-v0.0.1-pydantic.json", "w"
) as f:
schema = Project.schema_json()
schema = json_dumps(Project.model_json_schema())
schema_without_ref = jsonref.loads(schema)

json.dump(schema_without_ref, f, indent=2)
26 changes: 13 additions & 13 deletions api/specs/web-server/_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from typing import Any

from _common import Error, Log
from fastapi import APIRouter, status
from models_library.api_schemas_webserver.auth import (
AccountRequestInfo,
Expand All @@ -15,6 +14,7 @@
UnregisterCheck,
)
from models_library.generics import Envelope
from models_library.rest_error import EnvelopedError, Log
from pydantic import BaseModel, Field, confloat
from simcore_service_webserver._meta import API_VTAG
from simcore_service_webserver.login._2fa_handlers import Resend2faBody
Expand Down Expand Up @@ -75,7 +75,7 @@ async def register(_body: RegisterBody):
"/auth/unregister",
response_model=Envelope[Log],
status_code=status.HTTP_200_OK,
responses={status.HTTP_409_CONFLICT: {"model": Envelope[Error]}},
responses={status.HTTP_409_CONFLICT: {"model": EnvelopedError}},
)
async def unregister_account(_body: UnregisterCheck):
...
Expand Down Expand Up @@ -107,7 +107,7 @@ async def phone_confirmation(_body: PhoneConfirmationBody):
responses={
# status.HTTP_503_SERVICE_UNAVAILABLE
status.HTTP_401_UNAUTHORIZED: {
"model": Envelope[Error],
"model": EnvelopedError,
"description": "unauthorized reset due to invalid token code",
}
},
Expand All @@ -122,7 +122,7 @@ async def login(_body: LoginBody):
operation_id="auth_login_2fa",
responses={
status.HTTP_401_UNAUTHORIZED: {
"model": Envelope[Error],
"model": EnvelopedError,
"description": "unauthorized reset due to invalid token code",
}
},
Expand All @@ -137,7 +137,7 @@ async def login_2fa(_body: LoginTwoFactorAuthBody):
operation_id="auth_resend_2fa_code",
responses={
status.HTTP_401_UNAUTHORIZED: {
"model": Envelope[Error],
"model": EnvelopedError,
"description": "unauthorized reset due to invalid token code",
}
},
Expand All @@ -161,7 +161,7 @@ async def logout(_body: LogoutBody):
status_code=status.HTTP_204_NO_CONTENT,
responses={
status.HTTP_401_UNAUTHORIZED: {
"model": Envelope[Error],
"model": EnvelopedError,
"description": "unauthorized reset due to invalid token code",
}
},
Expand All @@ -174,7 +174,7 @@ async def check_auth():
"/auth/reset-password",
response_model=Envelope[Log],
operation_id="auth_reset_password",
responses={status.HTTP_503_SERVICE_UNAVAILABLE: {"model": Envelope[Error]}},
responses={status.HTTP_503_SERVICE_UNAVAILABLE: {"model": EnvelopedError}},
)
async def reset_password(_body: ResetPasswordBody):
"""a non logged-in user requests a password reset"""
Expand All @@ -186,7 +186,7 @@ async def reset_password(_body: ResetPasswordBody):
operation_id="auth_reset_password_allowed",
responses={
status.HTTP_401_UNAUTHORIZED: {
"model": Envelope[Error],
"model": EnvelopedError,
"description": "unauthorized reset due to invalid token code",
}
},
Expand All @@ -201,11 +201,11 @@ async def reset_password_allowed(code: str, _body: ResetPasswordConfirmation):
operation_id="auth_change_email",
responses={
status.HTTP_401_UNAUTHORIZED: {
"model": Envelope[Error],
"model": EnvelopedError,
"description": "unauthorized user. Login required",
},
status.HTTP_503_SERVICE_UNAVAILABLE: {
"model": Envelope[Error],
"model": EnvelopedError,
"description": "unable to send confirmation email",
},
},
Expand Down Expand Up @@ -233,15 +233,15 @@ class PasswordCheckSchema(BaseModel):
operation_id="auth_change_password",
responses={
status.HTTP_401_UNAUTHORIZED: {
"model": Envelope[Error],
"model": EnvelopedError,
"description": "unauthorized user. Login required",
},
status.HTTP_409_CONFLICT: {
"model": Envelope[Error],
"model": EnvelopedError,
"description": "mismatch between new and confirmation passwords",
},
status.HTTP_422_UNPROCESSABLE_ENTITY: {
"model": Envelope[Error],
"model": EnvelopedError,
"description": "current password is invalid",
},
},
Expand Down
54 changes: 17 additions & 37 deletions api/specs/web-server/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
import sys
from collections.abc import Callable
from pathlib import Path
from typing import Annotated, NamedTuple, Optional, Union, get_args, get_origin
from typing import (
Annotated,
Any,
Generic,
NamedTuple,
Optional,
TypeVar,
Union,
get_args,
get_origin,
)

from common_library.json_serialization import json_dumps
from common_library.pydantic_fields_extension import get_type
from fastapi import Query
from models_library.basic_types import LogLevel
from pydantic import BaseModel, ConfigDict, Field, Json, create_model
from pydantic import BaseModel, Json, create_model
from pydantic.fields import FieldInfo

CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
Expand Down Expand Up @@ -78,43 +87,14 @@ def as_query(model_class: type[BaseModel]) -> type[BaseModel]:
return create_model(new_model_name, **fields)


class Log(BaseModel):
level: LogLevel | None = Field("INFO", description="log level")
message: str = Field(
...,
description="log message. If logger is USER, then it MUST be human readable",
)
logger: str | None = Field(
None, description="name of the logger receiving this message"
)

model_config = ConfigDict(
json_schema_extra={
"example": {
"message": "Hi there, Mr user",
"level": "INFO",
"logger": "user-logger",
}
}
)

ErrorT = TypeVar("ErrorT")

class ErrorItem(BaseModel):
code: str = Field(
...,
description="Typically the name of the exception that produced it otherwise some known error code",
)
message: str = Field(..., description="Error message specific to this item")
resource: str | None = Field(
None, description="API resource affected by this error"
)
field: str | None = Field(None, description="Specific field within the resource")

class EnvelopeE(BaseModel, Generic[ErrorT]):
"""Complementary to models_library.generics.Envelope just for the generators"""

class Error(BaseModel):
logs: list[Log] | None = Field(None, description="log messages")
errors: list[ErrorItem] | None = Field(None, description="errors metadata")
status: int | None = Field(None, description="HTTP error code")
error: ErrorT | None = None
data: Any | None = None


class ParamSpec(NamedTuple):
Expand Down
5 changes: 5 additions & 0 deletions api/specs/web-server/_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
FolderReplaceBodyParams,
)
from models_library.generics import Envelope
from models_library.rest_error import EnvelopedError
from simcore_service_webserver._meta import API_VTAG
from simcore_service_webserver.folders._exceptions_handlers import _TO_HTTP_ERROR_MAP
from simcore_service_webserver.folders._models import (
FolderSearchQueryParams,
FoldersListQueryParams,
Expand All @@ -29,6 +31,9 @@
tags=[
"folders",
],
responses={
i.status_code: {"model": EnvelopedError} for i in _TO_HTTP_ERROR_MAP.values()
},
)


Expand Down
5 changes: 5 additions & 0 deletions api/specs/web-server/_workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
WorkspaceReplaceBodyParams,
)
from models_library.generics import Envelope
from models_library.rest_error import EnvelopedError
from simcore_service_webserver._meta import API_VTAG
from simcore_service_webserver.folders._exceptions_handlers import _TO_HTTP_ERROR_MAP
from simcore_service_webserver.workspaces._groups_api import WorkspaceGroupGet
from simcore_service_webserver.workspaces._models import (
WorkspacesGroupsBodyParams,
Expand All @@ -31,6 +33,9 @@
tags=[
"workspaces",
],
responses={
i.status_code: {"model": EnvelopedError} for i in _TO_HTTP_ERROR_MAP.values()
},
)


Expand Down
7 changes: 0 additions & 7 deletions packages/models-library/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ tests-ci: ## runs unit tests [ci-mode]
-m "not heavy_load" \
$(CURDIR)/tests

.PHONY: project-jsonschema.ignore.json
project-jsonschema.ignore.json: ## creates project-v0.0.1.json for DEV purposes
python3 -c "from models_library.projects import Project; print(Project.schema_json(indent=2))" > $@

.PHONY: service-jsonschema.ignore.json
node-meta-jsonschema.ignore.json: ## creates node-meta-v0.0.1.json for DEV purposes
python3 -c "from models_library.services import ServiceDockerData as cls; print(cls.schema_json(indent=2))" > $@

DOCKER_API_VERSION ?= 1.41
.PHONY: docker_rest_api.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
from copy import deepcopy
from typing import Any

from pydantic import schema_of
from pydantic import TypeAdapter

from ...projects_nodes import OutputID, OutputsDict
from ...services import ServiceMetaDataPublished, ServiceType
from ...services_constants import LATEST_INTEGRATION_VERSION
from .._key_labels import FUNCTION_SERVICE_KEY_PREFIX
from .._utils import EN, OM, FunctionServices, create_fake_thumbnail_url

LIST_NUMBERS_SCHEMA: dict[str, Any] = schema_of(list[float], title="list[number]")
LIST_NUMBERS_SCHEMA: dict[str, Any] = {
**TypeAdapter(list[float]).json_schema(),
"title": "list[number]",
}


META = ServiceMetaDataPublished.model_validate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

UUIDStr: TypeAlias = Annotated[str, StringConstraints(pattern=UUID_RE)]

NodeIDStr = UUIDStr
NodeIDStr: TypeAlias = UUIDStr

LocationID = int
LocationName = str
Expand Down
Loading

0 comments on commit e6fcbed

Please sign in to comment.