-
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
Changes from 3 commits
898f5a3
3639f9d
c25dcd5
ee43004
032e64d
ce4e4f5
4dda3fc
c43a62d
1a2d0ac
2ffad8b
ce22054
d185743
422fa12
8c8bbbf
fa84b6b
6fa073c
35a3147
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. For breaking change 1-1, Track 2 now makes This pattern has already been used by azure-cli/src/azure-cli/azure/cli/command_modules/resource/custom.py Lines 3551 to 3552 in 1b62d20
Another option is to let
but this is such a big breaking change that it will affect almost all command modules and extension which use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||||||
return _search_role_definitions(cmd.cli_ctx, definitions_client, name, [scope], custom_role_only) | ||||||||||
|
||||||||||
|
||||||||||
|
@@ -94,7 +94,7 @@ def _create_update_role_definition(cmd, role_definition, for_update): | |||||||||
definitions_client = _auth_client_factory(cmd.cli_ctx, scope=role_resource_id).role_definitions | ||||||||||
scopes_in_definition = role_definition.get('assignableScopes', None) | ||||||||||
scopes = (scopes_in_definition if scopes_in_definition else | ||||||||||
['/subscriptions/' + definitions_client.config.subscription_id]) | ||||||||||
['/subscriptions/' + definitions_client._config.subscription_id]) | ||||||||||
if role_resource_id: | ||||||||||
from msrestazure.tools import parse_resource_id | ||||||||||
role_id = parse_resource_id(role_resource_id)['name'] | ||||||||||
|
@@ -125,7 +125,7 @@ def delete_role_definition(cmd, name, 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) | ||||||||||
roles = _search_role_definitions(cmd.cli_ctx, definitions_client, name, [scope], custom_role_only) | ||||||||||
for r in roles: | ||||||||||
definitions_client.delete(role_definition_id=r.name, scope=scope) | ||||||||||
|
@@ -195,7 +195,7 @@ def _create_role_assignment(cli_ctx, role, assignee, resource_group_name=None, s | |||||||||
assignments_client = factory.role_assignments | ||||||||||
definitions_client = factory.role_definitions | ||||||||||
scope = _build_role_scope(resource_group_name, scope, | ||||||||||
assignments_client.config.subscription_id) | ||||||||||
assignments_client._config.subscription_id) | ||||||||||
|
||||||||||
role_id = _resolve_role_id(role, scope, definitions_client) | ||||||||||
object_id = _resolve_object_id(cli_ctx, assignee) if resolve_assignee else assignee | ||||||||||
|
@@ -213,25 +213,25 @@ def list_role_assignments(cmd, assignee=None, role=None, resource_group_name=Non | |||||||||
member(transitively). | ||||||||||
''' | ||||||||||
graph_client = _graph_client_factory(cmd.cli_ctx) | ||||||||||
factory = _auth_client_factory(cmd.cli_ctx, scope) | ||||||||||
assignments_client = factory.role_assignments | ||||||||||
definitions_client = factory.role_definitions | ||||||||||
authorization_client = _auth_client_factory(cmd.cli_ctx, scope) | ||||||||||
assignments_client = authorization_client.role_assignments | ||||||||||
definitions_client = authorization_client.role_definitions | ||||||||||
|
||||||||||
if show_all: | ||||||||||
if resource_group_name or scope: | ||||||||||
raise CLIError('group or scope are not required when --all is used') | ||||||||||
scope = None | ||||||||||
else: | ||||||||||
scope = _build_role_scope(resource_group_name, scope, | ||||||||||
definitions_client.config.subscription_id) | ||||||||||
definitions_client._config.subscription_id) | ||||||||||
|
||||||||||
assignments = _search_role_assignments(cmd.cli_ctx, assignments_client, definitions_client, | ||||||||||
scope, assignee, role, | ||||||||||
include_inherited, include_groups) | ||||||||||
|
||||||||||
results = todict(assignments) if assignments else [] | ||||||||||
if include_classic_administrators: | ||||||||||
results += _backfill_assignments_for_co_admins(cmd.cli_ctx, factory, assignee) | ||||||||||
results += _backfill_assignments_for_co_admins(cmd.cli_ctx, authorization_client, assignee) | ||||||||||
|
||||||||||
if not results: | ||||||||||
return [] | ||||||||||
|
@@ -240,7 +240,7 @@ def list_role_assignments(cmd, assignee=None, role=None, resource_group_name=Non | |||||||||
# (it's possible that associated roles and principals were deleted, and we just do nothing.) | ||||||||||
# 2. fill in role names | ||||||||||
role_defs = list(definitions_client.list( | ||||||||||
scope=scope or ('/subscriptions/' + definitions_client.config.subscription_id))) | ||||||||||
scope=scope or ('/subscriptions/' + definitions_client._config.subscription_id))) | ||||||||||
worker = MultiAPIAdaptor(cmd.cli_ctx) | ||||||||||
role_dics = {i.id: worker.get_role_property(i, 'role_name') for i in role_defs} | ||||||||||
for i in results: | ||||||||||
|
@@ -470,7 +470,7 @@ def _backfill_assignments_for_co_admins(cli_ctx, auth_client, assignee=None): | |||||||||
'principalName': email, | ||||||||||
'roleDefinitionName': admin.role, | ||||||||||
'roleDefinitionId': 'NA(classic admin role)', | ||||||||||
'scope': '/subscriptions/' + auth_client.config.subscription_id | ||||||||||
'scope': '/subscriptions/' + auth_client._config.subscription_id | ||||||||||
} | ||||||||||
if worker.old_api: | ||||||||||
result[-1]['properties'] = properties | ||||||||||
|
@@ -525,7 +525,7 @@ def delete_role_assignments(cmd, ids=None, assignee=None, role=None, resource_gr | |||||||||
return | ||||||||||
|
||||||||||
scope = _build_role_scope(resource_group_name, scope, | ||||||||||
assignments_client.config.subscription_id) | ||||||||||
assignments_client._config.subscription_id) | ||||||||||
assignments = _search_role_assignments(cmd.cli_ctx, assignments_client, definitions_client, | ||||||||||
scope, assignee, role, include_inherited, | ||||||||||
include_groups=False) | ||||||||||
|
@@ -556,9 +556,9 @@ def _search_role_assignments(cli_ctx, assignments_client, definitions_client, | |||||||||
f = "assignedTo('{}')".format(assignee_object_id) | ||||||||||
else: | ||||||||||
f = "principalId eq '{}'".format(assignee_object_id) | ||||||||||
assignments = list(assignments_client.list(filter=f)) | ||||||||||
assignments = list(assignments_client.list_for_subscription(filter=f)) | ||||||||||
else: | ||||||||||
assignments = list(assignments_client.list()) | ||||||||||
assignments = list(assignments_client.list_for_subscription()) | ||||||||||
|
||||||||||
worker = MultiAPIAdaptor(cli_ctx) | ||||||||||
if assignments: | ||||||||||
|
@@ -604,7 +604,7 @@ def _resolve_role_id(role, scope, definitions_client): | |||||||||
else: | ||||||||||
if is_guid(role): | ||||||||||
role_id = '/subscriptions/{}/providers/Microsoft.Authorization/roleDefinitions/{}'.format( | ||||||||||
definitions_client.config.subscription_id, role) | ||||||||||
definitions_client._config.subscription_id, role) | ||||||||||
if not role_id: # retrieve role id | ||||||||||
role_defs = list(definitions_client.list(scope, "roleName eq '{}'".format(role))) | ||||||||||
if not role_defs: | ||||||||||
|
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.
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 fromrole_assignments
:azure-cli/src/azure-cli/azure/cli/command_modules/role/_multi_api_adaptor.py
Lines 62 to 65 in 5f40c5e
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 fromrole_assignments
: #26577