Skip to content

Commit ad6472f

Browse files
committed
Update aro module and bump to 2025_07_25
* changes are identical to the downstream with the exception of * rp_mode_development functionality which is removed, and preview * extension metadata which is also removed.
1 parent 625c3f8 commit ad6472f

25 files changed

+3139
-271
lines changed

src/azure-cli/azure/cli/command_modules/aro/__init__.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,35 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6+
from azure.cli.command_modules.aro._client_factory import cf_aro
67
from azure.cli.command_modules.aro._params import load_arguments
78
from azure.cli.command_modules.aro.commands import load_command_table
8-
from azure.cli.core import AzCommandsLoader, ModExtensionSuppress
9+
from azure.cli.core import (
10+
AzCommandsLoader,
11+
ModExtensionSuppress
12+
)
913
from azure.cli.core.commands import CliCommandType
10-
from azure.cli.core.profiles import ResourceType
11-
from azure.cli.command_modules.aro._client_factory import cf_aro # pylint: disable=unused-import
14+
from azure.cli.core.aaz import load_aaz_command_table
1215
from azure.cli.command_modules.aro._help import helps # pylint: disable=unused-import
16+
try:
17+
from . import aaz
18+
except ImportError:
19+
aaz = None
1320

1421

1522
class AroCommandsLoader(AzCommandsLoader):
16-
1723
def __init__(self, cli_ctx=None):
1824
aro_custom = CliCommandType(
1925
operations_tmpl='azure.cli.command_modules.aro.custom#{}',
2026
client_factory=cf_aro)
21-
2227
suppress = ModExtensionSuppress(__name__, 'aro', '1.0.0',
2328
reason='Its functionality is included in the core az CLI.',
2429
recommend_remove=True)
2530
super().__init__(cli_ctx=cli_ctx,
2631
suppress_extension=suppress,
27-
custom_command_type=aro_custom,
28-
resource_type=ResourceType.MGMT_ARO)
32+
custom_command_type=aro_custom)
2933

