Skip to content

Commit 14fa4c1

Browse files
committed
Addressed review comments for Get and Remove Azure Ro Assignments fixes
1 parent c21ddc5 commit 14fa4c1

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/ResourceManager/Resources/Commands.Resources/Models.Authorization/AuthorizationClient.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public PSRoleAssignment CreateRoleAssignment(FilterRoleAssignmentsOptions parame
130130
/// </summary>
131131
/// <param name="options">The filtering options</param>
132132
/// <returns>The filtered role assignments</returns>
133-
public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions options, bool excludeAssignmentsForDeletedPrincipals = true)
133+
public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions options)
134134
{
135135
List<PSRoleAssignment> result = new List<PSRoleAssignment>();
136136
ListAssignmentsFilterParameters parameters = new ListAssignmentsFilterParameters();
@@ -140,25 +140,25 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
140140
// Filter first by principal
141141
parameters.PrincipalId = string.IsNullOrEmpty(options.ADObjectFilter.Id) ? ActiveDirectoryClient.GetObjectId(options.ADObjectFilter) : Guid.Parse(options.ADObjectFilter.Id);
142142
result.AddRange(AuthorizationManagementClient.RoleAssignments.List(parameters)
143-
.RoleAssignments.Select(r => r.ToPSRoleAssignment(this, ActiveDirectoryClient, excludeAssignmentsForDeletedPrincipals)).Where(r => r != null));
143+
.RoleAssignments.Select(r => r.ToPSRoleAssignment(this, ActiveDirectoryClient, options.ExcludeAssignmentsForDeletedPrincipals)).Where(r => r != null));
144144

145145
// Filter out by scope
146146
if (!string.IsNullOrEmpty(options.Scope))
147147
{
148-
result.RemoveAll(r => !options.Scope.StartsWith(r.Scope, StringComparison.InvariantCultureIgnoreCase));
148+
result.RemoveAll(r => !options.Scope.StartsWith(r.Scope, StringComparison.InvariantCultureIgnoreCase));
149149
}
150150
}
151151
else if (!string.IsNullOrEmpty(options.Scope))
152152
{
153153
// Filter by scope and above directly
154154
parameters.AtScope = true;
155155
result.AddRange(AuthorizationManagementClient.RoleAssignments.ListForScope(options.Scope, parameters)
156-
.RoleAssignments.Select(r => r.ToPSRoleAssignment(this, ActiveDirectoryClient, excludeAssignmentsForDeletedPrincipals)).Where(r => r != null));
156+
.RoleAssignments.Select(r => r.ToPSRoleAssignment(this, ActiveDirectoryClient, options.ExcludeAssignmentsForDeletedPrincipals)).Where(r => r != null));
157157
}
158158
else
159159
{
160160
result.AddRange(AuthorizationManagementClient.RoleAssignments.List(parameters)
161-
.RoleAssignments.Select(r => r.ToPSRoleAssignment(this, ActiveDirectoryClient, excludeAssignmentsForDeletedPrincipals)).Where(r => r != null));
161+
.RoleAssignments.Select(r => r.ToPSRoleAssignment(this, ActiveDirectoryClient, options.ExcludeAssignmentsForDeletedPrincipals)).Where(r => r != null));
162162
}
163163

164164
if (!string.IsNullOrEmpty(options.RoleDefinition))
@@ -177,7 +177,7 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
177177
public PSRoleAssignment RemoveRoleAssignment(FilterRoleAssignmentsOptions options)
178178
{
179179
// Match role assignments at exact scope. At most 1 roleAssignment should match the criteria
180-
PSRoleAssignment roleAssignment = FilterRoleAssignments(options, excludeAssignmentsForDeletedPrincipals: false)
180+
PSRoleAssignment roleAssignment = FilterRoleAssignments(options)
181181
.Where(ra => ra.Scope == options.Scope.TrimEnd('/'))
182182
.FirstOrDefault();
183183

src/ResourceManager/Resources/Commands.Resources/Models.Authorization/FilterRoleAssignmentsOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ public string Scope
5353
public ResourceIdentifier ResourceIdentifier { get; set; }
5454

5555
public ADObjectFilterOptions ADObjectFilter { get; set; }
56+
57+
public bool ExcludeAssignmentsForDeletedPrincipals { get; set; }
5658
}
5759
}

src/ResourceManager/Resources/Commands.Resources/RoleAssignments/GetAzureRoleAssignmentCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,11 @@ protected override void ProcessRecord()
212212
ResourceName = ResourceName,
213213
ResourceType = ResourceType,
214214
Subscription = string.IsNullOrEmpty(ResourceGroupName) ? null : DefaultProfile.DefaultContext.Subscription.Id.ToString()
215-
}
215+
},
216+
ExcludeAssignmentsForDeletedPrincipals = true
216217
};
217218

218-
WriteObject(PoliciesClient.FilterRoleAssignments(options, excludeAssignmentsForDeletedPrincipals: true), enumerateCollection: true);
219+
WriteObject(PoliciesClient.FilterRoleAssignments(options), enumerateCollection: true);
219220
}
220221
}
221222
}

src/ResourceManager/Resources/Commands.Resources/RoleAssignments/RemoveAzureRoleAssignmentCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ protected override void ProcessRecord()
149149
ResourceName = ResourceName,
150150
ResourceType = ResourceType,
151151
Subscription = DefaultProfile.DefaultContext.Subscription.Id.ToString()
152-
}
152+
},
153+
ExcludeAssignmentsForDeletedPrincipals = false
153154
};
154155

155156
ConfirmAction(

0 commit comments

Comments
 (0)