protected App UpdateIotCentral(ResourceGroup resourceGroup, AppPatch app, string appResourceName)
 {
     return(this.iotCentralClient.Apps.Update(
                resourceGroup.Name,
                appResourceName,
                app));
 }
        public void TestIotCentralCreateLifeCycle()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                Initialize(context);

                // Create Resource Group
                var resourceGroup = CreateResourceGroup(IotCentralTestUtilities.DefaultResourceGroupName);

                // Create App
                var app = CreateIotCentral(resourceGroup, IotCentralTestUtilities.DefaultLocation, IotCentralTestUtilities.DefaultResourceName, IotCentralTestUtilities.DefaultSubdomain);

                // Validate resourceName and subdomain are taken
                this.CheckAppNameAndSubdomainTaken(app.Name, app.Subdomain);

                Assert.NotNull(app);
                Assert.Equal(AppSku.ST1, app.Sku.Name);
                Assert.Equal(IotCentralTestUtilities.DefaultResourceName, app.Name);
                Assert.Equal(IotCentralTestUtilities.DefaultSubdomain, app.Subdomain);

                // Add and Get Tags
                IDictionary <string, string> tags = new Dictionary <string, string>
                {
                    { "key1", "value1" },
                    { "key2", "value2" }
                };

                var appPatch = new AppPatch()
                {
                    Tags        = tags,
                    DisplayName = IotCentralTestUtilities.DefaultResourceName,
                    Subdomain   = IotCentralTestUtilities.DefaultSubdomain
                };

                app = this.iotCentralClient.Apps.Update(IotCentralTestUtilities.DefaultResourceGroupName, IotCentralTestUtilities.DefaultResourceName, 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(IotCentralTestUtilities.DefaultResourceGroupName.ToLowerInvariant()).ToList();

                // Get all Iot Apps in a subscription
                var iotAppsBySubscription = this.iotCentralClient.Apps.ListBySubscription().ToList();

                // Get all of the available IoT Apps REST API operations
                var operationList = this.iotCentralClient.Operations.List().ToList();

                // Get IoT Central Apps REST API read operation
                var readOperation = operationList.Where(e => e.Name.Equals("Microsoft.IoTCentral/IotApps/Read", StringComparison.OrdinalIgnoreCase)).ToList();

                Assert.True(iotAppsByResourceGroup.Count > 0);
                Assert.True(iotAppsBySubscription.Count > 0);
                Assert.True(operationList.Count > 0);
                Assert.True(readOperation.Count.Equals(1));
            }
        }
Exemplo n.º 3
0
        static void Main()
        {
            // Access token from the azure-cli
            // az account get-access-token
            var token          = "";
            var subscriptionId = "";
            var creds          = new TokenCredentials(token, "Bearer");

            var client   = new IotCentralClient(creds);
            var skuInfo  = new AppSkuInfo("ST2");
            var location = "unitedstates";
            var app      = new App(location, skuInfo);

            client.SubscriptionId = subscriptionId;

            var name          = "csharp-test-app";
            var resourceGroup = "myResourceGroup";

            app.Location    = location;
            app.Subdomain   = name;
            app.DisplayName = name;

            Console.WriteLine("Check if the app name is available");
            OperationInputs input         = new OperationInputs(name);
            var             nameAvailable = client.Apps.CheckNameAvailability(input);

            Console.WriteLine(nameAvailable.Message);

            Console.WriteLine("Creating the app");
            client.Apps.CreateOrUpdate(resourceGroup, name, app);

            Console.WriteLine("Getting the app");
            var resultApp = client.Apps.Get(resourceGroup, name);

            Console.WriteLine(resultApp);

            Console.WriteLine("Updating the app");
            var updateApp = new AppPatch();

            updateApp.DisplayName = name + "-new-name";
            var updateResult = client.Apps.Update(resourceGroup, name, updateApp);

            Console.WriteLine(updateResult);

            Console.WriteLine("Listing apps");
            foreach (var currentApp in client.Apps.ListByResourceGroup(resourceGroup))
            {
                Console.WriteLine($"{currentApp.DisplayName} ({currentApp.Id})");
            }

            Console.WriteLine(Environment.NewLine);
            // Console.WriteLine("Removing app");
            // client.Apps.Delete(resourceGroup, name);

            Console.WriteLine("Done");
        }
        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);
            }
        }
