Skip to content

Commit

Permalink
Refactor credential classes (Variable and Secret) to inherit from Bas…
Browse files Browse the repository at this point in the history
…eCredential class
  • Loading branch information
arash77 committed Dec 3, 2024
1 parent f13b77d commit dedb684
Showing 1 changed file with 7 additions and 40 deletions.
47 changes: 7 additions & 40 deletions lib/galaxy/tool_util/deps/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
Expand All @@ -339,53 +339,20 @@ 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", "")
description = dict.get("description", "")
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:
Expand Down

0 comments on commit dedb684

Please sign in to comment.