Skip to content

Commit b8c918b

Browse files
PR reviews
1 parent 8c00993 commit b8c918b

File tree

35 files changed

+545
-530
lines changed

35 files changed

+545
-530
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
""" Helper script to generate OAS automatically
2+
"""
3+
4+
# pylint: disable=redefined-outer-name
5+
# pylint: disable=unused-argument
6+
# pylint: disable=unused-variable
7+
# pylint: disable=too-many-arguments
8+
9+
from typing import Annotated
10+
11+
from _common import as_query
12+
from fastapi import APIRouter, Depends, status
13+
from models_library.api_schemas_webserver.licensed_items import LicensedItemGet
14+
from models_library.generics import Envelope
15+
from models_library.rest_error import EnvelopedError
16+
from simcore_service_webserver._meta import API_VTAG
17+
from simcore_service_webserver.catalog.licenses._exceptions_handlers import (
18+
_TO_HTTP_ERROR_MAP,
19+
)
20+
from simcore_service_webserver.catalog.licenses._models import (
21+
LicensedItemsBodyParams,
22+
LicensedItemsListQueryParams,
23+
LicensedItemsPathParams,
24+
)
25+
26+
router = APIRouter(
27+
prefix=f"/{API_VTAG}",
28+
tags=[
29+
"licenses",
30+
"catalog",
31+
],
32+
responses={
33+
i.status_code: {"model": EnvelopedError} for i in _TO_HTTP_ERROR_MAP.values()
34+
},
35+
)
36+
37+
38+
@router.get(
39+
"/catalog/licensed-items",
40+
response_model=Envelope[list[LicensedItemGet]],
41+
)
42+
async def list_licensed_items(
43+
_query: Annotated[as_query(LicensedItemsListQueryParams), Depends()],
44+
):
45+
...
46+
47+
48+
@router.get(
49+
"/catalog/licensed-items/{licensed_item_id}",
50+
response_model=Envelope[LicensedItemGet],
51+
)
52+
async def get_licensed_item(
53+
_path: Annotated[LicensedItemsPathParams, Depends()],
54+
):
55+
...
56+
57+
58+
@router.post(
59+
"/catalog/licensed-items/{licensed_item_id}", status_code=status.HTTP_204_NO_CONTENT
60+
)
61+
async def purchase_licensed_item(
62+
_path: Annotated[LicensedItemsPathParams, Depends()],
63+
_body: LicensedItemsBodyParams,
64+
):
65+
...

api/specs/web-server/_license_goods.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

api/specs/web-server/openapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
"_announcements",
3232
"_catalog",
3333
"_catalog_tags", # MUST BE after _catalog
34+
"_catalog_licensed_items",
3435
"_computations",
3536
"_exporter",
3637
"_folders",
3738
"_long_running_tasks",
38-
"_license_goods",
3939
"_metamodeling",
4040
"_nih_sparc",
4141
"_nih_sparc_redirections",

packages/aws-library/requirements/_base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ redis==5.0.4
307307
# -r requirements/../../../packages/service-library/requirements/_base.in
308308
referencing==0.29.3
309309
# via
310-
# -c requirements/../../../packages/service-library/requirements/./constraints.txt
311310
# jsonschema
312311
# jsonschema-specifications
313312
repro-zipfile==0.3.1
@@ -393,6 +392,7 @@ wrapt==1.16.0
393392
# opentelemetry-instrumentation-redis
394393
yarl==1.12.1
395394
# via
395+
# -r requirements/../../../packages/service-library/requirements/_base.in
396396
# aio-pika
397397
# aiohttp
398398
# aiormq
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
from datetime import datetime
22
from typing import NamedTuple
33

4-
from models_library.license_goods import LicenseGoodID, LicenseResourceType
4+
from models_library.licensed_items import LicensedItemID, LicensedResourceType
55
from models_library.resource_tracker import PricingPlanId
66
from pydantic import PositiveInt
77

88
from ._base import OutputSchema
99

1010

11-
class LicenseGoodGet(OutputSchema):
12-
license_good_id: LicenseGoodID
11+
class LicensedItemGet(OutputSchema):
12+
licensed_item_id: LicensedItemID
1313
name: str
14-
license_resource_type: LicenseResourceType
14+
license_resource_type: LicensedResourceType
1515
pricing_plan_id: PricingPlanId
1616
created_at: datetime
1717
modified_at: datetime
1818

1919

20-
class LicenseGoodGetPage(NamedTuple):
21-
items: list[LicenseGoodGet]
20+
class LicensedItemGetPage(NamedTuple):
21+
items: list[LicensedItemGet]
2222
total: PositiveInt

packages/models-library/src/models_library/license_goods.py renamed to packages/models-library/src/models_library/licensed_items.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from .resource_tracker import PricingPlanId
99
from .utils.enums import StrAutoEnum
1010

11-
LicenseGoodID: TypeAlias = str
11+
LicensedItemID: TypeAlias = str
1212

1313

14-
class LicenseResourceType(StrAutoEnum):
14+
class LicensedResourceType(StrAutoEnum):
1515
VIP_MODEL = auto()
1616

1717

@@ -20,10 +20,10 @@ class LicenseResourceType(StrAutoEnum):
2020
#
2121

2222

