Skip to content

Commit 576ef2d

Browse files
committed
update commandlet to allowdelegation
1 parent 7ebbb37 commit 576ef2d

File tree

3 files changed

+45
-45
lines changed

3 files changed

+45
-45
lines changed

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/RoleAssignmentTests.ps1

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ Tests retrieval of classic administrators
1818
#>
1919
function Test-RaClassicAdmins
2020
{
21-
# Setup
22-
$subscription = Get-AzureRmSubscription
23-
24-
# Test
25-
$classic = Get-AzureRmRoleAssignment -IncludeClassicAdministrators | Where-Object { $_.Scope -ieq ('/subscriptions/' + $subscription[0].Id) -and $_.RoleDefinitionName.ToLower().Contains('administrator')}
26-
27-
# Assert
28-
Assert-NotNull $classic
29-
Assert-True { $classic.Length -ge 1 }
21+
# Setup
22+
$subscription = Get-AzureRmSubscription
23+
24+
# Test
25+
$classic = Get-AzureRmRoleAssignment -IncludeClassicAdministrators | Where-Object { $_.Scope -ieq ('/subscriptions/' + $subscription[0].Id) -and $_.RoleDefinitionName.ToLower().Contains('administrator')}
26+
27+
# Assert
28+
Assert-NotNull $classic
29+
Assert-True { $classic.Length -ge 1 }
3030
}
3131

3232
<#
@@ -41,11 +41,11 @@ function Test-RaNegativeScenarios
4141
# Bad OID returns zero role assignments
4242
$badOid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
4343
$badObjectResult = "Cannot find principal using the specified options"
44-
$assignments = Get-AzureRmRoleAssignment -ObjectId $badOid
44+
$assignments = Get-AzureRmRoleAssignment -ObjectId $badOid
4545
Assert-AreEqual 0 $assignments.Count
4646

47-
# Bad OID throws if Expand Principal Groups included
48-
Assert-Throws { Get-AzureRmRoleAssignment -ObjectId $badOid -ExpandPrincipalGroups } $badObjectResult
47+
# Bad OID throws if Expand Principal Groups included
48+
Assert-Throws { Get-AzureRmRoleAssignment -ObjectId $badOid -ExpandPrincipalGroups } $badObjectResult
4949

5050
# Bad UPN
5151
$badUpn = '[email protected]'
@@ -110,9 +110,9 @@ function Test-RaByScope
110110

111111
# Assert
112112
Assert-NotNull $newAssignment
113-
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
114-
Assert-AreEqual $scope $newAssignment.Scope
115-
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
113+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
114+
Assert-AreEqual $scope $newAssignment.Scope
115+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
116116

117117
VerifyRoleAssignmentDeleted $newAssignment
118118
}
@@ -142,8 +142,8 @@ function Test-RaByResourceGroup
142142

143143
# Assert
144144
Assert-NotNull $newAssignment
145-
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
146-
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
145+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
146+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
147147

148148
VerifyRoleAssignmentDeleted $newAssignment
149149
}
@@ -177,8 +177,8 @@ function Test-RaByResource
177177

178178
# Assert
179179
Assert-NotNull $newAssignment
180-
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
181-
Assert-AreEqual $groups[0].DisplayName $newAssignment.DisplayName
180+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
181+
Assert-AreEqual $groups[0].DisplayName $newAssignment.DisplayName
182182

183183
VerifyRoleAssignmentDeleted $newAssignment
184184
}
@@ -261,9 +261,9 @@ function Test-RaByServicePrincipal
261261

262262
# Assert
263263
Assert-NotNull $newAssignment
264-
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
265-
Assert-AreEqual $scope $newAssignment.Scope
266-
Assert-AreEqual $servicePrincipals[0].DisplayName $newAssignment.DisplayName
264+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
265+
Assert-AreEqual $scope $newAssignment.Scope
266+
Assert-AreEqual $servicePrincipals[0].DisplayName $newAssignment.DisplayName
267267

268268
VerifyRoleAssignmentDeleted $newAssignment
269269
}
@@ -282,7 +282,7 @@ function Test-RaByUpn
282282
Assert-AreEqual 1 $resourceGroups.Count "No resource group found. Unable to run the test."
283283

