Skip to content

Commit 9b7bd7c

Browse files
🎨 Require parent info headers when running function (#7900)
1 parent 5e3f6be commit 9b7bd7c

File tree

5 files changed

+2767
-50
lines changed

5 files changed

+2767
-50
lines changed

services/api-server/openapi.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7604,6 +7604,42 @@
76047604
"format": "uuid",
76057605
"title": "Function Id"
76067606
}
7607+
},
7608+
{
7609+
"name": "x-simcore-parent-project-uuid",
7610+
"in": "header",
7611+
"required": true,
7612+
"schema": {
7613+
"anyOf": [
7614+
{
7615+
"type": "string",
7616+
"format": "uuid"
7617+
},
7618+
{
7619+
"const": "null",
7620+
"type": "string"
7621+
}
7622+
],
7623+
"title": "X-Simcore-Parent-Project-Uuid"
7624+
}
7625+
},
7626+
{
7627+
"name": "x-simcore-parent-node-id",
7628+
"in": "header",
7629+
"required": true,
7630+
"schema": {
7631+
"anyOf": [
7632+
{
7633+
"type": "string",
7634+
"format": "uuid"
7635+
},
7636+
{
7637+
"const": "null",
7638+
"type": "string"
7639+
}
7640+
],
7641+
"title": "X-Simcore-Parent-Node-Id"
7642+
}
76077643
}
76087644
],
76097645
"requestBody": {
@@ -7700,6 +7736,42 @@
77007736
"format": "uuid",
77017737
"title": "Function Id"
77027738
}
7739+
},
7740+
{
7741+
"name": "x-simcore-parent-project-uuid",
7742+
"in": "header",
7743+
"required": true,
7744+
"schema": {
7745+
"anyOf": [
7746+
{
7747+
"type": "string",
7748+
"format": "uuid"
7749+
},
7750+
{
7751+
"const": "null",
7752+
"type": "string"
7753+
}
7754+
],
7755+
"title": "X-Simcore-Parent-Project-Uuid"
7756+
}
7757+
},
7758+
{
7759+
"name": "x-simcore-parent-node-id",
7760+
"in": "header",
7761+
"required": true,
7762+
"schema": {
7763+
"anyOf": [
7764+
{
7765+
"type": "string",
7766+
"format": "uuid"
7767+
},
7768+
{
7769+
"const": "null",
7770+
"type": "string"
7771+
}
7772+
],
7773+
"title": "X-Simcore-Parent-Node-Id"
7774+
}
77037775
}
77047776
],
77057777
"requestBody": {

services/api-server/src/simcore_service_api_server/api/routes/functions_routes.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
# pylint: disable=too-many-positional-arguments
12
from collections.abc import Callable
2-
from typing import Annotated, Final
3+
from typing import Annotated, Final, Literal
34

45
import jsonschema
5-
from fastapi import APIRouter, Depends, Request, status
6+
from fastapi import APIRouter, Depends, Header, Request, status
67
from fastapi_pagination.api import create_page
78
from jsonschema import ValidationError
89
from models_library.api_schemas_api_server.functions import (
@@ -29,6 +30,8 @@
2930
UnsupportedFunctionClassError,
3031
)
3132
from models_library.products import ProductName
33+
from models_library.projects import ProjectID
34+
from models_library.projects_nodes_io import NodeID
3235
from models_library.projects_state import RunningState
3336
from models_library.users import UserID
3437
from servicelib.fastapi.dependencies import get_reverse_url_mapper
@@ -372,8 +375,21 @@ async def run_function( # noqa: PLR0913
372375
product_name: Annotated[str, Depends(get_product_name)],
373376
solver_service: Annotated[SolverService, Depends(get_solver_service)],
374377
job_service: Annotated[JobService, Depends(get_job_service)],
378+
x_simcore_parent_project_uuid: Annotated[ProjectID | Literal["null"], Header()],
379+
x_simcore_parent_node_id: Annotated[NodeID | Literal["null"], Header()],
375380
) -> RegisteredFunctionJob:
376381

382+
parent_project_uuid = (
383+
x_simcore_parent_project_uuid
384+
if isinstance(x_simcore_parent_project_uuid, ProjectID)
385+
else None
386+
)
387+
parent_node_id = (
388+
x_simcore_parent_node_id
389+
if isinstance(x_simcore_parent_node_id, NodeID)
390+
else None
391+
)
392+
377393
# Make sure the user is allowed to execute any function
378394
# (read/write right is checked in the other endpoint called in this method)
379395
user_api_access_rights = await wb_api_rpc.get_functions_user_api_access_rights(
@@ -443,8 +459,8 @@ async def run_function( # noqa: PLR0913
443459
webserver_api=webserver_api,
444460
wb_api_rpc=wb_api_rpc,
445461
url_for=url_for,
446-
x_simcore_parent_project_uuid=None,
447-
x_simcore_parent_node_id=None,
462+
x_simcore_parent_project_uuid=parent_project_uuid,
463+
x_simcore_parent_node_id=parent_node_id,
448464
user_id=user_id,
449465
product_name=product_name,
450466
)
@@ -478,8 +494,8 @@ async def run_function( # noqa: PLR0913
478494
solver_service=solver_service,
479495
job_service=job_service,
480496
url_for=url_for,
481-
x_simcore_parent_project_uuid=None,
482-
x_simcore_parent_node_id=None,
497+
x_simcore_parent_project_uuid=parent_project_uuid,
498+
x_simcore_parent_node_id=parent_node_id,
483499
)
484500
await solvers_jobs.start_job(
485501
request=request,
@@ -558,6 +574,8 @@ async def map_function( # noqa: PLR0913
558574
product_name: Annotated[str, Depends(get_product_name)],
559575
solver_service: Annotated[SolverService, Depends(get_solver_service)],
560576
job_service: Annotated[JobService, Depends(get_job_service)],
577+
x_simcore_parent_project_uuid: Annotated[ProjectID | Literal["null"], Header()],
578+
x_simcore_parent_node_id: Annotated[NodeID | Literal["null"], Header()],
561579
) -> RegisteredFunctionJobCollection:
562580
function_jobs = []
563581
function_jobs = [
@@ -573,6 +591,8 @@ async def map_function( # noqa: PLR0913
573591
request=request,
574592
solver_service=solver_service,
575593
job_service=job_service,
594+
x_simcore_parent_project_uuid=x_simcore_parent_project_uuid,
595+
x_simcore_parent_node_id=x_simcore_parent_node_id,
576596
)
577597
for function_inputs in function_inputs_list
578598
]

0 commit comments

Comments
 (0)