23-
class LicenseGoodDB(BaseModel):
24-
license_good_id: LicenseGoodID
23+
class LicensedItemDB(BaseModel):
24+
licensed_item_id: LicensedItemID
2525
name: str
26-
license_resource_type: LicenseResourceType
26+
license_resource_type: LicensedResourceType
2727
pricing_plan_id: PricingPlanId
2828
product_name: ProductName
2929
created: datetime = Field(
@@ -38,6 +38,6 @@ class LicenseGoodDB(BaseModel):
3838
model_config = ConfigDict(from_attributes=True)
3939

4040

41-
class LicenseGoodUpdateDB(BaseModel):
41+
class LicensedItemUpdateDB(BaseModel):
4242
name: str | None = None
4343
pricing_plan_id: PricingPlanId | None = None

packages/postgres-database/src/simcore_postgres_database/migration/versions/4901050f94f4_add_license_db_tables.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def upgrade():
2121
"resource_tracker_license_purchases",
2222
sa.Column("license_purchase_id", sa.String(), nullable=False),
2323
sa.Column("product_name", sa.String(), nullable=False),
24-
sa.Column("license_good_id", sa.BigInteger(), nullable=False),
24+
sa.Column("licensed_item_id", sa.BigInteger(), nullable=False),
2525
sa.Column("wallet_id", sa.BigInteger(), nullable=False),
2626
sa.Column(
2727
"start_at",
@@ -87,8 +87,8 @@ def upgrade():
8787
unique=False,
8888
)
8989
op.create_table(
90-
"license_goods",
91-
sa.Column("license_good_id", sa.String(), nullable=False),
90+
"licensed_items",
91+
sa.Column("licensed_item_id", sa.String(), nullable=False),
9292
sa.Column("name", sa.String(), nullable=False),
9393
sa.Column(
9494
"license_resource_type",
@@ -123,14 +123,14 @@ def upgrade():
123123
onupdate="CASCADE",
124124
ondelete="CASCADE",
125125
),
126-
sa.PrimaryKeyConstraint("license_good_id"),
126+
sa.PrimaryKeyConstraint("licensed_item_id"),
127127
)
128128
# ### end Alembic commands ###
129129

130130

131131
def downgrade():
132132
# ### commands auto generated by Alembic - please adjust! ###
133-
op.drop_table("license_goods")
133+
op.drop_table("licensed_items")
134134
op.drop_index(
135135
op.f("ix_resource_tracker_license_checkouts_wallet_id"),
136136
table_name="resource_tracker_license_checkouts",

packages/postgres-database/src/simcore_postgres_database/models/license_goods.py renamed to packages/postgres-database/src/simcore_postgres_database/models/licensed_items.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ def _custom_id_generator():
1414
return f"lgo_{shortuuid.uuid()}"
1515

1616

17-
class LicenseResourceType(str, enum.Enum):
17+
class LicensedResourceType(str, enum.Enum):
1818
VIP_MODEL = "VIP_MODEL"
1919

2020

21-
license_goods = sa.Table(
22-
"license_goods",
21+
licensed_items = sa.Table(
22+
"licensed_items",
2323
metadata,
2424
sa.Column(
25-
"license_good_id",
25+
"licensed_item_id",
2626
sa.String,
2727
nullable=False,
2828
primary_key=True,
@@ -34,8 +34,8 @@ class LicenseResourceType(str, enum.Enum):
3434
nullable=False,
3535
),
3636
sa.Column(
37-
"license_resource_type",
38-
sa.Enum(LicenseResourceType),
37+
"licensed_resource_type",
38+
sa.Enum(LicensedResourceType),
3939
nullable=False,
4040
doc="Item type, ex. VIP_MODEL",
4141
),

packages/postgres-database/src/simcore_postgres_database/models/resource_tracker_license_purchases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _custom_id_generator():
3030
doc="Product name",
3131
),
3232
sa.Column(
33-
"license_good_id",
33+
"licensed_item_id",
3434
sa.BigInteger,
3535
nullable=False,
3636
),

packages/postgres-database/src/simcore_postgres_database/utils_repos.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ async def pass_or_acquire_connection(
1212
engine: AsyncEngine, connection: AsyncConnection | None = None
1313
) -> AsyncIterator[AsyncConnection]:
1414
"""
15-
When to use: For READ operations only!
15+
When to use: For READ operations!
16+
It ensures that a connection is available for use within the context, either by using an existing connection passed as a parameter or by acquiring a new one from the engine. The caller must manage the lifecycle of any connection explicitly passed in, but the function handles the cleanup for connections it creates itself. This function **does not open new transactions** and therefore is recommended only for read-only database operations.
1617
"""
1718
# NOTE: When connection is passed, the engine is actually not needed
1819
# NOTE: Creator is responsible of closing connection
@@ -34,7 +35,8 @@ async def transaction_context(
3435
engine: AsyncEngine, connection: AsyncConnection | None = None
3536
):
3637
"""
37-
When to use: For WRITE operations only!
38+
When to use: For WRITE operations!
39+
This function manages the database connection and ensures that a transaction context is established for write operations. It supports both outer and nested transactions, providing flexibility for scenarios where transactions may already exist in the calling context.
3840
"""
3941
async with pass_or_acquire_connection(engine, connection) as conn:
4042
if conn.in_transaction():

0 commit comments

Comments
 (0)