Skip to content
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

Managed services cmdlet changes #12105

Merged
merged 25 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
23ae023
New-AzManagedServicesDefinition changes
skayani May 14, 2020
12c0466
Get-AzManagedServicesDefinition changes
skayani May 14, 2020
bc030a4
Remove-AzManagedServicesDefinition changes
skayani May 14, 2020
02a8d8b
New-AzManagedServicesAssignment changes
skayani May 14, 2020
d60a00b
Get-AzManagedServicesAssignment changes
skayani May 15, 2020
200d68c
Remove-AzManagedServicesAssignment changes
skayani May 15, 2020
722d2bb
Made consistency changes
skayani May 15, 2020
8fb2e07
Small name fix
skayani May 15, 2020
27b38eb
Made suggested changes by Ramu
skayani May 15, 2020
c0f21a8
Made changes suggested by Ramu - updated examples
skayani Jun 2, 2020
acb21a9
Changed gets to return 'Scope'
skayani Jun 5, 2020
ec7a927
Updated ChangeLog.md + added header for newly added file
skayani Jun 5, 2020
8d25152
Fixed spacing issues in Get cmdlet .md files
skayani Jun 5, 2020
a75a77e
Update ChangeLog.md
VeryEarly Jun 10, 2020
354650a
Merge remote-tracking branch 'upstream/master' into managedServicesCm…
skayani Aug 24, 2020
64d5805
Added missing comment line
skayani Aug 26, 2020
ff8de39
Add new parameters for authorizations list and other changes to impro…
dramuy Sep 4, 2020
33699b7
Update the unit test to include the breaking change with displayName …
dramuy Sep 9, 2020
f9a8165
Changed Authorizations parameter to Authorization and added PassThru …
skayani Sep 14, 2020
6ff9e3d
Changed remove cmdlet return types to bool && git push
skayani Sep 15, 2020
ce2349f
Merge remote-tracking branch 'upstream/master' into managedServicesCm…
skayani Sep 22, 2020
484678c
Merge branch 'master' into managedServicesCmdletChanges
skayani Oct 9, 2020
3caf919
Suppressed breaking changes for S177 milestone
skayani Oct 13, 2020
c4fbbb1
Changed BreakingChangesIssues.csv -> BreakingChangeIssues.csv
skayani Oct 14, 2020
fbb982b
Update ChangeLog.md
VeryEarly Oct 15, 2020
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 @@ -17,13 +17,13 @@
Create, update, and delete registration assignments and registration definitions
#>

function New-AzManagedServicesAssignmentWithId
function New-AzManagedServicesAssignmentWithName
{
[CmdletBinding()]
param(
[string] [Parameter()] $Scope,
[string] [Parameter()] $RegistrationDefinitionResourceId,
[Guid] [Parameter()] $RegistrationAssignmentId
[string] [Parameter()] $RegistrationDefinitionName,
[string] [Parameter()] $Name
)

$profile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
Expand All @@ -36,29 +36,29 @@ function New-AzManagedServicesAssignmentWithId
$cmdlet.Scope = $Scope
}

if (-not ([string]::IsNullOrEmpty($RegistrationDefinitionResourceId)))
if (-not ([string]::IsNullOrEmpty($RegistrationDefinitionName)))
{
$cmdlet.RegistrationDefinitionResourceId = $RegistrationDefinitionResourceId
$cmdlet.RegistrationDefinitionName = $RegistrationDefinitionName
}

if ($RegistrationAssignmentId -ne $null -and $RegistrationAssignmentId -ne [System.Guid]::Empty)
if ($Name -ne $null -and $Name -ne [System.Guid]::Empty)
{
$cmdlet.RegistrationAssignmentId = $RegistrationAssignmentId
$cmdlet.Name = $Name
}

$cmdlet.ExecuteCmdlet()
}

