File tree Expand file tree Collapse file tree 4 files changed +48
-25
lines changed
services/api-server/src/simcore_service_api_server Expand file tree Collapse file tree 4 files changed +48
-25
lines changed Original file line number Diff line number Diff line change 1616from pydantic import HttpUrl
1717from servicelib .logging_utils import log_context
1818
19- from .exceptions .custom_errors import ServiceConfigurationError
2019from .models .schemas .jobs import Job , JobInputs
2120from .models .schemas .programs import Program
2221from .models .schemas .solvers import Solver
@@ -142,21 +141,3 @@ async def create_job(
142141 job_id = job .id ,
143142 )
144143 return job , new_project
145-
146-
147- def check_user_product_consistency (
148- service_cls_name : str ,
149- job_service : JobService ,
150- user_id : UserID ,
151- product_name : ProductName ,
152- ) -> None :
153- if user_id != job_service .user_id :
154- msg = f"User ID { user_id } does not match job service user ID { job_service .user_id } "
155- raise ServiceConfigurationError (
156- service_cls_name = service_cls_name , detail_msg = msg
157- )
158- if product_name != job_service .product_name :
159- msg = f"Product name { product_name } does not match job service product name { job_service .product_name } "
160- raise ServiceConfigurationError (
161- service_cls_name = service_cls_name , detail_msg = msg
162- )
Original file line number Diff line number Diff line change 1313from models_library .users import UserID
1414from pydantic import NonNegativeInt , PositiveInt
1515
16- from ._service_jobs import JobService , check_user_product_consistency
16+ from ._service_jobs import JobService
17+ from ._service_utils import check_user_product_consistency
1718from .exceptions .backend_errors import (
1819 ProgramOrSolverOrStudyNotFoundError ,
1920)
@@ -36,12 +37,18 @@ class SolverService:
3637 product_name : ProductName
3738
3839 def __post_init__ (self ):
39- # Context check
4040 check_user_product_consistency (
4141 service_cls_name = self .__class__ .__name__ ,
42+ service_provider = self .catalog_service ,
43+ user_id = self .user_id ,
44+ product_name = self .product_name ,
45+ )
46+
47+ check_user_product_consistency (
48+ service_cls_name = self .__class__ .__name__ ,
49+ service_provider = self .job_service ,
4250 user_id = self .user_id ,
4351 product_name = self .product_name ,
44- job_service = self .job_service ,
4552 )
4653
4754 async def get_solver (
Original file line number Diff line number Diff line change 99from models_library .rpc_pagination import PageLimitInt
1010from models_library .users import UserID
1111
12- from ._service_jobs import JobService , check_user_product_consistency
12+ from ._service_jobs import JobService
13+ from ._service_utils import check_user_product_consistency
1314from .models .api_resources import compose_resource_name
1415from .models .schemas .jobs import Job
1516from .models .schemas .studies import StudyID
@@ -24,12 +25,11 @@ class StudyService:
2425 product_name : ProductName
2526
2627 def __post_init__ (self ):
27- # Context check
2828 check_user_product_consistency (
2929 service_cls_name = self .__class__ .__name__ ,
30+ service_provider = self .job_service ,
3031 user_id = self .user_id ,
3132 product_name = self .product_name ,
32- job_service = self .job_service ,
3333 )
3434
3535 async def list_jobs (
Original file line number Diff line number Diff line change 1+ from typing import Protocol
2+
3+ from models_library .products import ProductName
4+ from models_library .users import UserID
5+
6+ from .exceptions .custom_errors import ServiceConfigurationError
7+
8+
9+ class UserProductProvider (Protocol ):
10+ """Protocol for classes that provide user_id and product_name properties."""
11+
12+ @property
13+ def user_id (self ) -> UserID : ...
14+
15+ @property
16+ def product_name (self ) -> ProductName : ...
17+
18+
19+ def check_user_product_consistency (
20+ service_cls_name : str ,
21+ service_provider : UserProductProvider ,
22+ user_id : UserID ,
23+ product_name : ProductName ,
24+ ) -> None :
25+
26+ if user_id != service_provider .user_id :
27+ msg = f"User ID { user_id } does not match { service_provider .__class__ .__name__ } user ID { service_provider .user_id } "
28+ raise ServiceConfigurationError (
29+ service_cls_name = service_cls_name , detail_msg = msg
30+ )
31+ if product_name != service_provider .product_name :
32+ msg = f"Product name { product_name } does not match { service_provider .__class__ .__name__ } product name { service_provider .product_name } "
33+ raise ServiceConfigurationError (
34+ service_cls_name = service_cls_name , detail_msg = msg
35+ )
You can’t perform that action at this time.
0 commit comments