|
12 | 12 | // limitations under the License.
|
13 | 13 | // ----------------------------------------------------------------------------------
|
14 | 14 |
|
15 |
| -using System; |
16 |
| -using System.Collections.Generic; |
17 |
| -using System.Linq; |
18 | 15 | using Microsoft.Azure.Commands.Resources.Models.ActiveDirectory;
|
19 |
| -using Microsoft.Azure.Common.Authentication; |
20 |
| -using Microsoft.Azure.Common.Authentication.Models; |
21 | 16 | using Microsoft.Azure.Management.Authorization;
|
22 | 17 | using Microsoft.Azure.Management.Authorization.Models;
|
| 18 | +using Microsoft.Azure.Common.Authentication.Models; |
| 19 | +using System; |
| 20 | +using System.Collections.Generic; |
| 21 | +using System.Linq; |
23 | 22 | using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;
|
| 23 | +using Microsoft.Azure.Common.Authentication; |
24 | 24 |
|
25 | 25 | namespace Microsoft.Azure.Commands.Resources.Models.Authorization
|
26 | 26 | {
|
@@ -92,13 +92,14 @@ public PSRoleAssignment CreateRoleAssignment(FilterRoleAssignmentsOptions parame
|
92 | 92 |
|
93 | 93 | RoleAssignmentCreateParameters createParameters = new RoleAssignmentCreateParameters
|
94 | 94 | {
|
95 |
| - Properties = new RoleAssignmentProperties() { PrincipalId = principalId, RoleDefinitionId = roleDefinitionId } |
| 95 | + Properties = new RoleAssignmentProperties { |
| 96 | + PrincipalId = principalId, |
| 97 | + RoleDefinitionId = roleDefinitionId |
| 98 | + } |
96 | 99 | };
|
97 | 100 |
|
98 | 101 | AuthorizationManagementClient.RoleAssignments.Create(parameters.Scope, roleAssignmentId, createParameters);
|
99 |
| - return |
100 |
| - AuthorizationManagementClient.RoleAssignments.Get(parameters.Scope, roleAssignmentId) |
101 |
| - .RoleAssignment.ToPSRoleAssignment(this, ActiveDirectoryClient); |
| 102 | + return AuthorizationManagementClient.RoleAssignments.Get(parameters.Scope, roleAssignmentId).RoleAssignment.ToPSRoleAssignment(this, ActiveDirectoryClient); |
102 | 103 | }
|
103 | 104 |
|
104 | 105 | /// <summary>
|
@@ -166,26 +167,6 @@ public PSRoleAssignment RemoveRoleAssignment(FilterRoleAssignmentsOptions option
|
166 | 167 | return roleAssignment;
|
167 | 168 | }
|
168 | 169 |
|
169 |
| - /// <summary> |
170 |
| - /// Deletes a role definition based on the id. |
171 |
| - /// </summary> |
172 |
| - /// <param name="id">The role definition id.</param> |
173 |
| - /// <returns>The deleted role definition.</returns> |
174 |
| - public PSRoleDefinition RemoveRoleDefinition(string id) |
175 |
| - { |
176 |
| - PSRoleDefinition roleDefinition = this.GetRoleDefinition(id); |
177 |
| - if (roleDefinition != null) |
178 |
| - { |
179 |
| - AuthorizationManagementClient.RoleDefinitions.Delete(roleDefinition.Id); |
180 |
| - } |
181 |
| - else |
182 |
| - { |
183 |
| - throw new KeyNotFoundException(string.Format(ProjectResources.RoleDefinitionWithIdNotFound, id)); |
184 |
| - } |
185 |
| - |
186 |
| - return roleDefinition; |
187 |
| - } |
188 |
| - |
189 | 170 | public PSRoleDefinition GetRoleRoleDefinition(string name)
|
190 | 171 | {
|
191 | 172 | PSRoleDefinition role = FilterRoleDefinitions(name).FirstOrDefault();
|
@@ -246,59 +227,5 @@ private static void ValidateRoleDefinition(PSRoleDefinition roleDefinition)
|
246 | 227 | throw new ArgumentException(ProjectResources.InvalidActions);
|
247 | 228 | }
|
248 | 229 | }
|
249 |
| - |
250 |
| - /// <summary> |
251 |
| - /// Updates a role definiton. |
252 |
| - /// </summary> |
253 |
| - /// <param name="role">The role definition to update.</param> |
254 |
| - /// <returns>The updated role definition.</returns> |
255 |
| - public PSRoleDefinition UpdateRoleDefinition(PSRoleDefinition role) |
256 |
| - { |
257 |
| - PSRoleDefinition roleDefinition = this.GetRoleDefinition(role.Id); |
258 |
| - if (roleDefinition == null) |
259 |
| - { |
260 |
| - throw new KeyNotFoundException(string.Format(ProjectResources.RoleDefinitionWithIdNotFound, role.Id)); |
261 |
| - } |
262 |
| - |
263 |
| - roleDefinition.Name = role.Name ?? roleDefinition.Name; |
264 |
| - roleDefinition.Actions = role.Actions ?? roleDefinition.Actions; |
265 |
| - roleDefinition.NotActions = role.NotActions ?? roleDefinition.NotActions; |
266 |
| - roleDefinition.AssignableScopes = role.AssignableScopes ?? roleDefinition.AssignableScopes; |
267 |
| - roleDefinition.Description = role.Description ?? roleDefinition.Description; |
268 |
| - |
269 |
| - // TODO: confirm with ARM on what exception will be thrown when the last segment of the roleDefinition's ID is not a GUID. |
270 |
| - // This will be done after their API is designed. |
271 |
| - string[] scopes = roleDefinition.Id.Split('/'); |
272 |
| - Guid roleDefinitionId = Guid.Parse(scopes.Last()); |
273 |
| - |
274 |
| - // TODO: update to include assignable scopes. |
275 |
| - return |
276 |
| - AuthorizationManagementClient.RoleDefinitions.CreateOrUpdate( |
277 |
| - roleDefinitionId, |
278 |
| - new RoleDefinitionCreateOrUpdateParameters() |
279 |
| - { |
280 |
| - RoleDefinition = new RoleDefinition() |
281 |
| - { |
282 |
| - Id = roleDefinition.Id, |
283 |
| - Name = roleDefinitionId, |
284 |
| - Properties = |
285 |
| - new RoleDefinitionProperties() |
286 |
| - { |
287 |
| - RoleName = roleDefinition.Name, |
288 |
| - Permissions = |
289 |
| - new List<Permission>() |
290 |
| - { |
291 |
| - new Permission() |
292 |
| - { |
293 |
| - Actions = roleDefinition.Actions, |
294 |
| - NotActions = roleDefinition.NotActions |
295 |
| - } |
296 |
| - }, |
297 |
| - AssignableScopes = roleDefinition.AssignableScopes, |
298 |
| - Description = roleDefinition.Description |
299 |
| - } |
300 |
| - } |
301 |
| - }).RoleDefinition.ToPSRoleDefinition(); |
302 |
| - } |
303 | 230 | }
|
304 | 231 | }
|
0 commit comments