internal async Task <ResourceGroup> Group(AppVersion version, ResourceGroupName name) { var record = await factory.DB .ResourceGroups .Retrieve() .Where(g => g.VersionID == version.ID.Value && g.Name == name.Value) .FirstOrDefaultAsync(); if (record == null) { record = await factory.DB .ResourceGroups .Retrieve() .Where(g => g.VersionID == version.ID.Value && g.Name == ResourceGroupName.Unknown.Value) .FirstOrDefaultAsync(); if (record == null) { record = await factory.DB .ResourceGroups .Retrieve() .Where(g => g.Name == ResourceGroupName.Unknown.Value) .FirstOrDefaultAsync(); } } return(factory.Group(record)); }
public override void ExecuteCmdlet() { if (ParameterSetName == ObjectParameterSet) { ResourceGroupName = CdnProfile.ResourceGroupName; ProfileName = CdnProfile.Name; } var existingProfile = CdnManagementClient.Profiles.ListBySubscriptionId().Select(p => p.ToPsProfile()) .Where(p => p.Name.ToLower() == ProfileName.ToLower()) .Where(p => p.ResourceGroupName.ToLower() == ResourceGroupName.ToLower()) .FirstOrDefault(); if (existingProfile == null) { throw new PSArgumentException(string.Format( Resources.Error_DeleteNonExistingProfile, ProfileName, ResourceGroupName)); } ConfirmAction(Force, string.Format(Resources.Confirm_RemoveProfile, ProfileName), this.MyInvocation.InvocationName, ProfileName, () => CdnManagementClient.Profiles.DeleteIfExists(ProfileName, ResourceGroupName), () => ContainsEndpoints()); if (PassThru) { WriteObject(true); } }
public HubClientResourceGroup(HubAppClient hubClient, HubClientAppContext appContext, AppVersionKey versionKey, ResourceGroupModel model) { this.hubClient = hubClient; this.appContext = appContext; this.versionKey = versionKey; ID = new EntityID(model.ID); name = new ResourceGroupName(model.Name); }
internal async Task <ResourceGroup> Add(AppVersion version, ResourceGroupName name, ModifierCategory modCategory) { var record = new ResourceGroupRecord { VersionID = version.ID.Value, Name = name.Value, ModCategoryID = modCategory.ID.Value }; await factory.DB.ResourceGroups.Create(record); return(factory.Group(record)); }
public async Task <IResourceGroup> ResourceGroup(ResourceGroupName name) { var appModifier = await appContext.GetModifierKey(); var request = new GetVersionResourceGroupRequest { VersionKey = versionKey.Value, GroupName = name.Value }; var group = await hubClient.Version.GetResourceGroup(appModifier, request); return(new HubClientResourceGroup(hubClient, appContext, versionKey, group)); }
public async Task <ResourceGroupModel> Execute(GetVersionResourceGroupRequest model) { var app = await appFromPath.Value(); var versionKey = AppVersionKey.Parse(model.VersionKey); var version = await app.Version(versionKey); var groupName = new ResourceGroupName(model.GroupName); var group = await version.ResourceGroup(groupName); var groupModel = group.ToModel(); return(groupModel); }
public override void ExecuteCmdlet() { var existingProfile = CdnManagementClient.Profiles.ListBySubscriptionId().Select(p => p.ToPsProfile()) .Where(p => p.Name.ToLower() == ProfileName.ToLower()) .Where(p => p.ResourceGroupName.ToLower() == ResourceGroupName.ToLower()) .FirstOrDefault(); if (existingProfile != null) { throw new PSArgumentException(string.Format(Resources.Error_CreateExistingProfile, ProfileName, ResourceGroupName)); } ConfirmAction(MyInvocation.InvocationName, ProfileName, NewProfile); }
public void GenerateBaseTags() { var newDate = this.TrackingStartDate.AddDays(30).Date; this.Tags.Add(new KeyValuePair <string, string>("expires", newDate.ToString("yyyy-MM-dd"))); this.Tags.Add(new KeyValuePair <string, string>("tagged-by", "thrazman")); this.Tags.Add(new KeyValuePair <string, string>("owner", this.ResourceOwner)); // service-msft-prod-azman-main-compute var groupNamePieces = ResourceGroupName.Split('-'); if (groupNamePieces.Count() >= 3) { this.Tags.Add(new KeyValuePair <string, string>("function", groupNamePieces[0])); // service this.Tags.Add(new KeyValuePair <string, string>("customer", groupNamePieces[1])); // msft this.Tags.Add(new KeyValuePair <string, string>("env", groupNamePieces[2])); // prod this.Tags.Add(new KeyValuePair <string, string>("project", string.Join('-', groupNamePieces.Skip(3)))); //azman-main-compute } }
public string ReplaceSecretsWithExampleStrings(string jsonActual) { string ret = jsonActual; ret = ReplaceOne(ret, TenantId, ExampleTenantId); ret = ReplaceOne(ret, ClientId, ExampleClientId); ret = ReplaceOne(ret, ClientSecret, ExampleClientSecret); ret = ReplaceOne(ret, SubId, ExampleSubId); ret = ReplaceOne(ret, ResourceGroupName, ExampleResourceGroupName); ret = ReplaceOne(ret, ResourceGroupName.ToLowerInvariant(), ExampleResourceGroupName.ToLowerInvariant()); ret = ReplaceOne(ret, FactoryName, ExampleFactoryName); ret = ReplaceOne(ret, FactoryName.ToLowerInvariant(), ExampleFactoryName.ToLowerInvariant()); ret = ReplaceOne(ret, FactoryLocation, ExampleFactoryLocation); ret = ReplaceOne(ret, FactoryLocation.ToLowerInvariant(), ExampleFactoryLocation.ToLowerInvariant()); ret = ReplaceOne(ret, StorageAccountName, ExampleStorageAccountName); ret = ReplaceOne(ret, StorageAccountKey, ExampleStorageAccountKey); ret = ReplaceOne(ret, BlobContainerName, ExampleBlobContainerName); return(ret); }
private static async Task updateResourceGroupFromTemplate(App app, AppVersion version, AppApiGroupTemplateModel groupTemplate) { var modCategory = await app.TryAddModCategory(new ModifierCategoryName(groupTemplate.ModCategory)); var groupName = new ResourceGroupName(groupTemplate.Name); var resourceGroup = await version.AddOrUpdateResourceGroup(groupName, modCategory); if (groupTemplate.IsAnonymousAllowed) { await resourceGroup.AllowAnonymous(); } else { await resourceGroup.DenyAnonymous(); } var allowedGroupRoles = await rolesFromNames(app, groupTemplate.Roles.Select(r => new AppRoleName(r))); await resourceGroup.SetRoleAccess(allowedGroupRoles); foreach (var actionTemplate in groupTemplate.ActionTemplates) { await updateResourceFromTemplate(app, resourceGroup, actionTemplate); } }
async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet) { var client = new Client(DefaultProfile.DefaultContext); ResourceGroupName = ResourceGroupName ?? Name; VirtualNetworkName = VirtualNetworkName ?? Name; SubnetName = SubnetName ?? Name; PublicIpAddressName = PublicIpAddressName ?? Name; SecurityGroupName = SecurityGroupName ?? Name; var resourceClient = AzureSession.Instance.ClientFactory.CreateArmClient <ResourceManagementClient>( DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager); var parameters = new Parameters(this, client, resourceClient); if (DiskFile != null) { if (!resourceClient.ResourceGroups.CheckExistence(ResourceGroupName)) { Location = Location ?? parameters.DefaultLocation; var st0 = resourceClient.ResourceGroups.CreateOrUpdate( ResourceGroupName, new ResourceGroup { Location = Location, Name = ResourceGroupName }); } parameters.ImageAndOsType = new ImageAndOsType( Linux ? OperatingSystemTypes.Linux : OperatingSystemTypes.Windows, null, null); var storageClient = AzureSession.Instance.ClientFactory.CreateArmClient <StorageManagementClient>( DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager); var st1 = storageClient.StorageAccounts.Create( ResourceGroupName, Name, new StorageAccountCreateParameters { Sku = new Microsoft.Azure.Management.Storage.Version2017_10_01.Models.Sku { Name = SkuName.PremiumLRS }, Location = Location }); var filePath = new FileInfo(SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiskFile)); using (var vds = new VirtualDiskStream(filePath.FullName)) { // 2 ^ 9 == 512 if (vds.DiskType == DiskType.Fixed && filePath.Length % 512 != 0) { throw new ArgumentOutOfRangeException( "filePath", string.Format("Given vhd file '{0}' is a corrupted fixed vhd", filePath)); } } var storageAccount = storageClient.StorageAccounts.GetProperties(ResourceGroupName, Name); // BlobUri destinationUri = null; BlobUri.TryParseUri( new Uri(string.Format( "{0}{1}/{2}{3}", storageAccount.PrimaryEndpoints.Blob, ResourceGroupName.ToLower(), Name.ToLower(), ".vhd")), out parameters.DestinationUri); if (parameters.DestinationUri?.Uri == null) { throw new ArgumentNullException("destinationUri"); } var storageCredentialsFactory = new StorageCredentialsFactory( ResourceGroupName, storageClient, DefaultContext.Subscription); var uploadParameters = new UploadParameters(parameters.DestinationUri, null, filePath, true, 2) { Cmdlet = this, BlobObjectFactory = new CloudPageBlobObjectFactory(storageCredentialsFactory, TimeSpan.FromMinutes(1)) }; if (!string.Equals( Environment.GetEnvironmentVariable("AZURE_TEST_MODE"), "Playback", StringComparison.OrdinalIgnoreCase)) { var st2 = VhdUploaderModel.Upload(uploadParameters); } } var result = await client.RunAsync(client.SubscriptionId, parameters, asyncCmdlet); if (result != null) { var fqdn = PublicIPAddressStrategy.Fqdn(DomainNameLabel, Location); var psResult = ComputeAutoMapperProfile.Mapper.Map <PSVirtualMachine>(result); psResult.FullyQualifiedDomainName = fqdn; var connectionString = parameters.ImageAndOsType.GetConnectionString( fqdn, Credential?.UserName); asyncCmdlet.WriteVerbose( Resources.VirtualMachineUseConnectionString, connectionString); asyncCmdlet.WriteObject(psResult); } }
/// <summary> /// Serializes the state of this cmdlet to a <see cref="Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.Json.JsonNode" /> object. /// </summary> /// <param name="container">The <see cref="Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.Json.JsonObject"/> container to serialize this object into. If the caller /// passes in <c>null</c>, a new instance will be created and returned to the caller.</param> /// <param name="serializationMode">Allows the caller to choose the depth of the serialization. See <see cref="Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.SerializationMode"/>.</param> /// <returns> /// a serialized instance of <see cref="GetAzConfigurationStore_ResourceGroupResourceGroupName" /> as a <see cref="Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.Json.JsonNode" /// />. /// </returns> public Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.Json.JsonNode ToJson(Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.Json.JsonObject container, Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.SerializationMode serializationMode) { // serialization method container = container ?? new Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.Json.JsonObject(); AddIf(null != (((object)SubscriptionId)?.ToString()) ? (Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.Json.JsonNode) new Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.Json.JsonString(SubscriptionId.ToString()) : null, "SubscriptionId", container.Add); AddIf(null != (((object)ResourceGroupName)?.ToString()) ? (Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.Json.JsonNode) new Microsoft.Azure.PowerShell.Cmdlets.AppConfiguration.Runtime.Json.JsonString(ResourceGroupName.ToString()) : null, "ResourceGroupName", container.Add); return(container); }
async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet) { ResourceGroupName = ResourceGroupName ?? Name; VirtualNetworkName = VirtualNetworkName ?? Name; SubnetName = SubnetName ?? Name; PublicIpAddressName = PublicIpAddressName ?? Name; SecurityGroupName = SecurityGroupName ?? Name; var imageAndOsType = new ImageAndOsType(OperatingSystemTypes.Windows, null); var resourceGroup = ResourceGroupStrategy.CreateResourceGroupConfig(ResourceGroupName); var virtualNetwork = resourceGroup.CreateVirtualNetworkConfig( name: VirtualNetworkName, addressPrefix: AddressPrefix); var subnet = virtualNetwork.CreateSubnet(SubnetName, SubnetAddressPrefix); var publicIpAddress = resourceGroup.CreatePublicIPAddressConfig( name: PublicIpAddressName, getDomainNameLabel: () => DomainNameLabel, allocationMethod: AllocationMethod); var networkSecurityGroup = resourceGroup.CreateNetworkSecurityGroupConfig( name: SecurityGroupName, openPorts: OpenPorts, getOsType: () => imageAndOsType.OsType); var networkInterface = resourceGroup.CreateNetworkInterfaceConfig( Name, subnet, publicIpAddress, networkSecurityGroup); var availabilitySet = AvailabilitySetName == null ? null : resourceGroup.CreateAvailabilitySetConfig(name: AvailabilitySetName); ResourceConfig <VirtualMachine> virtualMachine = null; if (DiskFile == null) { virtualMachine = resourceGroup.CreateVirtualMachineConfig( name: Name, networkInterface: networkInterface, getImageAndOsType: () => imageAndOsType, adminUsername: Credential.UserName, adminPassword: new NetworkCredential(string.Empty, Credential.Password).Password, size: Size, availabilitySet: availabilitySet); } else { var resourceClient = AzureSession.Instance.ClientFactory.CreateArmClient <ResourceManagementClient>(DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager); if (!resourceClient.ResourceGroups.CheckExistence(ResourceGroupName)) { var st0 = resourceClient.ResourceGroups.CreateOrUpdate(ResourceGroupName, new ResourceGroup { Location = Location, Name = ResourceGroupName }); } imageAndOsType = new ImageAndOsType( Linux ? OperatingSystemTypes.Linux : OperatingSystemTypes.Windows, null); var storageClient = AzureSession.Instance.ClientFactory.CreateArmClient <StorageManagementClient>(DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager); var st1 = storageClient.StorageAccounts.Create( ResourceGroupName, Name, new StorageAccountCreateParameters { #if !NETSTANDARD AccountType = AccountType.PremiumLRS, #else Sku = new Microsoft.Azure.Management.Storage.Models.Sku { Name = SkuName.PremiumLRS }, #endif Location = Location }); var filePath = new FileInfo(SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiskFile)); using (var vds = new VirtualDiskStream(filePath.FullName)) { if (vds.DiskType == DiskType.Fixed) { long divisor = Convert.ToInt64(Math.Pow(2, 9)); long rem = 0; Math.DivRem(filePath.Length, divisor, out rem); if (rem != 0) { throw new ArgumentOutOfRangeException( "filePath", string.Format("Given vhd file '{0}' is a corrupted fixed vhd", filePath)); } } } var storageAccount = storageClient.StorageAccounts.GetProperties(ResourceGroupName, Name); BlobUri destinationUri = null; BlobUri.TryParseUri( new Uri(string.Format( "{0}{1}/{2}{3}", storageAccount.PrimaryEndpoints.Blob, ResourceGroupName.ToLower(), Name.ToLower(), ".vhd")), out destinationUri); if (destinationUri == null || destinationUri.Uri == null) { throw new ArgumentNullException("destinationUri"); } var storageCredentialsFactory = new StorageCredentialsFactory( this.ResourceGroupName, storageClient, DefaultContext.Subscription); var parameters = new UploadParameters(destinationUri, null, filePath, true, 2) { Cmdlet = this, BlobObjectFactory = new CloudPageBlobObjectFactory(storageCredentialsFactory, TimeSpan.FromMinutes(1)) }; if (!string.Equals( Environment.GetEnvironmentVariable("AZURE_TEST_MODE"), "Playback", StringComparison.OrdinalIgnoreCase)) { var st2 = VhdUploaderModel.Upload(parameters); } var disk = resourceGroup.CreateManagedDiskConfig( name: Name, sourceUri: destinationUri.Uri.ToString() ); virtualMachine = resourceGroup.CreateVirtualMachineConfig( name: Name, networkInterface: networkInterface, osType: imageAndOsType.OsType, disk: disk, size: Size, availabilitySet: availabilitySet); } var client = new Client(DefaultProfile.DefaultContext); // get current Azure state var current = await virtualMachine.GetStateAsync(client, new CancellationToken()); Location = current.UpdateLocation(Location, virtualMachine); // generate a domain name label if it's not specified. DomainNameLabel = await PublicIPAddressStrategy.UpdateDomainNameLabelAsync( domainNameLabel : DomainNameLabel, name : Name, location : Location, client : client); var fqdn = PublicIPAddressStrategy.Fqdn(DomainNameLabel, Location); if (DiskFile == null) { imageAndOsType = await client.UpdateImageAndOsTypeAsync(ImageName, Location); } // create target state var target = virtualMachine.GetTargetState(current, client.SubscriptionId, Location); if (target.Get(availabilitySet) != null) { throw new InvalidOperationException("Availability set doesn't exist."); } // apply target state var newState = await virtualMachine .UpdateStateAsync( client, target, new CancellationToken(), new ShouldProcess(asyncCmdlet), asyncCmdlet.ReportTaskProgress); var result = newState.Get(virtualMachine); if (result == null) { result = current.Get(virtualMachine); } if (result != null) { var psResult = ComputeAutoMapperProfile.Mapper.Map <PSVirtualMachine>(result); psResult.FullyQualifiedDomainName = fqdn; asyncCmdlet.WriteVerbose(imageAndOsType.OsType == OperatingSystemTypes.Windows ? "Use 'mstsc /v:" + fqdn + "' to connect to the VM." : "Use 'ssh " + Credential.UserName + "@" + fqdn + "' to connect to the VM."); asyncCmdlet.WriteObject(psResult); } }
/// <summary> /// Creates an accurate AzureRM resource Uri string /// </summary> /// <returns>AzureRM resource Uri String</returns> public override string ToString() { if (!IsValid) { throw new Exception("ResourceUri does not contain valid components to create a valid AzureRM resource Uri string."); } // test & cleanup string?providerName = (string.IsNullOrWhiteSpace(ProviderName) ? null : ProviderName.Trim()); string?type = (string.IsNullOrWhiteSpace(Type) ? null : Type.Trim()); string?resourceGroupName = (string.IsNullOrWhiteSpace(ResourceGroupName) ? null : ResourceGroupName.Trim()); string?objectName = (string.IsNullOrWhiteSpace(ResourceName) ? null : ResourceName.Trim()); StringBuilder uri = new StringBuilder(); uri.Append("/subscriptions/").Append(Subscription.ToString("d")); if (resourceGroupName != null) { uri.Append("/resourceGroups/").Append(resourceGroupName); } if (providerName != null) { uri.Append("/providers/").Append(providerName); } if (type != null) { uri.Append("/").Append(type); } if (objectName != null) { uri.Append("/").Append(objectName); } return(uri.ToString()); }
public void TestIotCentralCreateLifeCycle() { using (MockContext context = MockContext.Start(this.GetType())) { // Note: Set IotCentralTestBase.isTestRecorderRun to true when building and running tests locally (before recording for PR). Initialize(context); // Create Resource Group Microsoft.Azure.Management.ResourceManager.Models.ResourceGroup resourceGroup = CreateResourceGroup(this.ResourceGroupName); // Create App App app = CreateIotCentral(resourceGroup, IotCentralTestUtilities.DefaultLocation, ResourceName, SubDomain); // Validate resourceName and subdomain are taken this.CheckAppNameAndSubdomainTaken(app.Name, app.Subdomain); Assert.NotNull(app); Assert.Equal(DefaultIotcSku, app.Sku.Name); Assert.Contains(IotCentralTestUtilities.DefaultResourceName, app.Name); Assert.Contains(IotCentralTestUtilities.DefaultSubdomain, app.Subdomain); Assert.Equal("eastus", app.Location); Assert.Equal("created", app.State); Assert.Equal("Microsoft.IoTCentral/IoTApps", app.Type); Assert.Equal("None", app.Identity.Type); // Add and Get Tags IDictionary <string, string> tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" }, }; var appPatch = new AppPatch() { Tags = tags, DisplayName = ResourceName, Subdomain = SubDomain, }; app = this.iotCentralClient.Apps.Update(ResourceGroupName, ResourceName, appPatch); Assert.NotNull(app); Assert.True(app.Tags.Count().Equals(2)); Assert.Equal("value2", app.Tags["key2"]); // Get all Iot Central apps in a resource group var iotAppsByResourceGroup = this.iotCentralClient.Apps.ListByResourceGroup(ResourceGroupName.ToLowerInvariant()).ToList(); // Get all Iot Apps in a subscription var iotAppsBySubscription = this.iotCentralClient.Apps.ListBySubscription().ToList(); Assert.True(iotAppsByResourceGroup.Count > 0); Assert.True(iotAppsBySubscription.Count > 0); } }
/// <summary> /// Serializes the state of this cmdlet to a <see cref="Microsoft.Azure.AzConfig.Runtime.Json.JsonNode" /> object. /// </summary> /// <param name="container">The <see cref="Microsoft.Azure.AzConfig.Runtime.Json.JsonObject"/> container to serialize this object into. If the caller /// passes in <c>null</c>, a new instance will be created and returned to the caller.</param> /// <param name="serializationMode">Allows the caller to choose the depth of the serialization. See <see cref="Microsoft.Azure.AzConfig.Runtime.SerializationMode"/>.</param> /// <returns> /// a serialized instance of <see cref="UpdateAzConfigurationStore_ResourceGroupNameConfigStoreNamePropertiesTags" /> as a /// <see cref="Microsoft.Azure.AzConfig.Runtime.Json.JsonNode" />. /// </returns> public Microsoft.Azure.AzConfig.Runtime.Json.JsonNode ToJson(Microsoft.Azure.AzConfig.Runtime.Json.JsonObject container, Microsoft.Azure.AzConfig.Runtime.SerializationMode serializationMode) { // serialization method container = container ?? new Microsoft.Azure.AzConfig.Runtime.Json.JsonObject(); AddIf(null != (((object)SubscriptionId)?.ToString()) ? (Microsoft.Azure.AzConfig.Runtime.Json.JsonNode) new Microsoft.Azure.AzConfig.Runtime.Json.JsonString(SubscriptionId.ToString()) : null, "SubscriptionId", container.Add); AddIf(null != (((object)ResourceGroupName)?.ToString()) ? (Microsoft.Azure.AzConfig.Runtime.Json.JsonNode) new Microsoft.Azure.AzConfig.Runtime.Json.JsonString(ResourceGroupName.ToString()) : null, "ResourceGroupName", container.Add); AddIf(null != (((object)ConfigStoreName)?.ToString()) ? (Microsoft.Azure.AzConfig.Runtime.Json.JsonNode) new Microsoft.Azure.AzConfig.Runtime.Json.JsonString(ConfigStoreName.ToString()) : null, "ConfigStoreName", container.Add); AddIf(null != ConfigStoreUpdateParameters ? (Microsoft.Azure.AzConfig.Runtime.Json.JsonNode)ConfigStoreUpdateParameters.ToJson(null) : null, "ConfigStoreUpdateParameters", container.Add); return(container); }
public void TestIotCentralCreateWithManagedIdentityLifeCycle() { using (MockContext context = MockContext.Start(this.GetType())) { Initialize(context); // Create Resource Group Microsoft.Azure.Management.ResourceManager.Models.ResourceGroup resourceGroup = CreateResourceGroup(ResourceGroupName); // Create App App app = CreateIotCentral(resourceGroup, IotCentralTestUtilities.DefaultLocation, ResourceName, SubDomain, DefaultMIType); // Validate resourceName and subdomain are taken this.CheckAppNameAndSubdomainTaken(app.Name, app.Subdomain); Assert.NotNull(app); Assert.Equal(AppSku.ST2, app.Sku.Name); Assert.Contains(IotCentralTestUtilities.DefaultResourceName, app.Name); Assert.Contains(IotCentralTestUtilities.DefaultSubdomain, app.Subdomain); Assert.Equal("eastus", app.Location); Assert.Equal("created", app.State); Assert.Equal("Microsoft.IoTCentral/IoTApps", app.Type); // validate managed identity. Assert.NotNull(app.Identity); Assert.Equal("SystemAssigned", app.Identity.Type); Assert.NotNull(app.Identity.PrincipalId); Assert.NotNull(app.Identity.TenantId); var principalId = app.Identity.PrincipalId; var tenantId = app.Identity.TenantId; // Add and Get Tags IDictionary <string, string> tags = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" }, }; var appPatch = new AppPatch() { Tags = tags, DisplayName = ResourceName, Subdomain = SubDomain, }; app = this.iotCentralClient.Apps.Update(ResourceGroupName, ResourceName, appPatch); Assert.NotNull(app); Assert.True(app.Tags.Count().Equals(2)); Assert.Equal("value2", app.Tags["key2"]); Assert.NotNull(app.Identity); Assert.Equal("SystemAssigned", app.Identity.Type); Assert.NotNull(app.Identity.PrincipalId); Assert.NotNull(app.Identity.TenantId); Assert.Equal(principalId, app.Identity.PrincipalId); Assert.Equal(tenantId, app.Identity.TenantId); // Get all Iot Central apps in a resource group var iotAppsByResourceGroup = this.iotCentralClient.Apps.ListByResourceGroup(ResourceGroupName.ToLowerInvariant()).ToList(); // Get all Iot Apps in a subscription var iotAppsBySubscription = this.iotCentralClient.Apps.ListBySubscription().ToList(); Assert.True(iotAppsByResourceGroup.Count > 0); Assert.True(iotAppsBySubscription.Count > 0); } }