Skip to content

Commit

Permalink
New-AzManagedServicesDefinition changes
Browse files Browse the repository at this point in the history
  • Loading branch information
skayani committed May 14, 2020
1 parent b8e4f23 commit 23ae023
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
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-AzManagedServicesDefinitionWithId -ManagedByTenantId $managedByTenantId -RoleDefinitionId $roleDefinitionId -PrincipalId $principalId -DisplayName $name -Name $definitionId

Assert-AreEqual $name $definition.Properties.Name
Assert-AreEqual $managedByTenantId $definition.Properties.ManagedByTenantId
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.")]
[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 (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();
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Creates or updates a registration definition.

### Default (Default)
```
New-AzManagedServicesDefinition -Name <String> -ManagedByTenantId <String>
-PrincipalId <String> -RoleDefinitionId <String> [-Description <String>] [-AsJob]
New-AzManagedServicesDefinition -DisplayName <String> -ManagedByTenantId <String>
-PrincipalId <String> -RoleDefinitionId <String> [-Name <String>] [-Description <String>] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ByPlan
```
New-AzManagedServicesDefinition -Name <String> -ManagedByTenantId <String>
-PrincipalId <String> -RoleDefinitionId <String> [-Description <String>] -PlanName <String>
New-AzManagedServicesDefinition -DisplayName <String> -ManagedByTenantId <String>
-PrincipalId <String> -RoleDefinitionId <String> [-Name <String>] [-Description <String>] -PlanName <String>
-PlanPublisher <String> -PlanProduct <String> -PlanVersion <String> [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```
Expand All @@ -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
---- ----------------- ----------- ----------------
Expand All @@ -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
---- ----------------- ----------- ----------------
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 23ae023

Please sign in to comment.