diff --git a/src/dioptra/restapi/v1/workflows/controller.py b/src/dioptra/restapi/v1/workflows/controller.py index f10dc87c6..de3e22e6b 100644 --- a/src/dioptra/restapi/v1/workflows/controller.py +++ b/src/dioptra/restapi/v1/workflows/controller.py @@ -82,6 +82,40 @@ def get(self): ) +@api.route("/entrypointValidate") +class EntrypointValidateEndpoint(Resource): + @inject + def __init__( + self, entrypoint_validate_service: EntrypointValidateService, *args, **kwargs + ) -> None: + """Initialize the workflow resource. + + All arguments are provided via dependency injection. + + Args: + entrypoint_validate_service: A EntrypointValidateService object. + """ + self._entrypoint_validate_service = entrypoint_validate_service + super().__init__(*args, **kwargs) + + @login_required + @accepts(schema=EntrypointWorkflowSchema, api=api) + def post(self): + """Validates the workflow for a entrypoint.""" # noqa: B950 + log = LOGGER.new( + request_id=str(uuid.uuid4()), resource="Workflows", request_type="POST" + ) + parsed_obj = request.parsed_obj # type: ignore + task_graph = parsed_obj["task_graph"] + plugin_ids = parsed_obj["plugin_ids"] + parameters = parsed_obj["parameters"] + return self._entrypoint_validate_service.validate( + task_graph=task_graph, + plugin_ids=plugin_ids, + entrypoint_parameters=parameters, + log=log, + ) + @api.route("/entrypointValidate") class EntrypointValidateEndpoint(Resource): @inject diff --git a/src/dioptra/restapi/v1/workflows/schema.py b/src/dioptra/restapi/v1/workflows/schema.py index dda7ddabc..f4dc01ab2 100644 --- a/src/dioptra/restapi/v1/workflows/schema.py +++ b/src/dioptra/restapi/v1/workflows/schema.py @@ -21,6 +21,8 @@ from dioptra.restapi.v1.entrypoints.schema import EntrypointParameterSchema +from dioptra.restapi.v1.entrypoints.schema import EntrypointParameterSchema + class FileTypes(Enum): TAR_GZ = "tar_gz" @@ -89,3 +91,26 @@ class EntrypointWorkflowSchema(Schema): many=True, metadata=dict(description="List of parameters for the entrypoint."), ) + + +class EntrypointWorkflowSchema(Schema): + """The YAML that represents the Entrypoint Workflow.""" + + taskGraph = fields.String( + attribute="task_graph", + metadata=dict(description="Task graph of the Entrypoint resource."), + required=True, + ) + pluginIds = fields.List( + fields.Integer(), + attribute="plugin_ids", + data_key="plugins", + metadata=dict(description="List of plugin files for the entrypoint."), + load_only=True, + ) + parameters = fields.Nested( + EntrypointParameterSchema, + attribute="parameters", + many=True, + metadata=dict(description="List of parameters for the entrypoint."), + )