284284
# Test
285-
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("f8dac632-b879-42f9-b4ab-df2aab22a149")
285+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("f8dac632-b879-42f9-b4ab-df2aab22a149")
286286
$newAssignment = New-AzureRmRoleAssignment `
287287
-SignInName $users[0].UserPrincipalName `
288288
-RoleDefinitionName $definitionName `
@@ -293,8 +293,8 @@ function Test-RaByUpn
293293

294294
# Assert
295295
Assert-NotNull $newAssignment
296-
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
297-
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
296+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
297+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
298298

299299
VerifyRoleAssignmentDeleted $newAssignment
300300
}
@@ -305,11 +305,11 @@ function Test-RaUserPermissions
305305
param([string]$rgName, [string]$action)
306306
# Test
307307
$rg = Get-AzureRmResourceGroup
308-
$errorMsg = "User should have access to only 1 RG. Found: {0}" -f $rg.Count
309-
Assert-AreEqual 1 $rg.Count $errorMsg
308+
$errorMsg = "User should have access to only 1 RG. Found: {0}" -f $rg.Count
309+
Assert-AreEqual 1 $rg.Count $errorMsg
310310

311-
# User should not be able to create another RG as he doesnt have access to the subscription.
312-
Assert-Throws{ New-AzureRmResourceGroup -Name 'NewGroupFromTest' -Location 'WestUS'}
311+
# User should not be able to create another RG as he doesnt have access to the subscription.
312+
Assert-Throws{ New-AzureRmResourceGroup -Name 'NewGroupFromTest' -Location 'WestUS'}
313313
}
314314

315315
<#
@@ -451,7 +451,7 @@ function Test-RaDelegation
451451
-ObjectId $users[0].Id.Guid `
452452
-RoleDefinitionName $definitionName `
453453
-Scope $assignmentScope `
454-
-CanDelegate
454+
-AllowDelegation
455455

456456
# Assert
457457
Assert-NotNull $newAssignment

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public class NewAzureRoleAssignmentCommand : ResourcesBaseCmdlet
148148

149149
[Parameter(Mandatory = false, HelpMessage = "Delegation flag.")]
150150
[ValidateNotNullOrEmpty]
151-
public SwitchParameter CanDelegate { get; set; }
151+
public SwitchParameter AllowDelegation { get; set; }
152152

153153
public override void ExecuteCmdlet()
154154
{
@@ -171,7 +171,7 @@ public override void ExecuteCmdlet()
171171
ResourceType = ResourceType,
172172
Subscription = DefaultProfile.DefaultContext.Subscription.Id.ToString(),
173173
},
174-
CanDelegate = CanDelegate.IsPresent ? true : false,
174+
CanDelegate = AllowDelegation.IsPresent ? true : false,
175175
};
176176

177177
AuthorizationClient.ValidateScope(parameters.Scope, false);

src/ResourceManager/Resources/Commands.Resources/help/New-AzureRmRoleAssignment.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,70 +15,70 @@ Assigns the specified RBAC role to the specified principal, at the specified sco
1515

1616
### EmptyParameterSet (Default)
1717
```
18-
New-AzureRmRoleAssignment -ObjectId <Guid> -Scope <String> -RoleDefinitionName <String> [-CanDelegate]
18+
New-AzureRmRoleAssignment -ObjectId <Guid> -Scope <String> -RoleDefinitionName <String> [-AllowDelegation]
1919
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2020
```
2121

2222
### ResourceGroupWithObjectIdParameterSet
2323
```
24-
New-AzureRmRoleAssignment -ObjectId <Guid> -ResourceGroupName <String> -RoleDefinitionName <String> [-CanDelegate]
24+
New-AzureRmRoleAssignment -ObjectId <Guid> -ResourceGroupName <String> -RoleDefinitionName <String> [-AllowDelegation]
2525
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2626
```
2727

2828
### ResourceWithObjectIdParameterSet
2929
```
3030
New-AzureRmRoleAssignment -ObjectId <Guid> -ResourceGroupName <String> -ResourceName <String>
31-
-ResourceType <String> [-ParentResource <String>] -RoleDefinitionName <String> [-CanDelegate]
31+
-ResourceType <String> [-ParentResource <String>] -RoleDefinitionName <String> [-AllowDelegation]
3232
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
3333
```
3434

