diff --git a/seqerakit/cli.py b/seqerakit/cli.py index f3e1b80..4366114 100644 --- a/seqerakit/cli.py +++ b/seqerakit/cli.py @@ -169,6 +169,7 @@ def main(args=None): [ "organizations", # all use method.add "workspaces", + "labels", "credentials", "secrets", "actions", diff --git a/seqerakit/helper.py b/seqerakit/helper.py index 0b71311..274638d 100644 --- a/seqerakit/helper.py +++ b/seqerakit/helper.py @@ -82,6 +82,7 @@ def parse_all_yaml(file_paths, destroy=False): "organizations", "teams", "workspaces", + "labels", "participants", "credentials", "compute-envs", diff --git a/seqerakit/overwrite.py b/seqerakit/overwrite.py index 7a18562..44fcd62 100644 --- a/seqerakit/overwrite.py +++ b/seqerakit/overwrite.py @@ -60,6 +60,11 @@ def __init__(self, sp): "method_args": self._get_organization_args, "name_key": "orgName", }, + "labels": { + "keys": ["name", "value", "workspace"], + "method_args": self._get_label_args, + "name_key": "name", + }, "teams": { "keys": ["name", "organization"], "method_args": self._get_team_args, @@ -171,6 +176,15 @@ def _get_workspace_args(self, args): workspace_id = self._find_workspace_id(args["organization"], args["name"]) return ("delete", "--id", str(workspace_id)) + def _get_label_args(self, args): + """ + Returns a list of arguments for the delete() method for labels. The + label_id used to delete will be retrieved using the _find_label_id() + method. + """ + label_id = self._find_label_id(args["name"], args["value"]) + return ("delete", "--id", str(label_id), "-w", args["workspace"]) + def _get_generic_deletion_args(self, args): """ Returns a list of arguments for the delete() method for resources that @@ -210,7 +224,10 @@ def _get_json_data(self, block, args, keys_to_get): self.cached_jsondata = json_method( block, "list", "-o", sp_args["organization"] ) - elif block in Overwrite.generic_deletion or block == "participants": + elif block in Overwrite.generic_deletion or block in { + "participants", + "labels", + }: sp_args = self._get_values_from_cmd_args(args, keys_to_get) self.cached_jsondata = json_method( block, "list", "-w", sp_args["workspace"] @@ -271,3 +288,15 @@ def _find_workspace_id(self, organization, workspace_name): ): return workspace.get("workspaceId") return None + + def _find_label_id(self, label_name, label_value): + """ + Custom method to find a label ID in a nested dictionary with a given + workspace name. This ID will be used to delete the label. + """ + jsondata = json.loads(self.cached_jsondata) + labels = jsondata["labels"] + for label in labels: + if label.get("name") == label_name and label.get("value") == label_value: + return label.get("id") + return None diff --git a/templates/labels.yml b/templates/labels.yml new file mode 100644 index 0000000..6a75adb --- /dev/null +++ b/templates/labels.yml @@ -0,0 +1,6 @@ +## To see the full list of options available run: "tw labels add" +labels: + - name: 'label_name' # required + value: 'label_value' # required + workspace: 'my_organization/my_workspace' # required + overwrite: True # optional