Exemplo n.º 5
0
 public override void ExecuteCmdlet()
 {
     this.SetNameAndResourceGroup();
     if (ShouldProcess(Name, ResourceProperties.Resources.SetIotCentralApp))
     {
         AppPatch applicationPatch             = CreateApplicationPatch();
         App      updatedIotCentralApplication = this.IotCentralClient.Apps.Update(this.ResourceGroupName, this.Name, applicationPatch);
         this.WriteObject(IotCentralUtils.ToPSIotCentralApp(updatedIotCentralApplication));
     }
 }
        private AppPatch CreateApplicationPatch()
        {
            App existingIotCentralApplication = this.GetApplication();

            this.SetApplicationDisplayName(existingIotCentralApplication);
            this.SetApplicationTags(existingIotCentralApplication);
            AppPatch iotCentralAppPatch = IotCentralUtils.CreateAppPatch(existingIotCentralApplication);

            return(iotCentralAppPatch);
        }
        public static AppPatch CreateAppPatch(App iotCentralApp)
        {
            var copiedIotCenralApp = new AppPatch()
            {
                DisplayName = iotCentralApp.DisplayName,
                Tags        = iotCentralApp.Tags
            };

            return(copiedIotCenralApp);
        }
        public void TestIotCentralUpdateLifeCycle()
        {
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                this.Initialize(context);

                // Create Resource Group
                var resourceGroup = CreateResourceGroup(UpdateResourceGroupName);

                // Create App
                var app = CreateIotCentral(resourceGroup, IotCentralTestUtilities.DefaultLocation, UpdateResourceName, UpdateSubDomain);

                // Validate the default sku
                Assert.Equal(DefaultIotcSku, app.Sku.Name);

                // Validate resourceName and subdomain are taken
                this.CheckAppNameAndSubdomainTaken(app.Name, app.Subdomain);

                // Update App
                var newSubDomain   = "test-updated-sub-domain";
                var newDisplayName = "test-updated-display-name";

                // Add and Get Tags
                IDictionary <string, string> tags = new Dictionary <string, string>
                {
                    { "key1", "value1" },
                    { "key2", "value2" },
                };

                AppPatch appPatch = new AppPatch()
                {
                    Tags        = tags,
                    DisplayName = newDisplayName,
                    Subdomain   = newSubDomain,
                    Sku         = new AppSkuInfo(AppSku.ST2),
                };

                app = UpdateIotCentral(resourceGroup, appPatch, UpdateResourceName);

                // List apps
                app = iotCentralClient.Apps.ListByResourceGroup(UpdateResourceGroupName)
                      .FirstOrDefault(e => e.Name.Equals(UpdateResourceName, StringComparison.OrdinalIgnoreCase));

                Assert.NotNull(app);
                Assert.Equal(newDisplayName, app.DisplayName);
                Assert.True(app.Tags.Count().Equals(2));
                Assert.Equal("value2", app.Tags["key2"]);
                Assert.Equal(app.Sku.Name, AppSku.ST2);
            }
        }
Exemplo n.º 9
0
        private AppPatch CreateApplicationPatch()
        {
            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);
        }
        static void Main()
        {
            // Access token from the azure-cli
            // az account get-access-token
            var token          = "";
            var subscriptionId = "";
            var creds          = new TokenCredentials(token, "Bearer");

            var client   = new IotCentralClient(creds);
            var skuInfo  = new AppSkuInfo("ST2");
            var location = "unitedstates";
            var app      = new App(location, skuInfo);

            client.SubscriptionId = subscriptionId;

            var name          = "csharp-test-app";
            var resourceGroup = "myResourceGroup";

            app.Location    = location;
            app.Subdomain   = name;
            app.DisplayName = name;

            Console.WriteLine("===Check if the app name is available");
            OperationInputs input = new OperationInputs(name);
            var             appNameAvailability = client.Apps.CheckNameAvailability(input);

            if (appNameAvailability.NameAvailable == true)
            {
                Console.WriteLine("app name is available!");
            }
            else
            {
                Console.WriteLine($"app name isn't available because {appNameAvailability.Reason}");
            }

            Console.WriteLine("===Creating the app");
            var createApp = client.Apps.CreateOrUpdate(resourceGroup, name, app);

            Console.WriteLine(createApp.Name);
            Console.WriteLine(createApp.DisplayName);

            Console.WriteLine("===Getting the app");
            var resultApp = client.Apps.Get(resourceGroup, name);

            Console.WriteLine(resultApp.Name);
            Console.WriteLine(resultApp.DisplayName);

            Console.WriteLine("===Updating the app");
            var updateApp = new AppPatch();

            updateApp.DisplayName = name + "-new-name";
            var updateResult = client.Apps.Update(resourceGroup, name, updateApp);

            Console.WriteLine(updateResult.Name);
            Console.WriteLine(updateResult.DisplayName);

            Console.WriteLine($"===Listing all the apps under the resource group of {resourceGroup}");
            foreach (var currentApp in client.Apps.ListByResourceGroup(resourceGroup))
            {
                Console.WriteLine($"{currentApp.DisplayName} ({currentApp.Id})");
            }

            Console.WriteLine("===Listing all the operations in iotc");
            foreach (var currentOperation in client.Operations.List())
            {
                Console.WriteLine(currentOperation.Name);
            }

            Console.WriteLine("===Listing all the app templates in iotc");
            foreach (var currentAppTemplate in client.Apps.ListTemplates())
            {
                Console.WriteLine(currentAppTemplate.Name);
            }

            Console.WriteLine("===Removing app");
            client.Apps.Delete(resourceGroup, name);

            Console.WriteLine("Done");
        }
        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);
            }
        }
 /// <summary>
 /// Update the metadata of an IoT Central application.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the IoT Central application.
 /// </param>
 /// <param name='resourceName'>
 /// The ARM resource name of the IoT Central application.
 /// </param>
 /// <param name='appPatch'>
 /// The IoT Central application metadata and security metadata.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <App> BeginUpdateAsync(this IAppsOperations operations, string resourceGroupName, string resourceName, AppPatch appPatch, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginUpdateWithHttpMessagesAsync(resourceGroupName, resourceName, appPatch, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Update the metadata of an IoT Central application.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group that contains the IoT Central application.
 /// </param>
 /// <param name='resourceName'>
 /// The ARM resource name of the IoT Central application.
 /// </param>
 /// <param name='appPatch'>
 /// The IoT Central application metadata and security metadata.
 /// </param>
 public static App BeginUpdate(this IAppsOperations operations, string resourceGroupName, string resourceName, AppPatch appPatch)
 {
     return(operations.BeginUpdateAsync(resourceGroupName, resourceName, appPatch).GetAwaiter().GetResult());
 }