From dedb684494f2c9df32235e721749f90fdd3b0fbe Mon Sep 17 00:00:00 2001 From: Arash Date: Tue, 3 Dec 2024 17:33:38 +0100 Subject: [PATCH] Refactor credential classes (Variable and Secret) to inherit from BaseCredential class --- lib/galaxy/tool_util/deps/requirements.py | 47 ++++------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/lib/galaxy/tool_util/deps/requirements.py b/lib/galaxy/tool_util/deps/requirements.py index b77566cc3cd9..5cc24b111fea 100644 --- a/lib/galaxy/tool_util/deps/requirements.py +++ b/lib/galaxy/tool_util/deps/requirements.py @@ -306,7 +306,7 @@ def resource_requirements_from_list(requirements: Iterable[Dict[str, Any]]) -> L return rr -class Secret: +class BaseCredential: def __init__( self, name: str, @@ -330,7 +330,7 @@ def to_dict(self) -> Dict[str, Any]: } @classmethod - def from_element(cls, elem) -> "Secret": + def from_element(cls, elem) -> "BaseCredential": return cls( name=elem.get("name"), inject_as_env=elem.get("inject_as_env"), @@ -339,7 +339,7 @@ def from_element(cls, elem) -> "Secret": ) @classmethod - def from_dict(cls, dict: Dict[str, Any]) -> "Secret": + def from_dict(cls, dict: Dict[str, Any]) -> "BaseCredential": name = dict["name"] inject_as_env = dict["inject_as_env"] label = dict.get("label", "") @@ -347,45 +347,12 @@ def from_dict(cls, dict: Dict[str, Any]) -> "Secret": return cls(name=name, inject_as_env=inject_as_env, label=label, description=description) -class Variable: - def __init__( - self, - name: str, - inject_as_env: str, - label: str = "", - description: str = "", - ) -> None: - self.name = name - self.inject_as_env = inject_as_env - self.label = label - self.description = description - if not self.inject_as_env: - raise ValueError("Missing inject_as_env") - - def to_dict(self) -> Dict[str, Any]: - return { - "name": self.name, - "inject_as_env": self.inject_as_env, - "label": self.label, - "description": self.description, - } +class Secret(BaseCredential): + pass - @classmethod - def from_element(cls, elem) -> "Variable": - return cls( - name=elem.get("name"), - inject_as_env=elem.get("inject_as_env"), - label=elem.get("label", ""), - description=elem.get("description", ""), - ) - @classmethod - def from_dict(cls, dict: Dict[str, Any]) -> "Variable": - name = dict["name"] - inject_as_env = dict["inject_as_env"] - label = dict.get("label", "") - description = dict.get("description", "") - return cls(name=name, inject_as_env=inject_as_env, label=label, description=description) +class Variable(BaseCredential): + pass class CredentialsRequirement: