From 3873675b8673b347db634322d9e20f87715b97e4 Mon Sep 17 00:00:00 2001 From: Arash Date: Thu, 31 Oct 2024 15:00:23 +0100 Subject: [PATCH] add secrets into cwl and yml --- lib/galaxy/tool_util/cwl/parser.py | 3 +++ lib/galaxy/tool_util/deps/requirements.py | 9 ++++++--- lib/galaxy/tool_util/parser/cwl.py | 2 ++ lib/galaxy/tool_util/parser/yaml.py | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/tool_util/cwl/parser.py b/lib/galaxy/tool_util/cwl/parser.py index e4a4ff83fb20..d2deec42a874 100644 --- a/lib/galaxy/tool_util/cwl/parser.py +++ b/lib/galaxy/tool_util/cwl/parser.py @@ -219,6 +219,9 @@ def software_requirements(self) -> List: def resource_requirements(self) -> List: return self.hints_or_requirements_of_class("ResourceRequirement") + def secrets(self) -> List: + return self.hints_or_requirements_of_class("Secrets") + class CommandLineToolProxy(ToolProxy): _class = "CommandLineTool" diff --git a/lib/galaxy/tool_util/deps/requirements.py b/lib/galaxy/tool_util/deps/requirements.py index 3c1a51171f4d..7b74ec2575be 100644 --- a/lib/galaxy/tool_util/deps/requirements.py +++ b/lib/galaxy/tool_util/deps/requirements.py @@ -339,13 +339,14 @@ def to_dict(self) -> Dict[str, Any]: "required": self.required, } - def from_dict(self, dict: Dict[str, Any]) -> "SecretsRequirement": + @classmethod + def from_dict(cls, dict: Dict[str, Any]) -> "SecretsRequirement": type = dict["type"] user_preferences_key = dict["user_preferences_key"] inject_as_env = dict["inject_as_env"] label = dict.get("label", "") required = dict.get("required", False) - return SecretsRequirement( + return cls( type=type, user_preferences_key=user_preferences_key, inject_as_env=inject_as_env, @@ -358,11 +359,13 @@ def parse_requirements_from_lists( software_requirements: List[Union[ToolRequirement, Dict[str, Any]]], containers: Iterable[Dict[str, Any]], resource_requirements: Iterable[Dict[str, Any]], -) -> Tuple[ToolRequirements, List[ContainerDescription], List[ResourceRequirement]]: + secrets: Iterable[Dict[str, Any]], +) -> Tuple[ToolRequirements, List[ContainerDescription], List[ResourceRequirement], List[SecretsRequirement]]: return ( ToolRequirements.from_list(software_requirements), [ContainerDescription.from_dict(c) for c in containers], resource_requirements_from_list(resource_requirements), + [SecretsRequirement.from_dict(s) for s in secrets], ) diff --git a/lib/galaxy/tool_util/parser/cwl.py b/lib/galaxy/tool_util/parser/cwl.py index 26d2fdfdc16c..171ab7ce817f 100644 --- a/lib/galaxy/tool_util/parser/cwl.py +++ b/lib/galaxy/tool_util/parser/cwl.py @@ -162,10 +162,12 @@ def parse_requirements_and_containers(self): software_requirements = self.tool_proxy.software_requirements() resource_requirements = self.tool_proxy.resource_requirements() + secrets = self.tool_proxy.secrets() return requirements.parse_requirements_from_lists( software_requirements=[{"name": r[0], "version": r[1], "type": "package"} for r in software_requirements], containers=containers, resource_requirements=resource_requirements, + secrets=secrets, ) def parse_profile(self): diff --git a/lib/galaxy/tool_util/parser/yaml.py b/lib/galaxy/tool_util/parser/yaml.py index c2e6352384c0..b78b36dd6116 100644 --- a/lib/galaxy/tool_util/parser/yaml.py +++ b/lib/galaxy/tool_util/parser/yaml.py @@ -111,6 +111,7 @@ def parse_requirements_and_containers(self): software_requirements=[r for r in mixed_requirements if r.get("type") != "resource"], containers=self.root_dict.get("containers", []), resource_requirements=[r for r in mixed_requirements if r.get("type") == "resource"], + secrets=self.root_dict.get("secrets", []), ) def parse_input_pages(self) -> PagesSource: