Skip to content

. #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 25, 2015
Merged

. #109

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function Test-UpdateComputeNodeUser
{
param([string]$accountName, [string]$poolId, [string]$computeNodeId, [string]$userName)

$context = Get-AzureRMBatchAccountKeys -Name $accountName
$context = Get-AzureRmBatchAccountKeys -Name $accountName

# Basically just validating that we can set the parameters and execute the cmdlet without error.
# If a Get user API is added, we can validate that the properties were actually updated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function Test-UpdateJobSchedule
{
param([string]$accountName, [string]$jobScheduleId)

$context = Get-AzureRMBatchAccountKeys -Name $accountName
$context = Get-AzureRmBatchAccountKeys -Name $accountName

$jobSchedule = Get-AzureBatchJobSchedule_ST $jobScheduleId -BatchContext $context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ function Test-UpdateJob
{
param([string]$accountName, [string]$jobId)

$context = Get-AzureRMBatchAccountKeys -Name $accountName
$context = Get-AzureRmBatchAccountKeys -Name $accountName

# Create the job with an auto pool
$poolSpec = New-Object Microsoft.Azure.Commands.Batch.Models.PSPoolSpecification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function Test-UpdatePool
{
param([string]$accountName, [string]$poolId)

$context = Get-AzureRMBatchAccountKeys -Name $accountName
$context = Get-AzureRmBatchAccountKeys -Name $accountName

$pool = Get-AzureBatchPool_ST $poolId -BatchContext $context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function Test-UpdateTask
{
param([string]$accountName, [string]$jobId, [string]$taskId)

$context = Get-AzureRMBatchAccountKeys -Name $accountName
$context = Get-AzureRmBatchAccountKeys -Name $accountName

$task = Get-AzureBatchTask_ST $jobId $taskId -BatchContext $context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Microsoft.Azure.Commands.Batch
{
[Cmdlet(VerbsCommon.Get, Constants.AzureRMBatchAccount), OutputType(typeof(BatchAccountContext))]
[Cmdlet(VerbsCommon.Get, Constants.AzureRmBatchAccount), OutputType(typeof(BatchAccountContext))]
public class GetBatchAccountCommand : BatchCmdletBase
{
[Alias("Name")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace Microsoft.Azure.Commands.Batch
{
[Cmdlet(VerbsCommon.Get, Constants.AzureRMBatchAccountKeys), OutputType(typeof(BatchAccountContext))]
[Cmdlet(VerbsCommon.Get, Constants.AzureRmBatchAccountKeys), OutputType(typeof(BatchAccountContext))]
public class GetBatchAccountKeysCommand : BatchCmdletBase
{
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Microsoft.Azure.Commands.Batch
{
[Cmdlet(VerbsCommon.New, Constants.AzureRMBatchAccount), OutputType(typeof(BatchAccountContext))]
[Cmdlet(VerbsCommon.New, Constants.AzureRmBatchAccount), OutputType(typeof(BatchAccountContext))]
public class NewBatchAccountCommand : BatchCmdletBase
{
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Microsoft.Azure.Commands.Batch
{
[Cmdlet(VerbsCommon.New, Constants.AzureRMBatchAccountKey), OutputType(typeof(BatchAccountContext))]
[Cmdlet(VerbsCommon.New, Constants.AzureRmBatchAccountKey), OutputType(typeof(BatchAccountContext))]
public class RegenBatchAccountKeyCommand : BatchCmdletBase
{
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Microsoft.Azure.Commands.Batch
{
[Cmdlet(VerbsCommon.Remove, Constants.AzureRMBatchAccount)]
[Cmdlet(VerbsCommon.Remove, Constants.AzureRmBatchAccount)]
public class RemoveBatchAccountCommand : BatchCmdletBase
{
private static string mamlCall = "RemoveAccount";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Microsoft.Azure.Commands.Batch
{
[Cmdlet(VerbsCommon.Set, Constants.AzureRMBatchAccount), OutputType(typeof(BatchAccountContext))]
[Cmdlet(VerbsCommon.Set, Constants.AzureRmBatchAccount), OutputType(typeof(BatchAccountContext))]
public class SetBatchAccountCommand : BatchCmdletBase
{
[Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public class Constants
public const int DefaultMaxCount = 1000;

// ARM cmdlet nouns
public const string AzureRMBatchAccount = "AzureRmBatchAccount";
public const string AzureRMBatchAccountKey = "AzureRmBatchAccountKey";
public const string AzureRMBatchAccountKeys = "AzureRmBatchAccountKeys";
public const string AzureRmBatchAccount = "AzureRmBatchAccount";
public const string AzureRmBatchAccountKey = "AzureRmBatchAccountKey";
public const string AzureRmBatchAccountKeys = "AzureRmBatchAccountKeys";

// Batch Service cmdlet nouns
public const string AzureBatchPool = "AzureBatchPool";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</Reference>
<Reference Include="Microsoft.Azure.Graph.RBAC">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.1-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Insights">
<HintPath>..\..\..\packages\Microsoft.Azure.Insights.0.7.7-preview\lib\net45\Microsoft.Azure.Insights.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</Reference>
<Reference Include="Microsoft.Azure.Graph.RBAC">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.0-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.1.7.1-preview\lib\net40\Microsoft.Azure.Graph.RBAC.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.Authorization">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.1.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
Expand Down Expand Up @@ -165,9 +165,6 @@
<Compile Include="Models.Authorization\FilterRoleAssignmentsOptions.cs" />
<Compile Include="Models.ActiveDirectory\ActiveDirectoryClient.cs" />
<Compile Include="Models.Authorization\AuthorizationClientExtensions.cs" />
<Compile Include="Models.Authorization\PSGroupRoleAssignment.cs" />
<Compile Include="Models.Authorization\PSServiceRoleAssignment.cs" />
<Compile Include="Models.Authorization\PSUserRoleAssignment.cs" />
<Compile Include="Models.Authorization\PSRoleAssignment.cs" />
<Compile Include="Models.Authorization\PSRoleDefinition.cs" />
<Compile Include="Models.Authorization\PSPermission.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ADObjectFilterOptions
{
public string SearchString { get; set; }

public string SignInName { get; set; }

public string Mail { get; set; }

public string UPN { get; set; }
Expand Down Expand Up @@ -48,6 +50,8 @@ public string ActiveFilter
return SPN;
else if (!string.IsNullOrEmpty(Mail))
return Mail;
else if (!string.IsNullOrEmpty(SignInName))
return SignInName;
else if (!string.IsNullOrEmpty(SearchString))
return SearchString;
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public PSADObject GetADObject(ADObjectFilterOptions options)

Debug.Assert(options != null);

if (IsSet(options.Mail, options.UPN, options.Id))
if (IsSet(options.SignInName, options.Mail, options.UPN, options.Id))
{
result = FilterUsers(options).FirstOrDefault();
}
Expand Down Expand Up @@ -163,11 +163,11 @@ public List<PSADUser> FilterUsers(ADObjectFilterOptions options)
users.Add(user.ToPSADUser());
}
}
else if (!string.IsNullOrEmpty(options.Mail))
else if (!string.IsNullOrEmpty(options.Mail) || !string.IsNullOrEmpty(options.SignInName))
{
try
{
user = GraphClient.User.GetBySignInName(options.Mail).Users.FirstOrDefault();
user = GraphClient.User.GetBySignInName(Normalize(options.Mail) ?? Normalize(options.SignInName)).Users.FirstOrDefault();
}
catch { /* The user does not exist, ignore the exception. */ }

Expand Down Expand Up @@ -225,6 +225,14 @@ public List<PSADObject> ListUserGroups(string principal)
return result;
}

public List<PSADObject> GetObjectsByObjectId(List<string> objectIds)
{
List<PSADObject> result = new List<PSADObject>();
var adObjects = GraphClient.Objects.GetObjectsByObjectIds(new GetObjectsParameters { Ids = objectIds }).AADObject;
result.AddRange(adObjects.Select(o => o.ToPSADObject()));
return result;
}

public List<PSADGroup> FilterGroups(ADObjectFilterOptions options)
{
List<PSADGroup> groups = new List<PSADGroup>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static PSADObject ToPSADObject(this AADObject obj)
Id = new Guid(obj.ObjectId),
Type = obj.ObjectType,
UserPrincipalName = obj.UserPrincipalName,
SignInName = obj.SignInName,
Mail = obj.Mail
};
}
Expand All @@ -66,6 +67,16 @@ public static PSADObject ToPSADObject(this AADObject obj)
};

}
else if (obj.ObjectType == typeof(ServicePrincipal).Name)
{
return new PSADServicePrincipal()
{
DisplayName = obj.DisplayName,
Id = new Guid(obj.ObjectId),
Type = obj.ObjectType,
ServicePrincipalName = obj.ServicePrincipalNames.FirstOrDefault()
};
}
else
{
return new PSADObject()
Expand Down Expand Up @@ -93,7 +104,8 @@ public static PSADUser ToPSADUser(this User user)
DisplayName = user.DisplayName,
Id = new Guid(user.ObjectId),
UserPrincipalName = user.UserPrincipalName,
Mail = user.SignInName
Mail = user.SignInName,
SignInName = user.SignInName
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public class PSADUser : PSADObject
public string UserPrincipalName { get; set; }

public string Mail { get; set; }

public string SignInName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,34 @@ internal static class ParameterSet

public const string SPN = "SPNParameterSet";

public const string SignInName = "SignInNameParameterSet";

public const string SearchString = "SearchStringParameterSet";

public const string ObjectId = "ObjectIdParameterSet";

public const string Scope = "ScopeParameterSet";

public const string ScopeWithMail = "ScopeWithMailParameterSet";

public const string ScopeWithUPN = "ScopeWithUPNParameterSet";

public const string ScopeWithSPN = "ScopeWithSPNParameterSet";

public const string ScopeWithSignInName = "ScopeWithSignInNameParameterSet";

public const string ScopeWithObjectId = "ScopeWithObjectIdParameterSet";

public const string ResourceGroup = "ResourceGroupParameterSet";

public const string ResourceGroupWithMail = "ResourceGroupWithMailParameterSet";

public const string ResourceGroupWithUPN = "ResourceGroupWithUPNParameterSet";

public const string ResourceGroupWithSPN = "ResourceGroupWithSPNParameterSet";

public const string ResourceGroupWithObjectId = "ResourceGroupWithObjectIdParameterSet";

public const string Resource = "ResourceParameterSet";

public const string ResourceWithMail = "ResourceWithMailParameterSet";
public const string ResourceGroupWithSignInName = "ResourceGroupWithSignInNameParameterSet";

public const string ResourceWithUPN = "ResourceWithUPNParameterSet";
public const string Resource = "ResourceParameterSet";

public const string ResourceWithSPN = "ResourceWithSPNParameterSet";

public const string ResourceWithSignInName = "ResourceWithSignInNameParameterSet";

public const string ResourceWithObjectId = "ResourceWithObjectIdParameterSet";

public const string ApplicationWithoutCredential = "ApplicationWithoutCredentialParameterSet";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public PSRoleDefinition GetRoleDefinition(string roleId)

/// <summary>
/// Filters the existing role Definitions.
/// If name is not provided, all role definitions are fetched.
/// </summary>
/// <param name="name">The role name</param>
/// <returns>The matched role Definitions</returns>
Expand Down Expand Up @@ -122,7 +123,11 @@ public PSRoleAssignment CreateRoleAssignment(FilterRoleAssignmentsOptions parame
};

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

RoleAssignment assignment = AuthorizationManagementClient.RoleAssignments.Get(parameters.Scope, roleAssignmentId).RoleAssignment;
IEnumerable<RoleAssignment> assignments = new List<RoleAssignment>() { assignment };

return assignments.ToPSRoleAssignments(this, ActiveDirectoryClient).FirstOrDefault();
}

/// <summary>
Expand Down Expand Up @@ -159,9 +164,10 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
{
parameters.PrincipalId = string.IsNullOrEmpty(options.ADObjectFilter.Id) ? adObject.Id : Guid.Parse(options.ADObjectFilter.Id);
}

result.AddRange(AuthorizationManagementClient.RoleAssignments.List(parameters)
.RoleAssignments.Select(r => r.ToPSRoleAssignment(this, ActiveDirectoryClient, options.ExcludeAssignmentsForDeletedPrincipals)).Where(r => r != null));
.RoleAssignments.ToPSRoleAssignments(this, ActiveDirectoryClient, options.ExcludeAssignmentsForDeletedPrincipals));


// Filter out by scope
if (!string.IsNullOrEmpty(options.Scope))
Expand All @@ -173,13 +179,14 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
{
// Filter by scope and above directly
parameters.AtScope = true;

result.AddRange(AuthorizationManagementClient.RoleAssignments.ListForScope(options.Scope, parameters)
.RoleAssignments.Select(r => r.ToPSRoleAssignment(this, ActiveDirectoryClient, options.ExcludeAssignmentsForDeletedPrincipals)).Where(r => r != null));
.RoleAssignments.ToPSRoleAssignments(this, ActiveDirectoryClient, options.ExcludeAssignmentsForDeletedPrincipals));
}
else
{
result.AddRange(AuthorizationManagementClient.RoleAssignments.List(parameters)
.RoleAssignments.Select(r => r.ToPSRoleAssignment(this, ActiveDirectoryClient, options.ExcludeAssignmentsForDeletedPrincipals)).Where(r => r != null));
.RoleAssignments.ToPSRoleAssignments(this, ActiveDirectoryClient, options.ExcludeAssignmentsForDeletedPrincipals));
}

if (!string.IsNullOrEmpty(options.RoleDefinition))
Expand All @@ -204,7 +211,8 @@ public List<PSRoleAssignment> FilterRoleAssignments(FilterRoleAssignmentsOptions
var userObject = adObject as PSADUser;
classicAdministratorsAssignments = classicAdministratorsAssignments.Where(c =>
c.DisplayName.Equals(userObject.UserPrincipalName, StringComparison.OrdinalIgnoreCase) ||
c.DisplayName.Equals(userObject.Mail, StringComparison.OrdinalIgnoreCase)).ToList();
c.DisplayName.Equals(userObject.Mail, StringComparison.OrdinalIgnoreCase) ||
c.DisplayName.Equals(userObject.SignInName, StringComparison.OrdinalIgnoreCase)).ToList();
}

result.AddRange(classicAdministratorsAssignments);
Expand Down
Loading