@@ -91,59 +91,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
9191 return cls ._args_schema
9292
9393 def _execute_operations (self ):
94- # Call pre_operations first to allow custom class to set managed_cluster
9594 self .pre_operations ()
96-
97- # Check if Deployment Safeguards already exists before attempting create
98- from azure .cli .core .util import send_raw_request
99- from azure .cli .core .azclierror import HTTPError
100- from knack .util import CLIError
101-
102- # Get the resource URI - check if managed_cluster is set, otherwise build from -g/-n
103- resource_uri = None
104-
105- # If managed_cluster is not set, build from resource_group and cluster_name
106- if has_value (self .ctx .args .managed_cluster ):
107- resource_uri = self .ctx .args .managed_cluster .to_serialized_data ()
108- else :
109- # Access resource_group and cluster_name from arguments
110- resource_group = getattr (self .ctx .args , "resource_group" , None )
111- cluster_name = getattr (self .ctx .args , "cluster_name" , None )
112- if resource_group and cluster_name :
113- subscription = self .ctx .subscription_id
114- resource_uri = f"/subscriptions/{ subscription } /resourceGroups/{ resource_group } /providers/Microsoft.ContainerService/managedClusters/{ cluster_name } "
115-
116- if not resource_uri :
117- raise CLIError ("Resource URI not found. Please provide either --managed-cluster or both --resource-group and --name." )
118-
119- # Validate resource_uri format to prevent URL injection
120- if not resource_uri .startswith ('/subscriptions/' ):
121- raise CLIError (f"Invalid managed cluster resource ID format: { resource_uri } " )
122-
123- # Construct the GET URL to check if resource already exists
124- safeguards_url = f"https://management.azure.com{ resource_uri } /providers/Microsoft.ContainerService/deploymentSafeguards/default?api-version=2025-05-02-preview"
125-
126- # Check if resource already exists
127- resource_exists = False
128- try :
129- response = send_raw_request (self .ctx .cli_ctx , "GET" , safeguards_url )
130- if response .status_code == 200 :
131- resource_exists = True
132- except HTTPError as ex :
133- # 404 means resource doesn't exist, which is expected for create
134- if ex .response .status_code != 404 :
135- # Re-raise if it's not a 404 - could be auth issue, network problem, etc.
136- raise
137-
138- # If resource exists, block the create
139- if resource_exists :
140- raise CLIError (
141- f"Deployment Safeguards instance already exists for this cluster. "
142- f"Please use 'az aks safeguards update' to modify the configuration, "
143- f"or 'az aks safeguards delete' to remove it before creating a new one."
144- )
145-
146- # If we get here, resource doesn't exist - proceed with create
14795 yield self .DeploymentSafeguardsCreate (ctx = self .ctx )()
14896 self .post_operations ()
14997
0 commit comments