Skip to content

Commit

Permalink
Updated IoT Central .NET package to 4.0.0 (RP version 2021-06-01) wit…
Browse files Browse the repository at this point in the history
…h support for Managed Identities (#16438)

* Updated IoT Central DotNet package to 4.0.0 with support for Managed Identities

Updated IoT Central Management Plane .Net package to 4.0.0. This version supports Managed Identities, removes support for S1 SKU, and supports only regional locations (not geographic).

Related:
.NET SDK update PR: Azure/azure-sdk-for-net#24992
Swagger update PR: Azure/azure-rest-api-specs#16139

* Minor updates to tests and changelog

Minor updates to tests and changelog

* Updated test session records.

Updated test session records.

* Update ChangeLog.md

* Reverting module version

Reverting module version and assembly version since they are computed per PR feedback.

Co-authored-by: Yunchi Wang <54880216+wyunchi-ms@users.noreply.github.com>
  • Loading branch information
gansvv and wyunchi-ms authored Nov 24, 2021
1 parent e6a0399 commit 093863f
Show file tree
Hide file tree
Showing 18 changed files with 512 additions and 436 deletions.
2 changes: 1 addition & 1 deletion src/IotCentral/IotCentral.Test/IotCentral.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.IotCentral" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Management.IotCentral" Version="4.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void RunPsTestWorkflow(
};
var providersToIgnore = new Dictionary<string, string>
{
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"},
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2021_04_01"},
{"Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2017-05-10"},
{"Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient", "2016-09-01"}
};
Expand Down
17 changes: 13 additions & 4 deletions src/IotCentral/IotCentral.Test/ScenarioTests/IotCentralTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ function Test-IotCentralAppLifecycleManagement{
$tagKey = "key1"
$tagValue = "value1"
$tags = @{ $tagKey = $tagValue }

$identity = "SystemAssigned"

try
{
# Test

# Create Resource Group
New-AzResourceGroup -Name $rgname -Location $location

# Create App
$created = New-AzIotCentralApp -ResourceGroupName $rgname -Name $rname -Subdomain $subdomain -Sku $st2Sku -DisplayName $displayName -Tag $tags
# Create and Validate App with System-Assigned Managed Identity
$created = New-AzIotCentralApp -ResourceGroupName $rgname -Name $rname -Subdomain $subdomain -Sku $st2Sku -DisplayName $displayName -Tag $tags -Identity $identity
$actual = Get-AzIotCentralApp -ResourceGroupName $rgname -Name $rname

$list = Get-AzIotCentralApp -ResourceGroupName $rgname

# Assert
Expand All @@ -57,11 +57,15 @@ function Test-IotCentralAppLifecycleManagement{
Assert-AreEqual 1 @($list).Count
Assert-AreEqual $actual.Name $list[0].Name
Assert-AreEqual $actual.Sku.Name $st2Sku
Assert-NotNull $actual.Identity
Assert-NotNull $actual.Identity.Type
Assert-AreEqual $actual.Identity.Type "SystemAssigned"

# Get App
$rname1 = $rname
$rname2 = ($rname1) + "-2"

# Create another app without Managed Identity and validate Get responses.
New-AzIotCentralApp $rgname $rname2 $rname2
$list = Get-AzIotCentralApp -ResourceGroupName $rgname
$app1 = $list | where {$_.Name -eq $rname1} | Select-Object -First 1
Expand All @@ -75,6 +79,8 @@ function Test-IotCentralAppLifecycleManagement{
Assert-AreEqual $rname2 $app2.Subdomain
Assert-AreEqual $resourceType $app1.Type
Assert-AreEqual $resourceType $app2.Type
Assert-AreEqual $app1.Identity.Type "SystemAssigned"
Assert-AreEqual $app2.Identity.Type "None"

# Test getting from empty group
$emptyrg = ($rgname) + "empty"
Expand Down Expand Up @@ -108,6 +114,9 @@ function Test-IotCentralAppLifecycleManagement{
Assert-AreEqual $actual.Subdomain $newSubdomain
Assert-AreEqual $actual.Name $rname
Assert-AreEqual $actual.Sku.Name $st1Sku

# Ensure MI is not updated after update (when Identity is not provided as input to patch operation)
Assert-AreEqual $actual.Identity.Type "SystemAssigned"

# Delete
# $job = Find-AzResource -ResourceType $resourceType -ResourceGroupNameEquals $rgname | Get-AzIotCentralApp | Remove-AzIotCentralApp -AsJob
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/IotCentral/IotCentral/Az.IotCentral.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '* Update our Azure PowerShell command to use our latest released .NET package with the version of 3.1.0.'
ReleaseNotes = '* Update our Azure PowerShell command to use our latest released .NET package with the version of 4.0.0.'

# Prerelease string of this module
# Prerelease = ''
Expand Down
2 changes: 2 additions & 0 deletions src/IotCentral/IotCentral/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
- Additional information about change #1
-->
## Upcoming Release
* Stable release version, updated to IoT Central .NET Management Plane SDK version 4.0.0.
* This change introduces support for System-Assigned Managed Identities, removes support for geographic locations (e.g., 'unitedstates'), and removes support for legacy S1 sku.

## Version 0.9.0
* Update our Azure PowerShell command to use our latest released .NET package with the version of 3.1.0.
Expand Down
6 changes: 2 additions & 4 deletions src/IotCentral/IotCentral/Common/IotCentralUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@

using Microsoft.Azure.Commands.IotCentral.Models;
using Microsoft.Azure.Management.IotCentral.Models;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.IotCentral.Common
{
Expand All @@ -35,13 +33,13 @@ public static IEnumerable<PSIotCentralApp> ToPSIotCentralApps(IEnumerable<App> i

public static AppPatch CreateAppPatch(App iotCentralApp)
{
var copiedIotCenralApp = new AppPatch()
var copiedIotCentralApp = new AppPatch()
{
DisplayName = iotCentralApp.DisplayName,
Tags = iotCentralApp.Tags,
Subdomain = iotCentralApp.Subdomain
};
return copiedIotCenralApp;
return copiedIotCentralApp;
}
}
}
2 changes: 1 addition & 1 deletion src/IotCentral/IotCentral/IotCentral.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.IotCentral" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Management.IotCentral" Version="4.0.0" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions src/IotCentral/IotCentral/IotCentral.generated.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<Alignment>Left</Alignment>
<Label>Sku Name</Label>
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>Identity</Label>
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>Resource Group Name</Label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using Microsoft.Azure.Management.IotCentral;
using Microsoft.Azure.Management.IotCentral.Models;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Management.IotCentral
Expand Down
15 changes: 13 additions & 2 deletions src/IotCentral/IotCentral/IotCentral/NewAzureRmIotCentralApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public class NewAzureRmIotCentralApp : IotCentralBaseCmdlet
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet as a job in the background.")]
public SwitchParameter AsJob { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Managed Identity Type. Can be SystemAssigned or None.")]
[ValidateNotNullOrEmpty]
public string Identity { get; set; }

public override void ExecuteCmdlet()
{
if (ShouldProcess(Name, ResourceProperties.Resources.NewIotCentralApp))
Expand All @@ -91,14 +97,14 @@ public override void ExecuteCmdlet()
Template = this.Template,
Sku = new AppSkuInfo() { Name = this.GetAppSkuName() },
Location = this.GetLocation(),
Tags = this.GetTags()
Tags = this.GetTags(),
Identity = new SystemAssignedServiceIdentity(this.GetIdentity()),
};

this.IotCentralClient.Apps.CreateOrUpdate(this.ResourceGroupName, this.Name, iotCentralApp);
App createdIotCentralApp = this.IotCentralClient.Apps.Get(this.ResourceGroupName, this.Name);
this.WriteObject(IotCentralUtils.ToPSIotCentralApp(createdIotCentralApp), false);
}

}

private IDictionary<string, string> GetTags()
Expand Down Expand Up @@ -132,5 +138,10 @@ private string GetLocation()
}
return this.Location;
}

private string GetIdentity()
{
return this.Identity ?? SystemAssignedServiceIdentityType.None;
}
}
}
19 changes: 18 additions & 1 deletion src/IotCentral/IotCentral/IotCentral/SetAzureRmIotCentralApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public class SetAzureRmIotCentralApp : IotCentralFullParameterSetCmdlet
[ValidateNotNullOrEmpty]
public string Sku { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Managed Identity Type. Can be None or SystemAssigned.")]
public string Identity { get; set; }

public override void ExecuteCmdlet()
{
this.SetNameAndResourceGroup();
Expand All @@ -67,7 +72,19 @@ public override void ExecuteCmdlet()

private AppPatch CreateApplicationPatch()
{
return new AppPatch(TagsConversionHelper.CreateTagDictionary(this.Tag, true), new AppSkuInfo(this.Sku), null, this.DisplayName, this.Subdomain);
var appPatch = new AppPatch(
tags: TagsConversionHelper.CreateTagDictionary(this.Tag, true),
sku: new AppSkuInfo(this.Sku),
displayName: this.DisplayName,
subdomain: this.Subdomain
);

if (!string.IsNullOrEmpty(this.Identity))
{
appPatch.Identity = new SystemAssignedServiceIdentity(type: this.Identity);
}

return appPatch;
}
}
}
7 changes: 6 additions & 1 deletion src/IotCentral/IotCentral/Models/PSIotCentralApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Management.IotCentral.Models;
using Microsoft.WindowsAzure.Commands.Common.Attributes;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Microsoft.Azure.Commands.IotCentral.Models
Expand Down Expand Up @@ -51,6 +50,7 @@ public PSIotCentralApp(App iotCentralApp){
this.DisplayName = iotCentralApp.DisplayName;
this.Subdomain = iotCentralApp.Subdomain;
this.Template = iotCentralApp.Template;
this.Identity = iotCentralApp.Identity;
}

