Skip to content

Commit 649886e

Browse files
committed
merge
2 parents 035f8b8 + 05593c6 commit 649886e

File tree

7 files changed

+1963
-5467
lines changed

7 files changed

+1963
-5467
lines changed

src/azure-cli/azure/cli/command_modules/role/_params.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,6 @@ class PrincipalType(str, Enum):
378378
'for tenant level role definitions.')
379379
c.argument('custom_role_only', arg_type=get_three_state_flag(), help='custom roles only(vs. build-in ones)')
380380
c.argument('role_definition', help="json formatted content which defines the new role.")
381-
c.argument('name', arg_type=name_arg_type, completer=get_role_definition_name_completion_list, help="the role's name")
381+
c.argument('name', arg_type=name_arg_type, completer=get_role_definition_name_completion_list,
382+
help="Matches the role definition's name (GUID) or roleName (e.g. 'Reader') property. "
383+
"If a GUID is provided, for better performance, use `az role definition show` command.")

src/azure-cli/azure/cli/command_modules/role/custom.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ def delete_role_definition(cmd, name, resource_group_name=None, scope=None,
155155

156156
def _search_role_definitions(cli_ctx, definitions_client, name, scopes, custom_role_only=False):
157157
for scope in scopes:
158-
roles = list(definitions_client.list(scope))
158+
# name argument matches the role definition's name (GUID) or roleName (e.g. 'Reader') property.
159+
# Only roleName can be used as a filter in Role Definitions - List API.
160+
# If name is a GUID, the filtering is performed on the client side.
161+
filter_query = f"roleName eq '{name}'" if name and not is_guid(name) else None
162+
roles = list(definitions_client.list(scope, filter=filter_query))
159163
worker = MultiAPIAdaptor(cli_ctx)
160164
if name:
161165
roles = [r for r in roles if r.name == name or worker.get_role_property(r, 'role_name') == name]

src/azure-cli/azure/cli/command_modules/role/tests/latest/recordings/test_built_in_role_definition_scenario.yaml

Lines changed: 1671 additions & 4 deletions
Large diffs are not rendered by default.
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
interactions:
2+
- request:
3+
body: '{"properties": {"roleName": "cli-test-role000001", "description": "Can
4+
monitor compute, network and storage, and restart virtual machines", "permissions":
5+
[{"actions": ["Microsoft.Compute/*/read", "Microsoft.Compute/virtualMachines/start/action",
6+
"Microsoft.Compute/virtualMachines/restart/action", "Microsoft.Network/*/read",
7+
"Microsoft.Storage/*/read", "Microsoft.Authorization/*/read", "Microsoft.Resources/subscriptions/resourceGroups/read",
8+
"Microsoft.Resources/subscriptions/resourceGroups/resources/read", "Microsoft.Insights/alertRules/*"],
9+
"dataActions": ["Microsoft.Storage/storageAccounts/blobServices/containers/blobs/*"],
10+
"notDataActions": ["Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write"]}],
11+
"assignableScopes": ["/subscriptions/00000000-0000-0000-0000-000000000000"]}}'
12+
headers:
13+
Accept:
14+
- application/json
15+
Accept-Encoding:
16+
- gzip, deflate
17+
CommandName:
18+
- role definition create
19+
Connection:
20+
- keep-alive
21+
Content-Length:
22+
- '807'
23+
Content-Type:
24+
- application/json
25+
ParameterSetName:
26+
- --role-definition
27+
User-Agent:
28+
- AZURECLI/2.68.0 azsdk-python-core/1.31.0 Python/3.12.8 (Windows-11-10.0.26100-SP0)
29+
method: PUT
30+
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/88888888-0000-0000-0000-000000000001?api-version=2022-05-01-preview
31+
response:
32+
body:
33+
string: '{"properties":{"roleName":"cli-test-role000001","type":"CustomRole","description":"Can
34+
monitor compute, network and storage, and restart virtual machines","assignableScopes":["/subscriptions/00000000-0000-0000-0000-000000000000"],"permissions":[{"actions":["Microsoft.Compute/*/read","Microsoft.Compute/virtualMachines/start/action","Microsoft.Compute/virtualMachines/restart/action","Microsoft.Network/*/read","Microsoft.Storage/*/read","Microsoft.Authorization/*/read","Microsoft.Resources/subscriptions/resourceGroups/read","Microsoft.Resources/subscriptions/resourceGroups/resources/read","Microsoft.Insights/alertRules/*"],"notActions":[],"dataActions":["Microsoft.Storage/storageAccounts/blobServices/containers/blobs/*"],"notDataActions":["Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write"]}],"createdOn":"2025-01-10T08:20:27.0007137Z","updatedOn":"2025-01-10T08:20:27.0007137Z","createdBy":null,"updatedBy":"0d504196-1423-4569-9a6e-15149656f0ee"},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/88888888-0000-0000-0000-000000000001","type":"Microsoft.Authorization/roleDefinitions","name":"88888888-0000-0000-0000-000000000001"}'
35+
headers:
36+
cache-control:
37+
- no-cache
38+
content-length:
39+
- '1217'
40+
content-type:
41+
- application/json; charset=utf-8
42+
date:
43+
- Fri, 10 Jan 2025 08:20:29 GMT
44+
expires:
45+
- '-1'
46+
pragma:
47+
- no-cache
48+
strict-transport-security:
49+
- max-age=31536000; includeSubDomains
50+
x-cache:
51+
- CONFIG_NOCACHE
52+
x-content-type-options:
53+
- nosniff
54+
x-ms-ratelimit-remaining-subscription-global-writes:
55+
- '2999'
56+
x-ms-ratelimit-remaining-subscription-writes:
57+
- '199'
58+
x-msedge-ref:
59+
- 'Ref A: 3DA9696496494F579E86A59EEC19744A Ref B: MAA201060516049 Ref C: 2025-01-10T08:20:26Z'
60+
status:
61+
code: 201
62+
message: Created
63+
- request:
64+
body: null
65+
headers:
66+
Accept:
67+
- application/json
68+
Accept-Encoding:
69+
- gzip, deflate
70+
CommandName:
71+
- role definition list
72+
Connection:
73+
- keep-alive
74+
ParameterSetName:
75+
- -n
76+
User-Agent:
77+
- AZURECLI/2.68.0 azsdk-python-core/1.31.0 Python/3.12.8 (Windows-11-10.0.26100-SP0)
78+
method: GET
79+
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions?$filter=roleName%20eq%20%27cli-test-role000001%27&api-version=2022-05-01-preview
80+
response:
81+
body:
82+
string: '{"value":[{"properties":{"roleName":"cli-test-role000001","type":"CustomRole","description":"Can
83+
monitor compute, network and storage, and restart virtual machines","assignableScopes":["/subscriptions/00000000-0000-0000-0000-000000000000"],"permissions":[{"actions":["Microsoft.Compute/*/read","Microsoft.Compute/virtualMachines/start/action","Microsoft.Compute/virtualMachines/restart/action","Microsoft.Network/*/read","Microsoft.Storage/*/read","Microsoft.Authorization/*/read","Microsoft.Resources/subscriptions/resourceGroups/read","Microsoft.Resources/subscriptions/resourceGroups/resources/read","Microsoft.Insights/alertRules/*"],"notActions":[],"dataActions":["Microsoft.Storage/storageAccounts/blobServices/containers/blobs/*"],"notDataActions":["Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write"]}],"createdOn":"2025-01-10T08:20:27.0127134Z","updatedOn":"2025-01-10T08:20:27.0127134Z","createdBy":"0d504196-1423-4569-9a6e-15149656f0ee","updatedBy":"0d504196-1423-4569-9a6e-15149656f0ee"},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/88888888-0000-0000-0000-000000000001","type":"Microsoft.Authorization/roleDefinitions","name":"88888888-0000-0000-0000-000000000001"}]}'
84+
headers:
85+
cache-control:
86+
- no-cache
87+
content-length:
88+
- '1263'
89+
content-type:
90+
- application/json; charset=utf-8
91+
date:
92+
- Fri, 10 Jan 2025 08:20:30 GMT
93+
expires:
94+
- '-1'
95+
pragma:
96+
- no-cache
97+
strict-transport-security:
98+
- max-age=31536000; includeSubDomains
99+
x-cache:
100+
- CONFIG_NOCACHE
101+
x-content-type-options:
102+
- nosniff
103+
x-ms-ratelimit-remaining-subscription-global-reads:
104+
- '3749'
105+
x-msedge-ref:
106+
- 'Ref A: 721218A1A02B44A4BFD873CFC0486514 Ref B: MAA201060516039 Ref C: 2025-01-10T08:20:30Z'
107+
status:
108+
code: 200
109+
message: OK
110+
- request:
111+
body: '{"properties": {"roleName": "cli-test-role000001", "description": "Can
112+
monitor compute, network and storage, and restart virtual machines", "permissions":
113+
[{"actions": ["Microsoft.Compute/*/read", "Microsoft.Compute/virtualMachines/start/action",
114+
"Microsoft.Compute/virtualMachines/restart/action", "Microsoft.Network/*/read",
115+
"Microsoft.Storage/*/read", "Microsoft.Authorization/*/read", "Microsoft.Resources/subscriptions/resourceGroups/read",
116+
"Microsoft.Resources/subscriptions/resourceGroups/resources/read", "Microsoft.Insights/alertRules/*",
117+
"Microsoft.Support/*"], "notActions": [], "dataActions": ["Microsoft.Storage/storageAccounts/blobServices/containers/blobs/*"],
118+
"notDataActions": ["Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write"]}],
119+
"assignableScopes": ["/subscriptions/00000000-0000-0000-0000-000000000000"]}}'
120+
headers:
121+
Accept:
122+
- application/json
123+
Accept-Encoding:
124+
- gzip, deflate
125+
CommandName:
126+
- role definition update
127+
Connection:
128+
- keep-alive
129+
Content-Length:
130+
- '848'
131+
Content-Type:
132+
- application/json
133+
ParameterSetName:
134+
- --role-definition
135+
User-Agent:
136+
- AZURECLI/2.68.0 azsdk-python-core/1.31.0 Python/3.12.8 (Windows-11-10.0.26100-SP0)
137+
method: PUT
138+
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/88888888-0000-0000-0000-000000000001?api-version=2022-05-01-preview
139+
response:
140+
body:
141+
string: '{"properties":{"roleName":"cli-test-role000001","type":"CustomRole","description":"Can
142+
monitor compute, network and storage, and restart virtual machines","assignableScopes":["/subscriptions/00000000-0000-0000-0000-000000000000"],"permissions":[{"actions":["Microsoft.Compute/*/read","Microsoft.Compute/virtualMachines/start/action","Microsoft.Compute/virtualMachines/restart/action","Microsoft.Network/*/read","Microsoft.Storage/*/read","Microsoft.Authorization/*/read","Microsoft.Resources/subscriptions/resourceGroups/read","Microsoft.Resources/subscriptions/resourceGroups/resources/read","Microsoft.Insights/alertRules/*","Microsoft.Support/*"],"notActions":[],"dataActions":["Microsoft.Storage/storageAccounts/blobServices/containers/blobs/*"],"notDataActions":["Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write"]}],"createdOn":"2025-01-10T08:20:31.0536501Z","updatedOn":"2025-01-10T08:20:31.0536501Z","createdBy":null,"updatedBy":"0d504196-1423-4569-9a6e-15149656f0ee"},"id":"/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/88888888-0000-0000-0000-000000000001","type":"Microsoft.Authorization/roleDefinitions","name":"88888888-0000-0000-0000-000000000001"}'
143+
headers:
144+
cache-control:
145+
- no-cache
146+
content-length:
147+
- '1239'
148+
content-type:
149+
- application/json; charset=utf-8
150+
date:
151+
- Fri, 10 Jan 2025 08:20:34 GMT
152+
expires:
153+
- '-1'
154+
pragma:
155+
- no-cache
156+
strict-transport-security:
157+
- max-age=31536000; includeSubDomains
158+
x-cache:
159+
- CONFIG_NOCACHE
160+
x-content-type-options:
161+
- nosniff
162+
x-ms-ratelimit-remaining-subscription-global-writes:
163+
- '2999'
164+
x-ms-ratelimit-remaining-subscription-writes:
165+
- '199'
166+
x-msedge-ref:
167+
- 'Ref A: F24C8CA60578459A89142403CEB6F074 Ref B: MAA201060513033 Ref C: 2025-01-10T08:20:30Z'
168+
status:
169+
code: 201
170+
message: Created
171+
- request:
172+
body: null
173+
headers:
174+
Accept:
175+
- application/json
176+
Accept-Encoding:
177+
- gzip, deflate
178+
CommandName:
179+
- role definition delete
180+
Connection:
181+
- keep-alive
182+
ParameterSetName:
183+
- -n
184+
User-Agent:
185+
- AZURECLI/2.68.0 azsdk-python-core/1.31.0 Python/3.12.8 (Windows-11-10.0.26100-SP0)
186+
method: GET
187+
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions?$filter=roleName%20eq%20%27cli-test-role000001%27&api-version=2022-05-01-preview
188+
response:
189+
body:
190+
string: '{"value":[]}'
191+
headers:
192+
cache-control:
193+
- no-cache
194+
content-length:
195+
- '12'
196+
content-type:
197+
- application/json; charset=utf-8
198+
date:
199+
- Fri, 10 Jan 2025 08:20:34 GMT
200+
expires:
201+
- '-1'
202+
pragma:
203+
- no-cache
204+
strict-transport-security:
205+
- max-age=31536000; includeSubDomains
206+
x-cache:
207+
- CONFIG_NOCACHE
208+
x-content-type-options:
209+
- nosniff
210+
x-ms-ratelimit-remaining-subscription-global-reads:
211+
- '3749'
212+
x-msedge-ref:
213+
- 'Ref A: F9C08EF99EC04683AFB1C61832D9C324 Ref B: MAA201060513011 Ref C: 2025-01-10T08:20:35Z'
214+
status:
215+
code: 200
216+
message: OK
217+
- request:
218+
body: null
219+
headers:
220+
Accept:
221+
- application/json
222+
Accept-Encoding:
223+
- gzip, deflate
224+
CommandName:
225+
- role definition list
226+
Connection:
227+
- keep-alive
228+
ParameterSetName:
229+
- -n
230+
User-Agent:
231+
- AZURECLI/2.68.0 azsdk-python-core/1.31.0 Python/3.12.8 (Windows-11-10.0.26100-SP0)
232+
method: GET
233+
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions?$filter=roleName%20eq%20%27cli-test-role000001%27&api-version=2022-05-01-preview
234+
response:
235+
body:
236+
string: '{"value":[]}'
237+
headers:
238+
cache-control:
239+
- no-cache
240+
content-length:
241+
- '12'
242+
content-type:
243+
- application/json; charset=utf-8
244+
date:
245+
- Fri, 10 Jan 2025 08:20:35 GMT
246+
expires:
247+
- '-1'
248+
pragma:
249+
- no-cache
250+
strict-transport-security:
251+
- max-age=31536000; includeSubDomains
252+
x-cache:
253+
- CONFIG_NOCACHE
254+
x-content-type-options:
255+
- nosniff
256+
x-ms-ratelimit-remaining-subscription-global-reads:
257+
- '3749'
258+
x-msedge-ref:
259+
- 'Ref A: 5207B9A11DE64D52AE9498F887DD248E Ref B: MAA201060514053 Ref C: 2025-01-10T08:20:35Z'
260+
status:
261+
code: 200
262+
message: OK
263+
version: 1

0 commit comments

Comments
 (0)