Skip to content

Commit

Permalink
Merge branch 'master' into 6865-ensure-backwards-compatibility-of-api…
Browse files Browse the repository at this point in the history
…-server
  • Loading branch information
bisgaard-itis committed Dec 5, 2024
2 parents 9f20961 + e05d046 commit cc17b2e
Show file tree
Hide file tree
Showing 31 changed files with 1,424 additions and 28 deletions.
66 changes: 66 additions & 0 deletions api/specs/web-server/_catalog_licensed_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
""" Helper script to generate OAS automatically
"""

# pylint: disable=redefined-outer-name
# pylint: disable=unused-argument
# pylint: disable=unused-variable
# pylint: disable=too-many-arguments

from typing import Annotated

from _common import as_query
from fastapi import APIRouter, Depends, status
from models_library.api_schemas_webserver.licensed_items import LicensedItemGet
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.catalog.licenses._exceptions_handlers import (
_TO_HTTP_ERROR_MAP,
)
from simcore_service_webserver.catalog.licenses._models import (
LicensedItemsBodyParams,
LicensedItemsListQueryParams,
LicensedItemsPathParams,
)

router = APIRouter(
prefix=f"/{API_VTAG}",
tags=[
"licenses",
"catalog",
],
responses={
i.status_code: {"model": EnvelopedError} for i in _TO_HTTP_ERROR_MAP.values()
},
)


@router.get(
"/catalog/licensed-items",
response_model=Envelope[list[LicensedItemGet]],
)
async def list_licensed_items(
_query: Annotated[as_query(LicensedItemsListQueryParams), Depends()],
):
...


@router.get(
"/catalog/licensed-items/{licensed_item_id}",
response_model=Envelope[LicensedItemGet],
)
async def get_licensed_item(
_path: Annotated[LicensedItemsPathParams, Depends()],
):
...


@router.post(
"/catalog/licensed-items/{licensed_item_id}:purchase",
status_code=status.HTTP_204_NO_CONTENT,
)
async def purchase_licensed_item(
_path: Annotated[LicensedItemsPathParams, Depends()],
_body: LicensedItemsBodyParams,
):
...
1 change: 1 addition & 0 deletions api/specs/web-server/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"_announcements",
"_catalog",
"_catalog_tags", # MUST BE after _catalog
"_catalog_licensed_items",
"_computations",
"_exporter",
"_folders",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from datetime import datetime
from typing import NamedTuple

from models_library.licensed_items import LicensedItemID, LicensedResourceType
from models_library.resource_tracker import PricingPlanId
from pydantic import PositiveInt

from ._base import OutputSchema


class LicensedItemGet(OutputSchema):
licensed_item_id: LicensedItemID
name: str
licensed_resource_type: LicensedResourceType
pricing_plan_id: PricingPlanId
created_at: datetime
modified_at: datetime


class LicensedItemGetPage(NamedTuple):
items: list[LicensedItemGet]
total: PositiveInt
44 changes: 44 additions & 0 deletions packages/models-library/src/models_library/licensed_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from datetime import datetime
from enum import auto
from typing import TypeAlias
from uuid import UUID

from pydantic import BaseModel, ConfigDict, Field

from .products import ProductName
from .resource_tracker import PricingPlanId
from .utils.enums import StrAutoEnum

LicensedItemID: TypeAlias = UUID


class LicensedResourceType(StrAutoEnum):
VIP_MODEL = auto()


#
# DB
#


class LicensedItemDB(BaseModel):
licensed_item_id: LicensedItemID
name: str
licensed_resource_type: LicensedResourceType
pricing_plan_id: PricingPlanId
product_name: ProductName
created: datetime = Field(
...,
description="Timestamp on creation",
)
modified: datetime = Field(
...,
description="Timestamp of last modification",
)
# ----
model_config = ConfigDict(from_attributes=True)


class LicensedItemUpdateDB(BaseModel):
name: str | None = None
pricing_plan_id: PricingPlanId | None = None
2 changes: 1 addition & 1 deletion packages/postgres-database/requirements/_base.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
--requirement ../../../packages/common-library/requirements/_base.in

