Skip to content

Commit

Permalink
Merge pull request Azure#50 from huangpf/crp2
Browse files Browse the repository at this point in the history
Crp2
  • Loading branch information
AzureRT committed Apr 14, 2015
2 parents af58849 + e825309 commit ae36ae7
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@
<Content Include="ScenarioTests\AuthorizationTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Resources\NewRoleDefinition.json" />
<None Include="Resources\RoleDefinition.json" />
<None Include="Resources\NewRoleDefinition.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\ActiveDirectoryTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -270,7 +271,9 @@
<None Include="ScenarioTests\RoleAssignmentTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\RoleDefinitionTests.ps1" />
<None Include="ScenarioTests\RoleDefinitionTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests\TestGetADUserWithMail.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
<Compile Include="Models.Authorization\AuthorizationClient.cs" />
<Compile Include="ProviderFeatures\RegisterAzureProviderFeatureCmdlet.cs" />
<Compile Include="Providers\GetAzureProviderCmdlet.cs" />
<Compile Include="Providers\GetAzureProviderOperationCmdlet.cs" />
<Compile Include="Providers\GetAzureProviderOperationCmdlet.cs" />
<Compile Include="Providers\RegisterAzureProviderCmdlet.cs" />
<Compile Include="Providers\UnregisterAzureProviderCmdlet.cs" />
<Compile Include="ResourceGroups\GetAzureResourceGroupLogCommand.cs" />
Expand All @@ -205,8 +205,6 @@
<Compile Include="RoleAssignments\NewAzureRoleAssignmentCommand.cs" />
<Compile Include="RoleDefinitions\GetAzureRoleDefinitionCommand.cs" />
<Compile Include="RoleDefinitions\NewAzureRoleDefinitionCommand.cs" />
<Compile Include="RoleDefinitions\RemoveAzureRoleDefinitionCommand.cs" />
<Compile Include="RoleDefinitions\SetAzureRoleDefinitionCommand.cs" />
<Compile Include="Templates\TestAzureResourceGroupTemplateCommand.cs" />
<Compile Include="Templates\SaveAzureResourceGroupGalleryTemplateCommand.cs" />
<Compile Include="Templates\GetAzureResourceGroupGalleryTemplateCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Commands.Resources.Models.ActiveDirectory;
using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Common.Authentication.Models;
using Microsoft.Azure.Management.Authorization;
using Microsoft.Azure.Management.Authorization.Models;
using Microsoft.Azure.Common.Authentication.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;
using Microsoft.Azure.Common.Authentication;

namespace Microsoft.Azure.Commands.Resources.Models.Authorization
{
Expand Down Expand Up @@ -92,13 +92,14 @@ public PSRoleAssignment CreateRoleAssignment(FilterRoleAssignmentsOptions parame

RoleAssignmentCreateParameters createParameters = new RoleAssignmentCreateParameters
{
Properties = new RoleAssignmentProperties() { PrincipalId = principalId, RoleDefinitionId = roleDefinitionId }
Properties = new RoleAssignmentProperties {
PrincipalId = principalId,
RoleDefinitionId = roleDefinitionId
}
};

AuthorizationManagementClient.RoleAssignments.Create(parameters.Scope, roleAssignmentId, createParameters);
return
AuthorizationManagementClient.RoleAssignments.Get(parameters.Scope, roleAssignmentId)
.RoleAssignment.ToPSRoleAssignment(this, ActiveDirectoryClient);
return AuthorizationManagementClient.RoleAssignments.Get(parameters.Scope, roleAssignmentId).RoleAssignment.ToPSRoleAssignment(this, ActiveDirectoryClient);
}

/// <summary>
Expand Down Expand Up @@ -166,26 +167,6 @@ public PSRoleAssignment RemoveRoleAssignment(FilterRoleAssignmentsOptions option
return roleAssignment;
}

/// <summary>
/// Deletes a role definition based on the id.
/// </summary>
/// <param name="id">The role definition id.</param>
/// <returns>The deleted role definition.</returns>
public PSRoleDefinition RemoveRoleDefinition(string id)
{
PSRoleDefinition roleDefinition = this.GetRoleDefinition(id);
if (roleDefinition != null)
{
AuthorizationManagementClient.RoleDefinitions.Delete(roleDefinition.Id);
}
else
{
throw new KeyNotFoundException(string.Format(ProjectResources.RoleDefinitionWithIdNotFound, id));
}

return roleDefinition;
}

public PSRoleDefinition GetRoleRoleDefinition(string name)
{
PSRoleDefinition role = FilterRoleDefinitions(name).FirstOrDefault();
Expand Down Expand Up @@ -246,59 +227,5 @@ private static void ValidateRoleDefinition(PSRoleDefinition roleDefinition)
throw new ArgumentException(ProjectResources.InvalidActions);
}
}

/// <summary>
/// Updates a role definiton.
/// </summary>
/// <param name="role">The role definition to update.</param>
/// <returns>The updated role definition.</returns>
public PSRoleDefinition UpdateRoleDefinition(PSRoleDefinition role)
{
PSRoleDefinition roleDefinition = this.GetRoleDefinition(role.Id);
if (roleDefinition == null)
{
throw new KeyNotFoundException(string.Format(ProjectResources.RoleDefinitionWithIdNotFound, role.Id));
}

roleDefinition.Name = role.Name ?? roleDefinition.Name;
roleDefinition.Actions = role.Actions ?? roleDefinition.Actions;
roleDefinition.NotActions = role.NotActions ?? roleDefinition.NotActions;
roleDefinition.AssignableScopes = role.AssignableScopes ?? roleDefinition.AssignableScopes;
roleDefinition.Description = role.Description ?? roleDefinition.Description;

// TODO: confirm with ARM on what exception will be thrown when the last segment of the roleDefinition's ID is not a GUID.
// This will be done after their API is designed.
string[] scopes = roleDefinition.Id.Split('/');
Guid roleDefinitionId = Guid.Parse(scopes.Last());

// TODO: update to include assignable scopes.
return
AuthorizationManagementClient.RoleDefinitions.CreateOrUpdate(
roleDefinitionId,
new RoleDefinitionCreateOrUpdateParameters()
{
RoleDefinition = new RoleDefinition()
{
Id = roleDefinition.Id,
Name = roleDefinitionId,
Properties =
new RoleDefinitionProperties()
{
RoleName = roleDefinition.Name,
Permissions =
new List<Permission>()
{
new Permission()
{
Actions = roleDefinition.Actions,
NotActions = roleDefinition.NotActions
}
},
AssignableScopes = roleDefinition.AssignableScopes,
Description = roleDefinition.Description
}
}
}).RoleDefinition.ToPSRoleDefinition();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<value>Invalid tag format. Ensure that each tag has a unique name. Example: @{Name = "tagName1"; Value = "tagValue1"}, @{Name = "tagName2"; Value = "tagValue2"}</value>
</data>
<data name="RoleDefinitionNotFound" xml:space="preserve">
<value>Cannot find role definition with name '{0}'.</value>
<value>Can not find role definition with name '{0}'.</value>
</data>
<data name="RemoveApplication" xml:space="preserve">
<value>Removing application ...</value>
Expand Down Expand Up @@ -297,4 +297,4 @@
<data name="InvalidAssignableScopes" xml:space="preserve">
<value>Invalid value for AssignableScopes</value>
</data>
</root>
</root>

This file was deleted.

This file was deleted.

Loading

0 comments on commit ae36ae7

Please sign in to comment.