Skip to content

Commit 4911c26

Browse files
committed
update RA calls with new version
1 parent 4c68486 commit 4911c26

File tree

14 files changed

+118
-70
lines changed

14 files changed

+118
-70
lines changed

src/ResourceManager/Resources/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
- Users can now use Set-AzureRMRoleRoleDefinition with assignable scopes including new scopes irrespective of the position of the scope
2525
* Allow scopes to end with "/"
2626
- Users can now use RoleDefinition and RoleAssignment commandlets with scopes ending with "/" ,consistent with API and CLI
27+
* Allow users to create RoleAssignment using delegation flag
28+
- Users can now use New-AzureRMRoleAssignment with an option of adding the delegation flag
2729

2830
## Version 5.0.0
2931
* Add support for online help

src/ResourceManager/Resources/Commands.Resources.Test/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<package id="Microsoft.Azure.Insights" version="0.10.0-preview" targetFramework="net45" />
99
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
1010
<package id="Microsoft.Azure.Management.ResourceManager" version="1.6.0-preview" targetFramework="net452" />
11+
<package id="Microsoft.Azure.Management.Authorization" version="2.6.0-preview" targetFramework="net45" />
1112
<package id="Microsoft.Azure.Management.Resources" version="2.20.0-preview" targetFramework="net45" />
1213
<package id="Microsoft.Azure.Test.Framework" version="1.0.6179.26854-prerelease" targetFramework="net45" />
1314
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.7-preview" targetFramework="net45" />

src/ResourceManager/Resources/Commands.Resources/Commands.Resources.Netcore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
2929
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
3030
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.4.0-preview" />
31-
<PackageReference Include="Microsoft.Azure.Management.Authorization" Version="2.5.0-preview" />
31+
<PackageReference Include="Microsoft.Azure.Management.Authorization" Version="2.6.0-preview" />
3232
<PackageReference Include="System.Collections.Specialized" Version="4.3.0" />
3333
<PackageReference Include="System.Reflection" Version="4.3.0" />
3434
<PackageReference Include="System.Security.SecureString" Version="4.3.0" />