/// <summary>
Expand Down Expand Up @@ -103,6 +103,11 @@ public PSIotCentralApp(App iotCentralApp){
/// </summary>
public string Type { get; private set; }

/// <summary>
/// The supported Managed Identities.
/// </summary>
public SystemAssignedServiceIdentity Identity { get; set; }

/// <summary>
/// The subscription identifier.
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion src/IotCentral/IotCentral/Models/PSIotCentralAppSku.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace Microsoft.Azure.Commands.IotCentral.Models
[JsonConverter(typeof(StringEnumConverter))]
public enum PSIotCentralAppSku
{
S1 = 1,
ST0 = 2,
ST1 = 3,
ST2 = 4
Expand Down
2 changes: 1 addition & 1 deletion src/IotCentral/IotCentral/Models/PSIotCentralAppSkuInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.Azure.Commands.IotCentral.Models
public class PSIotCentralAppSkuInfo
{
/// <summary>
/// Gets or sets the name of the SKU. Possible values include: 'S1', 'ST0', 'ST1', 'ST2'
/// Gets or sets the name of the SKU. Possible values include: 'ST0', 'ST1', 'ST2'
/// </summary>
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions src/IotCentral/IotCentral/help/Get-AzIotCentralApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Subdomain : MyAppSubdomain
Template : iotc-default@1.0.0
SubscriptionId : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
ResourceGroupName : MyResourceGroupName
Identity : Microsoft.Azure.Management.IotCentral.Models.SystemAssignedServiceIdentity

### Example 2 Get IoT Central Applications in Subscription.
```powershell
Expand All @@ -79,6 +80,7 @@ Subdomain : MyAppSubdomain
Template : iotc-default@1.0.0
SubscriptionId : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
ResourceGroupName : MyResourceGroupName
Identity : Microsoft.Azure.Management.IotCentral.Models.SystemAssignedServiceIdentity

ResourceId : /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/MyResourceGroupName2/providers/Microsoft
.IoTCentral/IoTApps/MyAppResourceName2
Expand All @@ -93,6 +95,7 @@ Subdomain : MyAppSubdomain2
Template : iotc-default@1.0.0
SubscriptionId : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
ResourceGroupName : MyResourceGroupName2
Identity : Microsoft.Azure.Management.IotCentral.Models.SystemAssignedServiceIdentity

### Example 3 Get IoT Central Applications in Resource Group.
```powershell
Expand All @@ -116,6 +119,7 @@ Subdomain : MyAppSubdomain
Template : iotc-default@1.0.0
SubscriptionId : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
ResourceGroupName : MyResourceGroupName
Identity : Microsoft.Azure.Management.IotCentral.Models.SystemAssignedServiceIdentity

ResourceId : /subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/MyResourceGroupName/providers/Microsoft
.IoTCentral/IoTApps/MyAppResourceName2
Expand All @@ -130,6 +134,7 @@ Subdomain : MyAppSubdomain2
Template : iotc-default@1.0.0
SubscriptionId : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
ResourceGroupName : MyResourceGroupName
Identity : Microsoft.Azure.Management.IotCentral.Models.SystemAssignedServiceIdentity

## PARAMETERS

Expand Down
20 changes: 19 additions & 1 deletion src/IotCentral/IotCentral/help/New-AzIotCentralApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Creates a new IoT Central Application.
## SYNTAX

```
New-AzIotCentralApp [-Subdomain] <String> [-DisplayName <String>] [-Template <String>] [-Sku <String>]
New-AzIotCentralApp [-Subdomain] <String> [-DisplayName <String>] [-Template <String>] [-Sku <String>] [-Identity <String>]
[-Location <String>] [-Tag <Hashtable>] [-AsJob] [-ResourceGroupName] <String> [-Name] <String>
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```
Expand Down Expand Up @@ -43,6 +43,7 @@ Subdomain : MyAppSubdomain
Template : iotc-default@1.0.0
SubscriptionId : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
ResourceGroupName : MyResourceGroupName
Identity : Microsoft.Azure.Management.IotCentral.Models.SystemAssignedServiceIdentity

Create an IoT Central application in the standard pricing tier ST2, in the region of the resource group.

Expand All @@ -66,6 +67,7 @@ Subdomain : MyAppSubdomain
Template : iotc-default@1.0.0
SubscriptionId : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
ResourceGroupName : MyResourceGroupName
Identity : Microsoft.Azure.Management.IotCentral.Models.SystemAssignedServiceIdentity

Create an IoT Central application with the standard pricing tier ST2 in the 'westus' region, with a custom display name, based on the iotc-default template.

Expand Down Expand Up @@ -226,6 +228,22 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -Identity
The type of managed identity for the IoT Central application.
Default value is None. System-assigned managed identities are supported.
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Confirm
Prompts you for confirmation before running the cmdlet.
Expand Down
Loading

0 comments on commit 093863f

Please sign in to comment.