[BUG] ArmClient.GetDenyAssignments(identifier) fails when the identifier is in a resource level #40050
Labels
ARM
bug
This issue requires a change to an existing behavior in the product in order to be resolved.
Mgmt
This issue is related to a management-plane library.
needs-team-attention
Workflow: This issue needs attention from Azure service team or SDK team
question
The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Library name and version
Azure.ResourceManager.Authorization 1.0.1
Describe the bug
When fetching a resource deny assignments using the ArmClient
It fails with: System.ArgumentException
essage=Value cannot be empty or contain only white-space characters. (Parameter 'resourceType')
Source=Azure.Core
StackTrace:
at Azure.Core.Argument.AssertNotNullOrWhiteSpace(String value, String name)
at Azure.Core.ResourceType..ctor(String resourceType)
at Azure.Core.ResourceType.op_Implicit(String resourceType)
at Azure.ResourceManager.Authorization.DenyAssignmentCollection.GetAllAsync(String filter, CancellationToken cancellationToken)
at Azure.ResourceManager.Authorization.DenyAssignmentCollection.System.Collections.Generic.IAsyncEnumerable<Azure.ResourceManager.Authorization.DenyAssignmentResource>.GetAsyncEnumerator(CancellationToken cancellationToken)
The issue is in the DenyAssignmentCollection, when it checks
else if (Id.ResourceType == "")
There is implicit convertion from string to ResourceType, and the resource type ctor does not allow empty strings.
you can fix it by changing it to do explicit string
else if (Id.ResourceType.ToString() == "")
Expected behavior
Should return the role assignments of the given resource
Actual behavior
fails with System.ArgumentException
Reproduction Steps
var armClient = new ArmClient(new AzureCliCredential());
var resource =
ResourceIdentifier.Parse(
"/subscriptions/{subId}/resourceGroups/{resourceGroup}/providers/{RP}/{Type}/{Name}");
var denyAssignments = await armClient.GetDenyAssignments(resource).ToListAsync();
Environment
.NET SDK:
Version: 7.0.404
Commit: 22f221a24c
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.404\
Host:
Version: 7.0.14
Architecture: x64
Commit: 808851b07a
The text was updated successfully, but these errors were encountered: