Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ async def batch_get_user_services(

Raises:
CatalogItemNotFoundError: When no services are found at all
ValidationError: if the ids are empty
"""
unique_service_identifiers = _BatchIdsValidator.validate_python(ids)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ServiceOutputGet,
ServiceOutputKey,
)
from models_library.batch_operations import create_batch_ids_validator
from models_library.products import ProductName
from models_library.rest_pagination import (
PageLimitInt,
Expand All @@ -25,6 +26,7 @@
from models_library.users import UserID
from models_library.utils.fastapi_encoders import jsonable_encoder
from pint import UnitRegistry
from pydantic import ValidationError
from servicelib.rabbitmq._errors import RPCServerError
from servicelib.rabbitmq.rpc_interfaces.catalog import services as catalog_rpc
from servicelib.rabbitmq.rpc_interfaces.catalog.errors import (
Expand Down Expand Up @@ -94,6 +96,11 @@ async def list_latest_services(
return page_data, page.meta


_BatchServicesIdsValidator = create_batch_ids_validator(
tuple[ServiceKey, ServiceVersion]
)


async def batch_get_my_services(
app: web.Application,
*,
Expand All @@ -102,12 +109,17 @@ async def batch_get_my_services(
services_ids: list[tuple[ServiceKey, ServiceVersion]],
) -> MyServicesBatchGetResult:
try:
ids = _BatchServicesIdsValidator.validate_python(services_ids)
except ValidationError as err:
msg = f"Invalid 'service_ids' parameter:\n{err}"
raise ValueError(msg) from err

try:
return await catalog_rpc.batch_get_my_services(
get_rabbitmq_rpc_client(app),
user_id=user_id,
product_name=product_name,
ids=services_ids,
ids=ids,
)

except RPCServerError as err:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,28 +546,32 @@ async def get_project_services(request: web.Request) -> web.Response:
)
)

batch_got = await catalog_service.batch_get_my_services(
request.app,
product_name=req_ctx.product_name,
user_id=req_ctx.user_id,
services_ids=services_in_project,
)
services = []
missing = None

if services_in_project:
batch_got = await catalog_service.batch_get_my_services(
request.app,
product_name=req_ctx.product_name,
user_id=req_ctx.user_id,
services_ids=services_in_project,
)
services = [
NodeServiceGet.model_validate(sv, from_attributes=True)
for sv in batch_got.found_items
]
missing = (
[
ServiceKeyVersion(key=k, version=v)
for k, v in batch_got.missing_identifiers
]
if batch_got.missing_identifiers
else None
)

return envelope_json_response(
ProjectNodeServicesGet(
project_uuid=path_params.project_id,
services=[
NodeServiceGet.model_validate(sv, from_attributes=True)
for sv in batch_got.found_items
],
missing=(
[
ServiceKeyVersion(key=k, version=v)
for k, v in batch_got.missing_identifiers
]
if batch_got.missing_identifiers
else None
),
project_uuid=path_params.project_id, services=services, missing=missing
)
)

Expand Down
Loading