From 23ae0236ebee5fcc6b1e7be69101d0de5f474cb1 Mon Sep 17 00:00:00 2001 From: Saif Kayani Date: Thu, 14 May 2020 15:14:11 -0700 Subject: [PATCH] New-AzManagedServicesDefinition changes --- .../ScenarioTests/ManagedServicesTests.ps1 | 14 ++--- .../NewAzureRmManagedServicesDefinition.cs | 23 ++++++-- .../help/New-AzManagedServicesDefinition.md | 57 ++++++++++++------- 3 files changed, 61 insertions(+), 33 deletions(-) diff --git a/src/ManagedServices/ManagedServices.Test/ScenarioTests/ManagedServicesTests.ps1 b/src/ManagedServices/ManagedServices.Test/ScenarioTests/ManagedServicesTests.ps1 index 14e3b1b0654c..cf44a117bfb0 100644 --- a/src/ManagedServices/ManagedServices.Test/ScenarioTests/ManagedServicesTests.ps1 +++ b/src/ManagedServices/ManagedServices.Test/ScenarioTests/ManagedServicesTests.ps1 @@ -53,12 +53,12 @@ function New-AzManagedServicesDefinitionWithId { [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 @@ -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))) @@ -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() @@ -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-AzManagedServicesDefinitionWithId -ManagedByTenantId $managedByTenantId -RoleDefinitionId $roleDefinitionId -PrincipalId $principalId -DisplayName $name -Name $definitionId Assert-AreEqual $name $definition.Properties.Name Assert-AreEqual $managedByTenantId $definition.Properties.ManagedByTenantId diff --git a/src/ManagedServices/ManagedServices/Commands/NewAzureRmManagedServicesDefinition.cs b/src/ManagedServices/ManagedServices/Commands/NewAzureRmManagedServicesDefinition.cs index d921738d0475..f97e0ac00d34 100644 --- a/src/ManagedServices/ManagedServices/Commands/NewAzureRmManagedServicesDefinition.cs +++ b/src/ManagedServices/ManagedServices/Commands/NewAzureRmManagedServicesDefinition.cs @@ -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.")] - [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; } @@ -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() { @@ -92,7 +96,16 @@ public override void ExecuteCmdlet() throw new ApplicationException("RoleDefinitionId must be a valid GUID."); } - if (this.RegistrationDefinitionId == default(Guid)) + if (this.Name != null) + { + if (!this.Name.IsGuid()) + { + throw new ApplicationException("Name must be a valid GUID."); + } + + this.RegistrationDefinitionId = new Guid(this.Name); + } + else { this.RegistrationDefinitionId = Guid.NewGuid(); } @@ -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 { diff --git a/src/ManagedServices/ManagedServices/help/New-AzManagedServicesDefinition.md b/src/ManagedServices/ManagedServices/help/New-AzManagedServicesDefinition.md index de36e34616e9..77e147e5604e 100644 --- a/src/ManagedServices/ManagedServices/help/New-AzManagedServicesDefinition.md +++ b/src/ManagedServices/ManagedServices/help/New-AzManagedServicesDefinition.md @@ -14,15 +14,15 @@ Creates or updates a registration definition. ### Default (Default) ``` -New-AzManagedServicesDefinition -Name -ManagedByTenantId - -PrincipalId -RoleDefinitionId [-Description ] [-AsJob] +New-AzManagedServicesDefinition -DisplayName -ManagedByTenantId + -PrincipalId -RoleDefinitionId [-Name ] [-Description ] [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` ### ByPlan ``` -New-AzManagedServicesDefinition -Name -ManagedByTenantId - -PrincipalId -RoleDefinitionId [-Description ] -PlanName +New-AzManagedServicesDefinition -DisplayName -ManagedByTenantId + -PrincipalId -RoleDefinitionId [-Name ] [-Description ] -PlanName -PlanPublisher -PlanProduct -PlanVersion [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -34,7 +34,7 @@ Creates or updates a registration definition. ### Example 1 ```powershell -PS C:\> PS C:\> New-AzManagedServicesDefinition -Name name -ManagedByTenantId bab3375b-6197-4a15-a44b-16c41faa91d7 -PrincipalId d6f6c88a-5b7a-455e-ba40-ce146d4d3671 -RoleDefinitionId acdd72a7-3385-48ef-bd42-f606fba81ae7 -Description mydef +PS C:\> PS C:\> New-AzManagedServicesDefinition -DisplayName MyRegistrationDefinition -ManagedByTenantId bab3375b-6197-4a15-a44b-16c41faa91d7 -PrincipalId d6f6c88a-5b7a-455e-ba40-ce146d4d3671 -RoleDefinitionId acdd72a7-3385-48ef-bd42-f606fba81ae7 -Description mydef Name ManagedByTenantId PrincipalId RoleDefinitionId ---- ----------------- ----------- ---------------- @@ -45,7 +45,7 @@ Creates or updates a registration definition given the required parameters. ### Example 2 ```powershell -PS C> New-AzManagedServicesDefinition -Name asd -ManagedByTenantId "bab3375b-6197-4a15-a44b-16c41faa91d7" -PrincipalId "d6f6c88a-5b7a-455e-ba40-ce146d4d3671" -RoleDefinitionId "acdd72a7-3385-48ef-bd42-f606fba81ae7" -PlanName plan -PlanPublisher publisher -PlanProduct product -PlanVersion 0.1 +PS C> New-AzManagedServicesDefinition -DisplayName asd -ManagedByTenantId "bab3375b-6197-4a15-a44b-16c41faa91d7" -PrincipalId "d6f6c88a-5b7a-455e-ba40-ce146d4d3671" -RoleDefinitionId "acdd72a7-3385-48ef-bd42-f606fba81ae7" -PlanName plan -PlanPublisher publisher -PlanProduct product -PlanVersion 0.1 Name ManagedByTenantId PrincipalId RoleDefinitionId ---- ----------------- ----------- ---------------- @@ -101,6 +101,21 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -DisplayName +The display name of the Registration Definition. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -ManagedByTenantId The ManagedBy Tenant Identifier. @@ -116,23 +131,23 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -PlanName -The name of the plan. +### -Name +The unique name of the Registration Definition (for example b0c052e5-c437-4771-a476-8b1201158a57). ```yaml Type: System.String -Parameter Sets: ByPlan +Parameter Sets: (All) Aliases: -Required: True +Required: False Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False ``` -### -PlanProduct -The name of the Product. +### -PlanName +The name of the plan. ```yaml Type: System.String @@ -146,8 +161,8 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -PlanPublisher -The name of the Publisher. +### -PlanProduct +The name of the Product. ```yaml Type: System.String @@ -161,8 +176,8 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -PlanVersion -The version number of the plan. +### -PlanPublisher +The name of the Publisher. ```yaml Type: System.String @@ -176,12 +191,12 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -PrincipalId -The ManagedBy Principal Identifier. +### -PlanVersion +The version number of the plan. ```yaml Type: System.String -Parameter Sets: (All) +Parameter Sets: ByPlan Aliases: Required: True @@ -191,8 +206,8 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -RegistrationDefinitionName -The name of the Registration Definition. +### -PrincipalId +The ManagedBy Principal Identifier. ```yaml Type: System.String