function New-AzManagedServicesDefinitionWithId
function New-AzManagedServicesDefinitionWithName
{
[CmdletBinding()]
param(
[string] [Parameter()] $Name,
[string] [Parameter()] $DisplayName,
[string] [Parameter()] $ManagedByTenantId,
[string] [Parameter()] $PrincipalId,
[string] [Parameter()] $RoleDefinitionId,
[string] [Parameter()] $Description,
[Guid] [Parameter()] $RegistrationDefinitionId
[string] [Parameter()] $Name
)

$profile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
Expand All @@ -71,9 +71,9 @@ function New-AzManagedServicesDefinitionWithId
$cmdlet.Description = $Description
}

if (-not ([string]::IsNullOrEmpty($Name)))
if (-not ([string]::IsNullOrEmpty($DisplayName)))
{
$cmdlet.Name = $Name
$cmdlet.DisplayName = $DisplayName
}

if (-not ([string]::IsNullOrEmpty($ManagedByTenantId)))
Expand All @@ -91,9 +91,9 @@ function New-AzManagedServicesDefinitionWithId
$cmdlet.RoleDefinitionId = $RoleDefinitionId
}

if ($RegistrationDefinitionId -ne $null -and $RegistrationDefinitionId -ne [System.Guid]::Empty)
if ($Name -ne $null -and $Name -ne [System.Guid]::Empty)
{
$cmdlet.RegistrationDefinitionId = $RegistrationDefinitionId
$cmdlet.Name = $Name
}

$cmdlet.ExecuteCmdlet()
Expand All @@ -110,7 +110,7 @@ function Test-ManagedServices_CRUD
$definitionId = "1ccdb215-959a-48b9-bd7c-0584d461ea6c"

#put def
$definition = New-AzManagedServicesDefinitionWithId -ManagedByTenantId $managedByTenantId -RoleDefinitionId $roleDefinitionId -PrincipalId $principalId -Name $name -RegistrationDefinitionId $definitionId
$definition = New-AzManagedServicesDefinitionWithName -ManagedByTenantId $managedByTenantId -RoleDefinitionId $roleDefinitionId -PrincipalId $principalId -DisplayName $name -Name $definitionId

Assert-AreEqual $name $definition.Properties.Name
Assert-AreEqual $managedByTenantId $definition.Properties.ManagedByTenantId
Expand All @@ -121,24 +121,26 @@ function Test-ManagedServices_CRUD
$getDef = Get-AzManagedServicesDefinition -Name $definitionId
Assert-NotNull $getDef
Assert-AreEqual $definition.Id $getDef.Id
Assert-NotNull $getDef.Scope

#put assignment
$assignment = New-AzManagedServicesAssignmentWithId `
-RegistrationDefinitionResourceId $definition.Id `
-RegistrationAssignmentId $assignmentId
$assignment = New-AzManagedServicesAssignmentWithName `
-RegistrationDefinitionName $definition.Name `
-Name $assignmentId
Assert-NotNull $assignment

#get assignment
$getAssignment = Get-AzManagedServicesAssignment -Id $assignmentId -ExpandRegistrationDefinition
$getAssignment = Get-AzManagedServicesAssignment -Name $assignmentId -ExpandRegistrationDefinition
Assert-NotNull $getAssignment
Assert-AreEqual $assignment.Id $getAssignment.Id
Assert-AreEqual $definition.Id $getAssignment.Properties.RegistrationDefinitionId
Assert-AreEqual $getDef.Scope $getAssignment.Scope

#remove assignment
Remove-AzManagedServicesAssignment -Id $assignmentId
Remove-AzManagedServicesAssignment -Name $assignmentId

#remove definition
Remove-AzManagedServicesDefinition -Id $definitionId
Remove-AzManagedServicesDefinition -Name $definitionId

#list assignments
$assignments = Get-AzManagedServicesAssignment
Expand Down
1 change: 1 addition & 0 deletions src/ManagedServices/ManagedServices/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Updated parameters naming conventions and associated examples

## Version 1.0.2
* Update references in .psd1 to use relative path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,29 @@ namespace Microsoft.Azure.PowerShell.Cmdlets.ManagedServices.Commands
public class GetAzureRmManagedServicesAssignment : ManagedServicesCmdletBase
{
protected const string DefaultParameterSet = "Default";
protected const string ByResourceIdParameterSet = "ByResourceId";
protected const string ByIdParameterSet = "ById";
protected const string ByNameParameterSet = "ByName";

[Parameter(Mandatory = false, ParameterSetName = DefaultParameterSet, HelpMessage = "The scope where the registration assignment is created.")]
[Parameter(Mandatory = false, ParameterSetName = ByIdParameterSet, HelpMessage = "The scope where the registration assignment is created.")]
[Parameter(Mandatory = false, ParameterSetName = ByNameParameterSet, HelpMessage = "The scope where the registration assignment is created.")]
[ScopeCompleter]
public string Scope { get; set; }

[Parameter(Mandatory = true, ParameterSetName = ByIdParameterSet, HelpMessage = "The Registration Assignment identifier.")]
[Parameter(Mandatory = true, ParameterSetName = ByNameParameterSet, HelpMessage = "The unique name of the Registration Assignment.")]
[ValidateNotNullOrEmpty]
public string Id { get; set; }

[Parameter(
Mandatory = true,
ValueFromPipelineByPropertyName = true,
ParameterSetName = ByResourceIdParameterSet,
HelpMessage = "The fully qualified resource id of registration assignment.")]
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }
skayani marked this conversation as resolved.
Show resolved Hide resolved
public string Name { get; set; }

[Parameter(ParameterSetName = DefaultParameterSet, HelpMessage = "Whether to include registration definition details.")]
[Parameter(ParameterSetName = ByResourceIdParameterSet, HelpMessage = "Whether to include registration definition details.")]
[Parameter(ParameterSetName = ByIdParameterSet, HelpMessage = "Whether to include registration definition details.")]
[Parameter(ParameterSetName = ByNameParameterSet, HelpMessage = "Whether to include registration definition details.")]
public SwitchParameter ExpandRegistrationDefinition { get; set; }

public override void ExecuteCmdlet()
{
string scope = null;
string assignmentId = null;

if (this.IsParameterBound(x => x.ResourceId))
{
assignmentId = this.ResourceId.GetResourceName();
scope = this.ResourceId.GetSubscriptionId().ToSubscriptionResourceId();
}
else if (this.IsParameterBound(x => x.Id))
if (this.IsParameterBound(x => x.Name))
{
assignmentId = this.Id;
assignmentId = this.Name;
scope = this.Scope ?? this.GetDefaultScope();
}
else if (this.IsParameterBound(x => x.Scope))
Expand All @@ -81,21 +66,21 @@ public override void ExecuteCmdlet()
var results = this.PSManagedServicesClient.ListRegistrationAssignments(
scope: scope,
expandRegistrationDefinition: this.ExpandRegistrationDefinition);
this.WriteRegistrationAssignmentList(results);
this.WriteRegistrationAssignmentList(results, scope);
}
else
{
// validate assignmentId.
if (!assignmentId.IsGuid())
{
throw new ApplicationException("RegistrationAssignment must be a valid GUID.");
throw new ApplicationException("Name must be a valid GUID.");
}

var result = this.PSManagedServicesClient.GetRegistrationAssignment(
scope: scope,
registrationAssignmentId: assignmentId,
expandRegistrationDefinition: this.ExpandRegistrationDefinition);
WriteObject(new PSRegistrationAssignment(result), true);
WriteObject(new PSGetRegistrationAssignment(result, scope), true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,15 @@ namespace Microsoft.Azure.PowerShell.Cmdlets.ManagedServices.Commands
[Cmdlet(
VerbsCommon.Get,
Microsoft.Azure.Commands.ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ManagedServicesDefinition",
DefaultParameterSetName = ByIdParameterSet), OutputType(typeof(PSRegistrationDefinition))]
DefaultParameterSetName = ByNameParameterSet), OutputType(typeof(PSRegistrationDefinition))]
public class GetAzureRmManagedServicesDefinition : ManagedServicesCmdletBase
{
////protected const string DefaultParameterSet = "Default";
protected const string ByResourceIdParameterSet = "ByResourceId";
protected const string ByIdParameterSet = "ById";
protected const string ByNameParameterSet = "ByName";

[Parameter(ParameterSetName = ByIdParameterSet, Mandatory = false, HelpMessage = "The registration definition identifier.")]
[Parameter(ParameterSetName = ByNameParameterSet, Mandatory = false, HelpMessage = "The unique name of the Registration Definition.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
ParameterSetName = ByResourceIdParameterSet,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The full qualified resource id of registration definition.")]
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }
skayani marked this conversation as resolved.
Show resolved Hide resolved

public override void ExecuteCmdlet()
{
string definitionId = null;
Expand All @@ -50,30 +40,25 @@ public override void ExecuteCmdlet()
{
definitionId = this.Name;
}
else if (this.IsParameterBound(x => x.ResourceId))
{
definitionId = this.ResourceId.GetResourceName();
scope = this.ResourceId.GetSubscriptionId().ToSubscriptionResourceId();
}

if (string.IsNullOrEmpty(definitionId))
{
var results = this.PSManagedServicesClient.ListRegistrationDefinitions(
scope: scope);
this.WriteRegistrationDefinitionsList(results);
this.WriteRegistrationDefinitionsList(results, scope);
}
else
{
// validate definitionId.
if (!definitionId.IsGuid())
{
throw new ApplicationException("RegistrationDefinitionId must be a valid GUID.");
throw new ApplicationException("Name must be a valid GUID.");
}

var result = this.PSManagedServicesClient.GetRegistrationDefinition(
scope: scope,
registrationDefinitionId: definitionId);
WriteObject(new PSRegistrationDefinition(result), true);
WriteObject(new PSGetRegistrationDefinition(result, scope), true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,20 @@ namespace Microsoft.Azure.PowerShell.Cmdlets.ManagedServices.Commands
public class NewAzureRmManagedServicesAssignment : ManagedServicesCmdletBase
{
protected const string DefaultParameterSet = "Default";
protected const string ByResourceIdParameterSet = "ByResourceId";
protected const string ByInputObjectParameterSet = "ByInputObject";

[Parameter(ParameterSetName = DefaultParameterSet, Mandatory = false, HelpMessage = "The unique name of the Registration Assignment.")]
public string Name { get; set; }

[Parameter(Position = 0, ParameterSetName = DefaultParameterSet, Mandatory = false, HelpMessage = "The scope where the registration assignment should be created.")]
[Parameter(Position = 0, ParameterSetName = ByResourceIdParameterSet, Mandatory = false, HelpMessage = "The scope where the registration assignment should be created.")]
[Parameter(Position = 0, ParameterSetName = ByInputObjectParameterSet, Mandatory = false, HelpMessage = "The scope where the registration assignment should be created.")]
[ScopeCompleter]
public string Scope { get; set; }

[Parameter(ParameterSetName = DefaultParameterSet, Mandatory = true, HelpMessage = "The registration definition identifier.")]
[Parameter(ParameterSetName = DefaultParameterSet, Mandatory = true, HelpMessage = "The unique name of the Registration Definition.")]
[ValidateNotNullOrEmpty]
public string RegistrationDefinitionName { get; set; }

[Parameter(ParameterSetName = ByResourceIdParameterSet, ValueFromPipelineByPropertyName = true, Mandatory = true, HelpMessage = "The fully qualified resource id of the registration definition.")]
[ValidateNotNullOrEmpty]
[Alias("ResourceId")]
public string RegistrationDefinitionResourceId { get; set; }
skayani marked this conversation as resolved.
Show resolved Hide resolved

[Parameter(ParameterSetName = ByInputObjectParameterSet, ValueFromPipeline = true, Mandatory = true, HelpMessage = "The registration definition input object.")]
public PSRegistrationDefinition RegistrationDefinition { get; set; }

Expand All @@ -60,7 +56,7 @@ public class NewAzureRmManagedServicesAssignment : ManagedServicesCmdletBase
public override void ExecuteCmdlet()
{
string scope = this.GetDefaultScope();
string definitionId = this.RegistrationDefinitionResourceId;
string definitionId = String.Empty;

if (this.IsParameterBound(x => x.RegistrationDefinitionName))
{
Expand All @@ -70,18 +66,22 @@ public override void ExecuteCmdlet()
// registation definitions can only exist at the subscription level.
definitionId = $"{subscriptionScope}/providers/Microsoft.ManagedServices/registrationDefinitions/{this.RegistrationDefinitionName}";
}
else if (this.IsParameterBound(x => x.RegistrationDefinitionResourceId))
{
definitionId = this.RegistrationDefinitionResourceId;
scope = this.Scope ?? definitionId.GetSubscriptionId().ToSubscriptionResourceId();
}
else if (this.IsParameterBound(x => x.RegistrationDefinition))
{
definitionId = this.RegistrationDefinition.Id;
scope = this.Scope ?? definitionId.GetSubscriptionId().ToSubscriptionResourceId();
scope = this.Scope ?? this.GetDefaultScope();
}

if (this.RegistrationAssignmentId == default(Guid))
if (!String.IsNullOrWhiteSpace(this.Name))
{
if (!this.Name.IsGuid())
{
throw new ApplicationException("Name must be a valid GUID.");
}

this.RegistrationAssignmentId = new Guid(this.Name);
}
else
{
this.RegistrationAssignmentId = Guid.NewGuid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ public class NewAzureRmManagedServicesDefinition : ManagedServicesCmdletBase
protected const string DefaultParameterSet = "Default";
protected const string ByPlanParameterSet = "ByPlan";

[Parameter(ParameterSetName = DefaultParameterSet, Mandatory = true, HelpMessage = "The name of the Registration Definition.")]
skayani marked this conversation as resolved.
Show resolved Hide resolved
[Parameter(ParameterSetName = ByPlanParameterSet, Mandatory = true, HelpMessage = "The name of the Registration Definition.")]
[Parameter(ParameterSetName = DefaultParameterSet, Mandatory = false, HelpMessage = "The unique name of the Registration Definition.")]
[Parameter(ParameterSetName = ByPlanParameterSet, Mandatory = false, HelpMessage = "The unique name of the Registration Definition.")]
public string Name { get; set; }

[Parameter(ParameterSetName = DefaultParameterSet, Mandatory = true, HelpMessage = "The display name of the Registration Definition.")]
[Parameter(ParameterSetName = ByPlanParameterSet, Mandatory = true, HelpMessage = "The display name of the Registration Definition.")]
public string DisplayName { get; set; }

[Parameter(ParameterSetName = DefaultParameterSet, Mandatory = true, HelpMessage = "The ManagedBy Tenant Identifier.")]
[Parameter(ParameterSetName = ByPlanParameterSet, Mandatory = true, HelpMessage = "The ManagedBy Tenant Identifier.")]
public string ManagedByTenantId { get; set; }
Expand Down Expand Up @@ -71,7 +75,7 @@ public class NewAzureRmManagedServicesDefinition : ManagedServicesCmdletBase
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

public Guid RegistrationDefinitionId { get; set; } = default(Guid);
public Guid RegistrationDefinitionId { get; set; }

public override void ExecuteCmdlet()
{
Expand All @@ -92,7 +96,16 @@ public override void ExecuteCmdlet()
throw new ApplicationException("RoleDefinitionId must be a valid GUID.");
}

if (this.RegistrationDefinitionId == default(Guid))
if (!String.IsNullOrWhiteSpace(this.Name))
{
if (!this.Name.IsGuid())
{
throw new ApplicationException("Name must be a valid GUID.");
}

this.RegistrationDefinitionId = new Guid(this.Name);
}
else
{
this.RegistrationDefinitionId = Guid.NewGuid();
}
Expand Down Expand Up @@ -122,7 +135,7 @@ public override void ExecuteCmdlet()
Properties = new RegistrationDefinitionProperties
{
Description = this.Description,
RegistrationDefinitionName = this.Name,
RegistrationDefinitionName = this.DisplayName,
ManagedByTenantId = this.ManagedByTenantId,
Authorizations = new List<Authorization>
{
Expand Down
Loading