3535
### ScopeWithObjectIdParameterSet
3636
```
37-
New-AzureRmRoleAssignment -ObjectId <Guid> [-Scope <String>] -RoleDefinitionName <String> [-CanDelegate]
37+
New-AzureRmRoleAssignment -ObjectId <Guid> [-Scope <String>] -RoleDefinitionName <String> [-AllowDelegation]
3838
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
3939
```
4040

4141
### RoleIdWithScopeAndObjectIdParameterSet
4242
```
43-
New-AzureRmRoleAssignment -ObjectId <Guid> -Scope <String> -RoleDefinitionId <Guid> [-CanDelegate]
43+
New-AzureRmRoleAssignment -ObjectId <Guid> -Scope <String> -RoleDefinitionId <Guid> [-AllowDelegation]
4444
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
4545
```
4646

4747
### ResourceGroupWithSignInNameParameterSet
4848
```
49-
New-AzureRmRoleAssignment -SignInName <String> -ResourceGroupName <String> -RoleDefinitionName <String> [-CanDelegate]
49+
New-AzureRmRoleAssignment -SignInName <String> -ResourceGroupName <String> -RoleDefinitionName <String> [-AllowDelegation]
5050
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
5151
```
5252

5353
### ResourceWithSignInNameParameterSet
5454
```
5555
New-AzureRmRoleAssignment -SignInName <String> -ResourceGroupName <String> -ResourceName <String>
56-
-ResourceType <String> [-ParentResource <String>] -RoleDefinitionName <String> [-CanDelegate]
56+
-ResourceType <String> [-ParentResource <String>] -RoleDefinitionName <String> [-AllowDelegation]
5757
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
5858
```
5959

6060
### ScopeWithSignInNameParameterSet
6161
```
62-
New-AzureRmRoleAssignment -SignInName <String> [-Scope <String>] -RoleDefinitionName <String> [-CanDelegate]
62+
New-AzureRmRoleAssignment -SignInName <String> [-Scope <String>] -RoleDefinitionName <String> [-AllowDelegation]
6363
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
6464
```
6565

6666
### ResourceGroupWithSPNParameterSet
6767
```
68-
New-AzureRmRoleAssignment -ServicePrincipalName <String> -ResourceGroupName <String> [-CanDelegate]
68+
New-AzureRmRoleAssignment -ServicePrincipalName <String> -ResourceGroupName <String> [-AllowDelegation]
6969
-RoleDefinitionName <String> [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
7070
```
7171

7272
### ResourceWithSPNParameterSet
7373
```
7474
New-AzureRmRoleAssignment -ServicePrincipalName <String> -ResourceGroupName <String> -ResourceName <String>
75-
-ResourceType <String> [-ParentResource <String>] -RoleDefinitionName <String> [-CanDelegate]
75+
-ResourceType <String> [-ParentResource <String>] -RoleDefinitionName <String> [-AllowDelegation]
7676
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
7777
```
7878

7979
### ScopeWithSPNParameterSet
8080
```
81-
New-AzureRmRoleAssignment -ServicePrincipalName <String> [-Scope <String>] -RoleDefinitionName <String> [-CanDelegate]
81+
New-AzureRmRoleAssignment -ServicePrincipalName <String> [-Scope <String>] -RoleDefinitionName <String> [-AllowDelegation]
8282
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
8383
```
8484

@@ -109,7 +109,7 @@ ResourceName, ResourceType, ResourceGroupName and (optionally) ParentResource -
109109

110110
### -------------------------- Example 1 --------------------------
111111
```
112-
PS C:\> New-AzureRmRoleAssignment -ResourceGroupName rg1 -SignInName [email protected] -RoleDefinitionName Reader -CanDelegate
112+
PS C:\> New-AzureRmRoleAssignment -ResourceGroupName rg1 -SignInName [email protected] -RoleDefinitionName Reader -AllowDelegation
113113
```
114114

115115
Grant Reader role access to a user at a resource group scope with the Role Assignment being available for delegation
@@ -335,7 +335,7 @@ Accept pipeline input: True (ByPropertyName)
335335
Accept wildcard characters: False
336336
```
337337
338-
### -CanDelegate
338+
### -AllowDelegation
339339
The delegation flag while creating a Role assignment.
340340
341341
```yaml

0 commit comments

Comments
 (0)