@@ -34,6 +34,7 @@ class Overwrite:
3434 "datasets" ,
3535 "actions" ,
3636 "pipelines" ,
37+ "studios" ,
3738 ]
3839
3940 def __init__ (self , sp ):
@@ -62,7 +63,7 @@ def __init__(self, sp):
6263 },
6364 "labels" : {
6465 "keys" : ["name" , "value" , "workspace" ],
65- "method_args" : self ._get_label_args ,
66+ "method_args" : lambda args : self ._get_id_resource_args ( "labels" , args ) ,
6667 "name_key" : "name" ,
6768 },
6869 "members" : {
@@ -85,6 +86,13 @@ def __init__(self, sp):
8586 "method_args" : self ._get_workspace_args ,
8687 "name_key" : "workspaceName" ,
8788 },
89+ "data-links" : {
90+ "keys" : ["name" , "workspace" ],
91+ "method_args" : lambda args : self ._get_id_resource_args (
92+ "data-links" , args
93+ ),
94+ "name_key" : "name" ,
95+ },
8896 }
8997
9098 def handle_overwrite (self , block , args , overwrite = False , destroy = False ):
@@ -197,14 +205,17 @@ def _get_workspace_args(self, args):
197205 workspace_id = self ._find_workspace_id (args ["organization" ], args ["name" ])
198206 return ("delete" , "--id" , str (workspace_id ))
199207
200- def _get_label_args (self , args ):
208+ def _get_id_resource_args (self , resource_type , args ):
201209 """
202210 Returns a list of arguments for the delete() method for labels. The
203- label_id used to delete will be retrieved using the _find_label_id()
204- method.
211+ label_id used to delete will be retrieved using the _find_id() method.
205212 """
206- label_id = self ._find_label_id (args ["name" ], args ["value" ])
207- return ("delete" , "--id" , str (label_id ), "-w" , args ["workspace" ])
213+ if resource_type == "labels" :
214+ resource_id = self ._find_id (resource_type , args ["name" ], args ["value" ])
215+ else : # data-links
216+ resource_id = self ._find_id (resource_type , args ["name" ])
217+
218+ return ("delete" , "--id" , str (resource_id ), "-w" , args ["workspace" ])
208219
209220 def _get_generic_deletion_args (self , args ):
210221 """
@@ -252,6 +263,7 @@ def _get_json_data(self, block, args, keys_to_get):
252263 elif block in Overwrite .generic_deletion or block in {
253264 "participants" ,
254265 "labels" ,
266+ "data-links" ,
255267 }:
256268 sp_args = self ._get_values_from_cmd_args (args , keys_to_get )
257269 with self .sp .suppress_output ():
@@ -326,16 +338,41 @@ def _find_workspace_id(self, organization, workspace_name):
326338 return workspace_id
327339 return None
328340
329- def _find_label_id (self , label_name , label_value ):
341+ def _find_id (self , resource_type , name , value = None ):
330342 """
331- Custom method to find a label ID in a nested dictionary with a given
332- workspace name. This ID will be used to delete the label.
343+ Finds the unique identifier (ID) for a Seqera Platform resource by searching
344+ through the cached JSON data. This method is necessary because certain Platform
345+ resources must be deleted using their ID rather than their name.
346+
347+ Args:
348+ resource_type (str): Type of resource to search for. Currently supports:
349+ - 'labels': Platform labels that require both name and value matching
350+ - 'data-links': Data link resources that only require name matching
351+ name (str): Name of the resource to find
352+ value (str, optional): For labels only, the value field that must match
353+ along with the name. Defaults to None for non-label resources.
354+
355+ Returns:
356+ str: The unique identifier (ID) of the matching resource if found
357+ None: If no matching resource is found
358+
359+ Note:
360+ - For labels, both name and value must match to find the correct ID
361+ - For data-links, only the name needs to match
362+ - The method uses cached JSON data from previous API calls to avoid
363+ redundant requests to the Platform
333364 """
334365 jsondata = json .loads (self .cached_jsondata )
335- labels = jsondata ["labels" ]
336- for label in labels :
337- if label .get ("name" ) == utils .resolve_env_var (label_name ) and label .get (
338- "value"
339- ) == utils .resolve_env_var (label_value ):
340- return label .get ("id" )
366+ json_key = "dataLinks" if resource_type == "data-links" else resource_type
367+ resources = jsondata [json_key ]
368+
369+ for resource in resources :
370+ if resource_type == "labels" :
371+ if resource .get ("name" ) == utils .resolve_env_var (name ) and resource .get (
372+ "value"
373+ ) == utils .resolve_env_var (value ):
374+ return resource .get ("id" )
375+ elif resource_type == "data-links" :
376+ if resource .get ("name" ) == utils .resolve_env_var (name ):
377+ return resource .get ("id" )
341378 return None
0 commit comments