3034
def load_command_table(self, args):
31-
from azure.cli.core.aaz import load_aaz_command_table
32-
try:
33-
from . import aaz
34-
except ImportError:
35-
aaz = None
3635
if aaz:
3736
load_aaz_command_table(
3837
loader=self,

src/azure-cli/azure/cli/command_modules/aro/_aad.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import time
77

8-
from azure.cli.command_modules.role import graph_client_factory
9-
from azure.cli.command_modules.role import GraphError
8+
from azure.cli.command_modules.role import (
9+
graph_client_factory,
10+
GraphError
11+
)
1012

1113
from knack.log import get_logger
1214

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import argparse
7+
8+
from azure.mgmt.redhatopenshift.models import PlatformWorkloadIdentity
9+
from azure.cli.core.azclierror import CLIError
10+
11+
12+
# pylint:disable=protected-access
13+
# pylint:disable=too-few-public-methods
14+
class AROPlatformWorkloadIdentityAddAction(argparse._AppendAction):
15+
16+
def __call__(self, parser, namespace, values, option_string=None):
17+
try:
18+
if len(values) != 2:
19+
msg = f"{option_string} requires 2 values in format: `OPERATOR_NAME RESOURCE_ID`"
20+
raise argparse.ArgumentError(self, msg)
21+
22+
operator_name, resource_id = values
23+
parsed = (operator_name, PlatformWorkloadIdentity(resource_id=resource_id))
24+
25+
super().__call__(parser, namespace, parsed, option_string)
26+
27+
except ValueError as e:
28+
raise CLIError(f"usage error: {option_string} NAME ID") from e

src/azure-cli/azure/cli/command_modules/aro/_client_factory.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
55

6-
7-
from azure.cli.core.commands.client_factory import get_mgmt_service_client
86
from azure.mgmt.redhatopenshift import AzureRedHatOpenShiftClient
7+
from azure.cli.core.commands.client_factory import get_mgmt_service_client
98

109

1110
def cf_aro(cli_ctx, *_):

src/azure-cli/azure/cli/command_modules/aro/_dynamic_validators.py

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
# --------------------------------------------------------------------------------------------
2-
# Copyright (c) Microsoft Corporation. All rights reserved.
3-
# Licensed under the MIT License. See License.txt in the project root for license information.
4-
# --------------------------------------------------------------------------------------------
5-
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the Apache License 2.0.
63

4+
import collections
75
import ipaddress
86
import re
97
from itertools import tee
108

11-
from azure.cli.command_modules.aro._validators import validate_vnet, validate_cidr
12-
from azure.cli.command_modules.aro._rbac import has_role_assignment_on_resource
13-
from azure.cli.command_modules.aro.aaz.latest.network.vnet.subnet import Show as subnet_show
14-
from azure.cli.command_modules.aro.aaz.latest.network.vnet import Show as vnet_show
159
from azure.cli.core.commands.client_factory import get_mgmt_service_client
1610
from azure.cli.core.commands.validators import get_default_location_from_resource_group
1711
from azure.cli.core.profiles import ResourceType
18-
from azure.cli.core.azclierror import CLIInternalError, InvalidArgumentValueError, \
12+
from azure.cli.core.azclierror import (
13+
CLIInternalError,
14+
InvalidArgumentValueError,
1915
RequiredArgumentMissingError
20-
from azure.core.exceptions import ResourceNotFoundError, HttpResponseError
16+
)
17+
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
2118
from azure.mgmt.core.tools import is_valid_resource_id, parse_resource_id
2219
from knack.log import get_logger
20+
from azure.cli.command_modules.aro._validators import validate_vnet, validate_cidr
21+
from azure.cli.command_modules.aro._rbac import has_role_assignment_on_resource
22+
from azure.cli.command_modules.aro.aaz.latest.network.vnet.subnet import Show as subnet_show
23+
from azure.cli.command_modules.aro.aaz.latest.network.vnet import Show as vnet_show
2324
import azure.cli.command_modules.aro.custom
2425

2526

@@ -289,15 +290,15 @@ def _validate_cidr_ranges(cmd, namespace):
289290
return _validate_cidr_ranges
290291

291292

292-
def dyn_validate_resource_permissions(service_principle_ids, resources):
293+
def dyn_validate_resource_permissions(service_principal_ids, resources):
293294
prog = get_progress_tracker("Validating resource permissions")
294295

295296
@prog
296297
def _validate_resource_permissions(cmd,
297298
_namespace):
298299
errors = []
299300

300-
for sp_id in service_principle_ids:
301+
for sp_id in service_principal_ids:
301302
for role in sorted(resources):
302303
for resource in resources[role]:
303304
try:
@@ -331,7 +332,7 @@ def _validate_version(cmd,
331332
if namespace.location is None:
332333
get_default_location_from_resource_group(cmd, namespace)
333334

334-
versions = azure.cli.command_modules.aro.custom.aro_get_versions(namespace.client, namespace.location)
335+
versions = azext_aro.custom.aro_get_versions(namespace.client, namespace.location)
335336

336337
found = False
337338
for version in versions:
@@ -351,15 +352,47 @@ def _validate_version(cmd,
351352

352353
def validate_cluster_create(version,
353354
resources,
354-
service_principle_ids):
355+
service_principal_ids):
355356
error_object = []
356357

357358
error_object.append(dyn_validate_vnet("vnet"))
358359
error_object.append(dyn_validate_subnet_and_route_tables("master_subnet"))
359360
error_object.append(dyn_validate_subnet_and_route_tables("worker_subnet"))
360361
error_object.append(dyn_validate_cidr_ranges())
361-
error_object.append(dyn_validate_resource_permissions(service_principle_ids, resources))
362+
error_object.append(dyn_validate_resource_permissions(service_principal_ids, resources))
362363
if version is not None:
363364
error_object.append(dyn_validate_version())
364365

365366
return error_object
367+
368+
369+
def dyn_validate_managed_identity_delete_permissions():
370+
prog = get_progress_tracker("Validating Managed Identity Delete Permissions")
371+
372+
@prog
373+
def _validate_managed_identity_delete_permissions(cmd, namespace):
374+
errors = []
375+
managed_identities = namespace.managed_identities
376+
377+
for mi in managed_identities:
378+
parts, auth_client = get_clients(mi, cmd)
379+
validation_errors = validate_resource(auth_client, "Managed Identity", parts, [
380+
"Microsoft.ManagedIdentity/userAssignedIdentities/delete"
381+
])
382+
for error in validation_errors:
383+
errors.append(f"{error[3]} over {mi}")
384+
385+
return errors
386+
387+
return _validate_managed_identity_delete_permissions
388+
389+
390+
def validate_cluster_delete(cmd, delete_identities, managed_identities):
391+
errors = []
392+
393+
if delete_identities:
394+
namespace = collections.namedtuple("Namespace", ["managed_identities"])(managed_identities)
395+
validate_managed_identity_delete = dyn_validate_managed_identity_delete_permissions()
396+
errors.extend(validate_managed_identity_delete(cmd, namespace))
397+
398+
return errors

src/azure-cli/azure/cli/command_modules/aro/_format.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# --------------------------------------------------------------------------------------------
2-
# Copyright (c) Microsoft Corporation. All rights reserved.
3-
# Licensed under the MIT License. See License.txt in the project root for license information.
4-
# --------------------------------------------------------------------------------------------
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the Apache License 2.0.
53

64
import collections
75

src/azure-cli/azure/cli/command_modules/aro/_help.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# --------------------------------------------------------------------------------------------
2-
# Copyright (c) Microsoft Corporation. All rights reserved.
3-
# Licensed under the MIT License. See License.txt in the project root for license information.
4-
# --------------------------------------------------------------------------------------------
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the Apache License 2.0.
53

64
from knack.help_files import helps
75

0 commit comments

Comments
 (0)