-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[Role] az role assignment create/update: Support --description, --condition and --condition-version
#14958
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] az role assignment create/update: Support --description, --condition and --condition-version
#14958
Changes from all commits
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 |
|---|---|---|
|
|
@@ -585,12 +585,44 @@ | |
| examples: | ||
| - name: Create role assignment for an assignee. | ||
| text: az role assignment create --assignee sp_name --role a_role | ||
| - name: Create role assignment for an assignee with description and condition. | ||
| text: >- | ||
| az role assignment create --role "Owner" --assignee "Jhon.Doe@Contoso.com" | ||
| --description "Role assignment foo to check on bar" | ||
| --condition "@Resource[Microsoft.Storage/storageAccounts/blobServices/containers:Name] stringEquals 'foo'" | ||
| --condition-version "2.0" | ||
| supported-profiles: latest | ||
| - name: Create a new role assignment for a user, group, or service principal. (autogenerated) | ||
| text: | | ||
| az role assignment create --assignee 00000000-0000-0000-0000-000000000000 --role "Storage Account Key Operator Service Role" --scope $id | ||
| crafted: true | ||
| """ | ||
|
|
||
|
|
||
| helps['role assignment update'] = """ | ||
| type: command | ||
| short-summary: Update an existing role assignment for a user, group, or service principal. | ||
| examples: | ||
| - name: Update a role assignment from a JSON file. | ||
| text: az role assignment update --role-assignment assignment.json | ||
| - name: Update a role assignment from a JSON string. (Bash) | ||
| text: | | ||
| az role assignment update --role-assignment '{ | ||
| "canDelegate": null, | ||
|
Member
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. Can we add parameters like --can-deleagate so that users can see help messages.
Contributor
Author
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. Taking JSON as an input is asked by the service team. I had the same suggestion as you to expose explicit arguments but the suggestion was rejected.
Member
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. CLI is yours. You fix it. Be brave. Go ahead. |
||
| "condition": "@Resource[Microsoft.Storage/storageAccounts/blobServices/containers:Name] stringEquals '"'"'foo'"'"'", | ||
| "conditionVersion": "2.0", | ||
| "description": "Role assignment foo to check on bar", | ||
| "id": "/subscriptions/00000001-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.Authorization/roleAssignments/3eabdd43-375b-4dbd-8dc4-04acd15ce56b", | ||
| "name": "3eabdd43-375b-4dbd-8dc4-04acd15ce56b", | ||
| "principalId": "00000002-0000-0000-0000-000000000000", | ||
| "principalType": "User", | ||
| "resourceGroup": "rg1", | ||
| "roleDefinitionId": "/subscriptions/00000001-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7", | ||
| "scope": "/subscriptions/00000001-0000-0000-0000-000000000000/resourceGroups/rg1", | ||
| "type": "Microsoft.Authorization/roleAssignments" | ||
| }' | ||
| """ | ||
|
|
||
| helps['role assignment delete'] = """ | ||
| type: command | ||
| short-summary: Delete role assignments. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -186,6 +186,9 @@ def load_arguments(self, _): | |
| "use the object id and not the app id.") | ||
| c.argument('ids', nargs='+', help='space-separated role assignment ids') | ||
| c.argument('include_classic_administrators', arg_type=get_three_state_flag(), help='list default role assignments for subscription classic administrators, aka co-admins') | ||
| c.argument('description', min_api='2020-04-01-preview', help='Description of role assignment.') | ||
| c.argument('condition', min_api='2020-04-01-preview', help='Condition under which the user can be granted permission.') | ||
| c.argument('condition_version', min_api='2020-04-01-preview', help='Version of the condition syntax. If --condition is specified without --condition-version, default to 2.0.') | ||
|
Contributor
Author
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.
Added. I didn't use the built-in default mechanism because it is a conditional default - only when |
||
|
|
||
| time_help = ('The {} of the query in the format of %Y-%m-%dT%H:%M:%SZ, e.g. 2000-12-31T12:59:59Z. Defaults to {}') | ||
| with self.argument_context('role assignment list-changelogs') as c: | ||
|
|
@@ -198,6 +201,11 @@ def load_arguments(self, _): | |
| c.argument('assignee_principal_type', min_api='2018-09-01-preview', arg_type=get_enum_type(PrincipalType), | ||
| help='use with --assignee-object-id to avoid errors caused by propagation latency in AAD Graph') | ||
|
|
||
| with self.argument_context('role assignment update') as c: | ||
| c.argument('role_assignment', | ||
| help='Description of an existing role assignment as JSON, or a path to a file containing a ' | ||
| 'JSON description.') | ||
|
|
||
| with self.argument_context('role assignment delete') as c: | ||
| c.argument('yes', options_list=['--yes', '-y'], action='store_true', help='Continue to delete all assignments under the subscription') | ||
|
|
||
|
|
||
Large diffs are not rendered by default.
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.
What's the difference between
>-and|?Uh oh!
There was an error while loading. Please reload this page.
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.
@qwordy

In short:
>-will replace all single\nto whitespace (especially, the final\nwill be removed), and combine double\nto 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.
I use
>-to make the code more readable purposefully.