src/ResourceManager/Resources/Commands.Resources/Commands.Resources.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5555
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
5656
</Reference>
57+
<Reference Include="Microsoft.Azure.Management.Authorization, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
58+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.6.0-preview\lib\net452\Microsoft.Azure.Management.Authorization.dll</HintPath>
59+
</Reference>
5760
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
5861
</ItemGroup>
5962
<ItemGroup>
@@ -144,10 +147,10 @@
144147
<Project>{70527617-7598-4aef-b5bd-db9186b8184b}</Project>
145148
<Name>Commands.Common.Authentication.Abstractions</Name>
146149
</ProjectReference>
147-
<ProjectReference Include="..\..\..\Common\Commands.Common.Authorization\Commands.Common.Authorization.csproj">
150+
<!-- <ProjectReference Include="..\..\..\Common\Commands.Common.Authorization\Commands.Common.Authorization.csproj">
148151
<Project>{24508e26-154d-47f1-80ee-439bf0710996}</Project>
149152
<Name>Commands.Common.Authorization</Name>
150-
</ProjectReference>
153+
</ProjectReference>-->
151154
<ProjectReference Include="..\..\..\Common\Commands.Common.Graph.RBAC\Commands.Common.Graph.RBAC.csproj">
152155
<Project>{269acf73-0a34-42dc-ab9c-4b15931a489d}</Project>
153156
<Name>Commands.Common.Graph.RBAC</Name>

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

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
1818
using Microsoft.Azure.Commands.Common.Authentication.Models;
1919
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
20-
using Microsoft.Azure.Management.Authorization.Version2015_07_01;
21-
using Microsoft.Azure.Management.Authorization.Version2015_07_01.Models;
20+
using Microsoft.Azure.Management.Authorization;
21+
using Microsoft.Azure.Management.Authorization.Models;
2222
using System;
2323
using System.Collections.Generic;
2424
using System.Linq;
@@ -152,7 +152,7 @@ public List<PSRoleDefinition> FilterRoleDefinitionsByCustom(string scope, bool s
152152
List<PSRoleDefinition> result = new List<PSRoleDefinition>();
153153
result.AddRange(AuthorizationManagementClient.RoleDefinitions.List(
154154
scope, scopeAndBelow ? new Rest.Azure.OData.ODataQuery<RoleDefinitionFilter>(filter => filter.AtScopeAndBelow()) : null)
155-
.Where(r => r.Properties.Type == AuthorizationClientExtensions.CustomRole)
155+
.Where(r => r.RoleType == AuthorizationClientExtensions.CustomRole)
156156
.Select(r => r.ToPSRoleDefinition()));
157157
return result;
158158
}
@@ -170,12 +170,12 @@ public PSRoleAssignment CreateRoleAssignment(FilterRoleAssignmentsOptions parame
170170
string roleDefinitionId = !string.IsNullOrEmpty(parameters.RoleDefinitionName)
171171
? AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromScopeAndIdAsGuid(scope, GetSingleRoleDefinitionByName(parameters.RoleDefinitionName, scope).Id)
172172
: AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromScopeAndIdAsGuid(scope, parameters.RoleDefinitionId);
173-
var createProperties = new RoleAssignmentProperties
173+
var createParameters = new RoleAssignmentCreateParameters
174174
{
175175
PrincipalId = principalId.ToString(),
176-
RoleDefinitionId = roleDefinitionId
176+
RoleDefinitionId = roleDefinitionId,
177+
CanDelegate = parameters.CanDelegate
177178
};
178-
var createParameters = new RoleAssignmentCreateParameters(createProperties);
179179

180180
RoleAssignment assignment = AuthorizationManagementClient.RoleAssignments.Create(
181181
parameters.Scope, roleAssignmentId.ToString(), createParameters);
@@ -473,22 +473,18 @@ private PSRoleDefinition CreateOrUpdateRoleDefinition(Guid roleDefinitionId, PSR
473473
PSRoleDefinition roleDef = null;
474474
var parameters = new RoleDefinition()
475475
{
476-
Name = roleDefinitionId.ToString(),
477-
Properties = new RoleDefinitionProperties()
478-
{
479-
AssignableScopes = roleDefinition.AssignableScopes,
480-
Description = roleDefinition.Description,
481-
Permissions = new List<Permission>()
476+
AssignableScopes = roleDefinition.AssignableScopes,
477+
Description = roleDefinition.Description,
478+
Permissions = new List<Permission>()
479+
{
480+
new Permission()
482481
{
483-
new Permission()
484-
{
485-
Actions = roleDefinition.Actions,
486-
NotActions = roleDefinition.NotActions
487-
}
488-
},
489-
RoleName = roleDefinition.Name,
490-
Type = "CustomRole"
491-
}
482+
Actions = roleDefinition.Actions,
483+
NotActions = roleDefinition.NotActions
484+
}
485+
},
486+
RoleName = roleDefinition.Name,
487+
RoleType = "CustomRole"
492488
};
493489

494490
try

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

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
using Hyak.Common;
1616
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
17-
using Microsoft.Azure.Management.Authorization.Version2015_07_01.Models;
17+
using Microsoft.Azure.Management.Authorization.Models;
1818
using System;
1919
using System.Collections.Generic;
2020
using System.Linq;
@@ -30,7 +30,7 @@ public static IEnumerable<RoleAssignment> FilterRoleAssignmentsOnRoleId(this IEn
3030
{
3131
if (!string.IsNullOrEmpty(roleId))
3232
{
33-
return assignments.Where(a => a.Properties.RoleDefinitionId.GuidFromFullyQualifiedId() == roleId);
33+
return assignments.Where(a => a.RoleDefinitionId.GuidFromFullyQualifiedId() == roleId);
3434
}
3535

3636
return assignments;
@@ -44,13 +44,13 @@ public static PSRoleDefinition ToPSRoleDefinition(this RoleDefinition role)
4444
{
4545
roleDefinition = new PSRoleDefinition
4646
{
47-
Name = role.Properties.RoleName,
48-
Actions = new List<string>(role.Properties.Permissions.SelectMany(r => r.Actions)),
49-
NotActions = new List<string>(role.Properties.Permissions.SelectMany(r => r.NotActions)),
47+
Name = role.RoleName,
48+
Actions = new List<string>(role.Permissions.SelectMany(r => r.Actions)),
49+
NotActions = new List<string>(role.Permissions.SelectMany(r => r.NotActions)),
5050
Id = role.Id.GuidFromFullyQualifiedId(),
51-
AssignableScopes = role.Properties.AssignableScopes.ToList(),
52-
Description = role.Properties.Description,
53-
IsCustom = role.Properties.Type == CustomRole ? true : false
51+
AssignableScopes = role.AssignableScopes.ToList(),
52+
Description = role.Description,
53+
IsCustom = role.RoleType == CustomRole ? true : false
5454
};
5555
}
5656

@@ -63,7 +63,7 @@ public static PSRoleAssignment ToPSRoleAssignment(this RoleAssignment assignment
6363

6464
try
6565
{
66-
roleDefinitions = new List<PSRoleDefinition> { policyClient.GetRoleDefinition(assignment.Properties.RoleDefinitionId) };
66+
roleDefinitions = new List<PSRoleDefinition> { policyClient.GetRoleDefinition(assignment.RoleDefinitionId) };
6767
}
6868
catch (CloudException ce)
6969
{
@@ -116,17 +116,17 @@ private static IEnumerable<PSRoleAssignment> ToPSRoleAssignments(this IEnumerabl
116116
}
117117

118118
List<string> objectIds = new List<string>();
119-
objectIds.AddRange(assignments.Select(r => r.Properties.PrincipalId.ToString()));
119+
objectIds.AddRange(assignments.Select(r => r.PrincipalId.ToString()));
120120
List<PSADObject> adObjects = activeDirectoryClient.GetObjectsByObjectId(objectIds);
121121

122122
foreach (RoleAssignment assignment in assignments)
123123
{
124-
assignment.Properties.RoleDefinitionId = assignment.Properties.RoleDefinitionId.GuidFromFullyQualifiedId();
125-
PSADObject adObject = adObjects.SingleOrDefault(o => o.Id == Guid.Parse(assignment.Properties.PrincipalId)) ??
126-
new PSADObject() { Id = Guid.Parse(assignment.Properties.PrincipalId) };
127-
PSRoleDefinition roleDefinition = roleDefinitions.SingleOrDefault(r => r.Id == assignment.Properties.RoleDefinitionId) ??
128-
new PSRoleDefinition() { Id = assignment.Properties.RoleDefinitionId };
129-
124+
assignment.RoleDefinitionId = assignment.RoleDefinitionId.GuidFromFullyQualifiedId();
125+
PSADObject adObject = adObjects.SingleOrDefault(o => o.Id == Guid.Parse(assignment.PrincipalId)) ??
126+
new PSADObject() { Id = Guid.Parse(assignment.PrincipalId) };
127+
PSRoleDefinition roleDefinition = roleDefinitions.SingleOrDefault(r => r.Id == assignment.RoleDefinitionId) ??
128+
new PSRoleDefinition() { Id = assignment.RoleDefinitionId };
129+
bool delegationFlag = assignment.CanDelegate.HasValue ? (bool)assignment.CanDelegate : false;
130130
if (adObject is PSADUser)
131131
{
132132
psAssignments.Add(new PSRoleAssignment()
@@ -135,10 +135,11 @@ private static IEnumerable<PSRoleAssignment> ToPSRoleAssignments(this IEnumerabl
135135
DisplayName = adObject.DisplayName,
136136
RoleDefinitionId = roleDefinition.Id,
137137
RoleDefinitionName = roleDefinition.Name,
138-
Scope = assignment.Properties.Scope,
138+
Scope = assignment.Scope,
139139
SignInName = ((PSADUser)adObject).UserPrincipalName,
140140
ObjectId = adObject.Id,
141-
ObjectType = adObject.Type
141+
ObjectType = adObject.Type,
142+
CanDelegate = delegationFlag
142143
});
143144
}
144145
else if (adObject is PSADGroup)
@@ -149,9 +150,10 @@ private static IEnumerable<PSRoleAssignment> ToPSRoleAssignments(this IEnumerabl
149150
DisplayName = adObject.DisplayName,
150151
RoleDefinitionId = roleDefinition.Id,
151152
RoleDefinitionName = roleDefinition.Name,
152-
Scope = assignment.Properties.Scope,
153+
Scope = assignment.Scope,
153154
ObjectId = adObject.Id,
154-
ObjectType = adObject.Type
155+
ObjectType = adObject.Type,
156+
CanDelegate = delegationFlag
155157
});
156158
}
157159
else if (adObject is PSADServicePrincipal)
@@ -162,9 +164,10 @@ private static IEnumerable<PSRoleAssignment> ToPSRoleAssignments(this IEnumerabl
162164
DisplayName = adObject.DisplayName,
163165
RoleDefinitionId = roleDefinition.Id,
164166
RoleDefinitionName = roleDefinition.Name,
165-
Scope = assignment.Properties.Scope,
167+
Scope = assignment.Scope,
166168
ObjectId = adObject.Id,
167-
ObjectType = adObject.Type
169+
ObjectType = adObject.Type,
170+
CanDelegate = delegationFlag
168171
});
169172
}
170173
else if (!excludeAssignmentsForDeletedPrincipals)
@@ -175,8 +178,9 @@ private static IEnumerable<PSRoleAssignment> ToPSRoleAssignments(this IEnumerabl
175178
DisplayName = adObject.DisplayName,
176179
RoleDefinitionId = roleDefinition.Id,
177180
RoleDefinitionName = roleDefinition.Name,
178-
Scope = assignment.Properties.Scope,
181+
Scope = assignment.Scope,
179182
ObjectId = adObject.Id,
183+
CanDelegate = delegationFlag
180184
});
181185
}
182186