alembic
opentelemetry-instrumentation-asyncpg
pydantic
sqlalchemy[postgresql_psycopg2binary,postgresql_asyncpg] # SEE extras in https://github.com/sqlalchemy/sqlalchemy/blob/main/setup.cfg#L43
opentelemetry-instrumentation-asyncpg
yarl
2 changes: 1 addition & 1 deletion packages/postgres-database/requirements/_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pydantic-core==2.27.1
# via pydantic
pydantic-extra-types==2.10.0
# via -r requirements/../../../packages/common-library/requirements/_base.in
setuptools==75.2.0
setuptools==75.6.0
# via opentelemetry-instrumentation
sqlalchemy==1.4.54
# via
Expand Down
2 changes: 1 addition & 1 deletion packages/postgres-database/requirements/_migration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ certifi==2024.8.30
# via
# -c requirements/../../../requirements/constraints.txt
# requests
charset-normalizer==3.3.2
charset-normalizer==3.4.0
# via requests
click==8.1.7
# via -r requirements/_migration.in
Expand Down
17 changes: 9 additions & 8 deletions packages/postgres-database/requirements/_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ async-timeout==4.0.3
# aiopg
attrs==24.2.0
# via pytest-docker
coverage==7.6.1
coverage==7.6.8
# via
# -r requirements/_test.in
# pytest-cov
faker==29.0.0
faker==33.1.0
# via -r requirements/_test.in
greenlet==3.1.1
# via
Expand All @@ -19,11 +19,11 @@ greenlet==3.1.1
# sqlalchemy
iniconfig==2.0.0
# via pytest
mypy==1.12.0
mypy==1.13.0
# via sqlalchemy
mypy-extensions==1.0.0
# via mypy
packaging==24.1
packaging==24.2
# via pytest
pluggy==1.5.0
# via pytest
Expand All @@ -32,7 +32,7 @@ psycopg2-binary==2.9.9
# -c requirements/_base.txt
# aiopg
# sqlalchemy
pytest==8.3.3
pytest==8.3.4
# via
# -r requirements/_test.in
# pytest-asyncio
Expand All @@ -43,7 +43,7 @@ pytest-asyncio==0.23.8
# via
# -c requirements/../../../requirements/constraints.txt
# -r requirements/_test.in
pytest-cov==5.0.0
pytest-cov==6.0.0
# via -r requirements/_test.in
pytest-docker==3.1.1
# via -r requirements/_test.in
Expand All @@ -70,14 +70,15 @@ sqlalchemy2-stubs==0.0.2a38
# via sqlalchemy
types-docker==7.1.0.20240827
# via -r requirements/_test.in
types-psycopg2==2.9.21.20240819
types-psycopg2==2.9.21.20241019
# via -r requirements/_test.in
types-requests==2.32.0.20240914
types-requests==2.32.0.20241016
# via types-docker
typing-extensions==4.12.2
# via
# -c requirements/_base.txt
# -c requirements/_migration.txt
# faker
# mypy
# sqlalchemy2-stubs
urllib3==2.2.3
Expand Down
32 changes: 16 additions & 16 deletions packages/postgres-database/requirements/_tools.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
astroid==3.3.4
astroid==3.3.5
# via pylint
black==24.8.0
black==24.10.0
# via -r requirements/../../../requirements/devenv.txt
build==1.2.2
build==1.2.2.post1
# via pip-tools
bump2version==1.0.1
# via -r requirements/../../../requirements/devenv.txt
Expand All @@ -12,21 +12,21 @@ click==8.1.7
# via
# black
# pip-tools
dill==0.3.8
dill==0.3.9
# via pylint
distlib==0.3.8
distlib==0.3.9
# via virtualenv
filelock==3.16.1
# via virtualenv
identify==2.6.1
identify==2.6.3
# via pre-commit
isort==5.13.2
# via
# -r requirements/../../../requirements/devenv.txt
# pylint
mccabe==0.7.0
# via pylint
mypy==1.12.0
mypy==1.13.0
# via
# -c requirements/_test.txt
# -r requirements/../../../requirements/devenv.txt
Expand All @@ -37,14 +37,14 @@ mypy-extensions==1.0.0
# mypy
nodeenv==1.9.1
# via pre-commit
packaging==24.1
packaging==24.2
# via
# -c requirements/_test.txt
# black
# build
pathspec==0.12.1
# via black
pip==24.2
pip==24.3.1
# via pip-tools
pip-tools==7.4.1
# via -r requirements/../../../requirements/devenv.txt
Expand All @@ -53,11 +53,11 @@ platformdirs==4.3.6
# black
# pylint
# virtualenv
pre-commit==3.8.0
pre-commit==4.0.1
# via -r requirements/../../../requirements/devenv.txt
pylint==3.3.0
pylint==3.3.2
# via -r requirements/../../../requirements/devenv.txt
pyproject-hooks==1.1.0
pyproject-hooks==1.2.0
# via
# build
# pip-tools
Expand All @@ -66,9 +66,9 @@ pyyaml==6.0.2
# -c requirements/../../../requirements/constraints.txt
# -c requirements/_test.txt
# pre-commit
ruff==0.6.7
ruff==0.8.1
# via -r requirements/../../../requirements/devenv.txt
setuptools==75.2.0
setuptools==75.6.0
# via
# -c requirements/_base.txt
# pip-tools
Expand All @@ -79,7 +79,7 @@ typing-extensions==4.12.2
# -c requirements/_base.txt
# -c requirements/_test.txt
# mypy
virtualenv==20.26.5
virtualenv==20.28.0
# via pre-commit
wheel==0.44.0
wheel==0.45.1
# via pip-tools
Loading

0 comments on commit cc17b2e

Please sign in to comment.