diff --git a/crc/scripts/get_spec_from_workflow_id.py b/crc/scripts/get_spec_from_workflow_id.py new file mode 100644 index 00000000..78f16787 --- /dev/null +++ b/crc/scripts/get_spec_from_workflow_id.py @@ -0,0 +1,23 @@ +from crc import session +from crc.api.common import ApiError +from crc.models.workflow import WorkflowModel, WorkflowSpecModel, WorkflowSpecModelSchema +from crc.scripts.script import Script + + +class ScriptTemplate(Script): + + def get_description(self): + return """Get a workflow spec, from a workflow id. You must pass in a workflow id.""" + + def do_task_validate_only(self, task, study_id, workflow_id, *args, **kwargs): + return self.do_task(task, study_id, workflow_id, *args, **kwargs) + + def do_task(self, task, study_id, workflow_id, *args, **kwargs): + if len(args) < 1: + raise ApiError(code='missing_parameter', + message='Please pass in a workflow_id to use in the search.') + passed_workflow_id = args[0] + workflow = session.query(WorkflowModel).filter(WorkflowModel.id == passed_workflow_id).first() + workflow_spec = session.query(WorkflowSpecModel).filter(WorkflowSpecModel.id==workflow.workflow_spec_id).first() + if workflow_spec: + return WorkflowSpecModelSchema().dump(workflow_spec)