-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Role] Migrate azure-mgmt-authorization
SDK to Track 2 and bump API version to 2022-04-01
#25452
Conversation
@@ -59,7 +59,7 @@ def list_role_definitions(cmd, name=None, resource_group_name=None, scope=None, | |||
custom_role_only=False): | |||
definitions_client = _auth_client_factory(cmd.cli_ctx, scope).role_definitions | |||
scope = _build_role_scope(resource_group_name, scope, | |||
definitions_client.config.subscription_id) | |||
definitions_client._config.subscription_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For breaking change 1-1, Track 2 now makes config
a protected attribute as _config
. I can't find a better way to extract subscription ID from the SDK client.
This pattern has already been used by resource
command module:
azure-cli/src/azure-cli/azure/cli/command_modules/resource/custom.py
Lines 3551 to 3552 in 1b62d20
subscriptionId=serialize.url( | |
"self._config.subscription_id", self.rcf.resources._config.subscription_id, 'str'), |
Another option is to let get_mgmt_service_client
return the subscription ID during client creation:
def get_mgmt_service_client(cli_ctx, client_or_resource_type, subscription_id=None, api_version=None, | |
aux_subscriptions=None, aux_tenants=None, credential=None, **kwargs): |
but this is such a big breaking change that it will affect almost all command modules and extension which use get_mgmt_service_client
to create a client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was mentioned in doc: https://github.com/Azure/azure-cli/blob/dev/doc/track_2_migration_guidance.md#obtaining-subscription
However, the doc is not accurate as the subscription used to create the client (possibly via --subscription
) may not be the same as the current subscription. Assuming the subscription used to create the client being the same as the current subscription can introduce bugs very difficult to track down.
azure-mgmt-authorization
SDK to Track 2 and bump API Version to 2022-04-01 azure-mgmt-authorization
SDK to Track 2 and bump API Version to 2022-04-01
Migrate azure-mgmt-authorization SDK to Track 2 |
Affected modules: vm aro iot acs resource |
I accidentally discovered a problem with In "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleAssignments": {
"get": {
"tags": [
"RoleAssignments"
],
"operationId": "RoleAssignments_List", "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleAssignments": {
"get": {
"tags": [
"RoleAssignments"
],
"operationId": "RoleAssignments_ListForSubscription", so this line will fail:
However, the azure-cli/src/azure-cli/azure/cli/command_modules/ams/operations/sp.py Lines 245 to 258 in 8058c09
See the doc for |
@@ -2141,7 +2141,7 @@ def show_provider_operations(cmd, resource_provider_namespace): | |||
version = getattr(get_api_version(cmd.cli_ctx, ResourceType.MGMT_AUTHORIZATION), 'provider_operations_metadata') | |||
auth_client = _authorization_management_client(cmd.cli_ctx) | |||
if version == '2015-07-01': | |||
return auth_client.provider_operations_metadata.get(resource_provider_namespace, version) | |||
return auth_client.provider_operations_metadata.get(resource_provider_namespace, api_version=version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to handle breaking change 3-1.
I discovered a problem with azure-cli/src/azure-cli/azure/cli/command_modules/iot/custom.py Lines 588 to 590 in 9ef066f
|
@@ -736,7 +737,7 @@ def assign_identity(cli_ctx, getter, setter, identity_role=None, identity_scope= | |||
assignments_client.create(scope=identity_scope, role_assignment_name=assignment_name, | |||
parameters=parameters) | |||
break | |||
except CloudError as ex: | |||
except HttpResponseError as ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to handle breaking change 1-3.
@@ -104,7 +107,7 @@ def add_role_assignment_executor(cmd, role, assignee, resource_group_name=None, | |||
operation_group="role_assignments", | |||
) | |||
properties = RoleAssignmentProperties(role_definition_id=role_id, principal_id=object_id) | |||
return assignments_client.create(scope, assignment_name, properties, custom_headers=custom_headers) | |||
return assignments_client.create(scope, assignment_name, properties, headers=custom_headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to handle breaking change 1-2.
# In 2022-04-01 API, principal_type is by default 'User', so we have to explicitly set it to None if we can't | ||
# resolve principal type from Graph | ||
# https://github.com/Azure/azure-rest-api-specs/issues/21664 | ||
parameters = RoleAssignmentCreateParameters( | ||
role_definition_id=role_id, principal_id=object_id, principal_type=assignee_principal_type, | ||
description=description, condition=condition, condition_version=condition_version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to handle breaking change 2-2.
azure-mgmt-authorization
SDK to Track 2 and bump API Version to 2022-04-01azure-mgmt-authorization
SDK to Track 2 and bump API version to 2022-04-01
'classic_administrators': '2015-06-01', | ||
'role_definitions': '2018-01-01-preview', | ||
'role_definitions': '2022-04-01', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'role_definitions': '2022-04-01', |
We can simply remove this line if role_definitions
uses the same API version with default one~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
role_definitions
frequently diverges from role_assignments
:
azure-cli/src/azure-cli/azure/cli/command_modules/role/_multi_api_adaptor.py
Lines 62 to 65 in 5f40c5e
# 2015-07-01 RoleDefinition: flattened, RoleAssignment: unflattened | |
# 2018-01-01-preview RoleDefinition: flattened | |
# 2020-04-01-preview RoleAssignment: flattened | |
# Get property_name from properties if the model is unflattened. |
so it is merely a placeholder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
role_definitions
will again diverge from role_assignments
: #26577
35a3147
… version to 2022-04-01 (Azure#25452)
Related command
az role
Description
Close #23372
Migrate
azure-mgmt-authorization
SDK to Track 2 and bump API Version to2022-04-01
:role_assignments
:2020-04-01-preview
->2022-04-01
role_definitions
:2018-01-01-preview
->2022-04-01
Breaking changes in
azure-mgmt-authorization
SDKFor SDK version
0.61.0
(Track 1) ->3.0.0
(Track 2):definitions_client.config
andassignments_client.config
are changed todefinitions_client._config
andassignments_client._config
.custom_headers
are changed toheaders
.msrestazure.azure_exceptions.CloudError
toazure.core.exceptions.HttpResponseError
For API version
2020-04-01-preview
->2022-04-01
:RoleAssignmentsOperations
changeslist
method tolist_for_subscription
.RoleAssignmentCreateParameters.principal_type
's default value is changed fromNone
toUser
([Role]RoleAssignmentProperties.principalType
should not have default valueUser
azure-rest-api-specs#21664)For API version
2015-07-01
:ProviderOperationsMetadataOperations.get
changesapi_version
from positional argument to keyword argument.