@@ -190,9 +194,9 @@ public static PSRoleAssignment ToPSRoleAssignment(this ClassicAdministrator clas
190194
{
191195
return new PSRoleAssignment()
192196
{
193-
RoleDefinitionName = classicAdministrator.Properties.Role,
194-
DisplayName = classicAdministrator.Properties.EmailAddress,
195-
SignInName = classicAdministrator.Properties.EmailAddress,
197+
RoleDefinitionName = classicAdministrator.Role,
198+
DisplayName = classicAdministrator.EmailAddress,
199+
SignInName = classicAdministrator.EmailAddress,
196200
Scope = AuthorizationHelper.GetSubscriptionScope(currentSubscriptionId),
197201
ObjectType = "User"
198202
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@ public string Scope
6060
public bool IncludeClassicAdministrators { get; set; }
6161

6262
public bool ExcludeAssignmentsForDeletedPrincipals { get; set; }
63+
64+
public bool CanDelegate { get; set; }
6365
}
6466
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ public class PSRoleAssignment
3333
public Guid ObjectId { get; set; }
3434

3535
public string ObjectType { get; set; }
36+
37+
public bool CanDelegate { get; set; }
3638
}
3739
}

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourceClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
2020
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
2121
using Microsoft.Azure.Commands.Resources.Models.Authorization;
22-
using Microsoft.Azure.Management.Authorization.Version2015_07_01;
23-
using Microsoft.Azure.Management.Authorization.Version2015_07_01.Models;
22+
using Microsoft.Azure.Management.Authorization;
23+
using Microsoft.Azure.Management.Authorization.Models;
2424
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2525
using Newtonsoft.Json;
2626
using System;

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourcesExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
using Microsoft.Azure.Commands.Common.Authentication;
2222
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
2323
using Microsoft.Azure.Commands.Resources.Models.Authorization;
24-
using Microsoft.Azure.Management.Authorization.Version2015_07_01.Models;
24+
using Microsoft.Azure.Management.Authorization.Models;
2525
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2626
using Newtonsoft.Json;
2727
using Microsoft.WindowsAzure.Commands.Common;

src/ResourceManager/Resources/Commands.Resources/Providers/GetAzureProviderOperationCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Microsoft.Azure.Commands.Resources
2222
using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;
2323
using Microsoft.Azure.Management.ResourceManager;
2424
using Microsoft.Azure.Management.ResourceManager.Models;
25-
using Microsoft.Azure.Management.Authorization.Version2015_07_01.Models;
25+
using Microsoft.Azure.Management.Authorization.Models;
2626

2727
/// <summary>
2828
/// Get an existing resource.

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,29 @@ public class NewAzureRoleAssignmentCommand : ResourcesBaseCmdlet
146146
[ValidateGuidNotEmpty]
147147
public Guid RoleDefinitionId { get; set; }
148148

149+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.Empty,
150+
HelpMessage = "Delegation flag.")]
151+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ScopeWithObjectId,
152+
HelpMessage = "Delegation flag.")]
153+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ScopeWithSignInName,
154+
HelpMessage = "Delegation flag.")]
155+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ScopeWithSPN,
156+
HelpMessage = "Delegation flag.")]
157+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ResourceGroupWithObjectId,
158+
HelpMessage = "Delegation flag.")]
159+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ResourceWithObjectId,
160+
HelpMessage = "Delegation flag.")]
161+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ResourceGroupWithSignInName,
162+
HelpMessage = "Delegation flag.")]
163+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ResourceWithSignInName,
164+
HelpMessage = "Delegation flag.")]
165+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ResourceGroupWithSPN,
166+
HelpMessage = "Delegation flag.")]
167+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ResourceWithSPN,
168+
HelpMessage = "Delegation flag.")]
169+
[ValidateNotNullOrEmpty]
170+
public bool CanDelegate { get; set; }
171+
149172
public override void ExecuteCmdlet()
150173
{
151174
FilterRoleAssignmentsOptions parameters = new FilterRoleAssignmentsOptions()
@@ -166,7 +189,8 @@ public override void ExecuteCmdlet()
166189
ResourceName = ResourceName,
167190
ResourceType = ResourceType,
168191
Subscription = DefaultProfile.DefaultContext.Subscription.Id.ToString(),
169-
}
192+
},
193+
CanDelegate = CanDelegate
170194
};
171195

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

0 commit comments

Comments
 (0)