public void CannotCreateOrUpdateFreeServiceWithIdentity()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();

                string serviceName    = SearchTestUtilities.GenerateServiceName();
                SearchService service = DefineServiceWithSku(SkuName.Free);
                service.Identity      = new Identity(IdentityType.SystemAssigned);

                CloudException e = Assert.Throws <CloudException>(() =>
                                                                  searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service));

                Assert.Equal("Resource identity is not supported for the selected SKU", e.Message);

                // retry create without identity
                service.Identity = null;
                service          = searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service);
                Assert.NotNull(service);
                Assert.Null(service.Identity);

                // try update the created service by defining an identity
                var serviceUpdate = new SearchServiceUpdate
                {
                    Identity = new Identity()
                };

                e = Assert.Throws <CloudException>(() =>
                                                   searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, serviceUpdate));

                Assert.Equal("Resource identity is not supported for the selected SKU", e.Message);
                searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name);
            });
        }
Beispiel #2
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(InputObjectParameterSetName, StringComparison.InvariantCulture))
            {
                ResourceGroupName = InputObject.ResourceGroupName;
                Name = InputObject.Name;
            }
            else if (ParameterSetName.Equals(ResourceIdParameterSetName, StringComparison.InvariantCulture))
            {
                var id = new ResourceIdentifier(ResourceId);
                ResourceGroupName = id.ResourceGroupName;
                Name = id.ResourceName;
            }

            if (ShouldProcess(Name, Resources.UpdateSearchService))
            {
                CatchThrowInnerException(() =>
                {
                    // GET
                    var service = SearchClient.Services.GetWithHttpMessagesAsync(ResourceGroupName, Name).Result.Body;

                    var networkRuleSet = IPRuleList?.Any() == true ? new PSNetworkRuleSet
                    {
                        IpRules = IPRuleList
                    } : null;

                    var identity = IdentityType.HasValue ? new PSIdentity
                    {
                        Type = IdentityType.Value
                    } : null;

                    // UPDATE
                    var update = new SearchServiceUpdate
                    {
                        // Keep existing properties
                        HostingMode = service.HostingMode,
                        Location    = service.Location,
                        //NetworkRuleSet = service.NetworkRuleSet,
                        Sku  = service.Sku,
                        Tags = service.Tags,

                        // Update the properties passed in (treating nulls as no change to be consistent)
                        NetworkRuleSet      = (NetworkRuleSet)networkRuleSet ?? service.NetworkRuleSet,
                        PublicNetworkAccess = (PublicNetworkAccess?)PublicNetworkAccess ?? service.PublicNetworkAccess,
                        Identity            = (Identity)identity ?? service.Identity,

                        PartitionCount = PartitionCount,
                        ReplicaCount   = ReplicaCount,
                    };

                    service = SearchClient.Services.UpdateWithHttpMessagesAsync(ResourceGroupName, Name, update).Result.Body;

                    // OUTPUT
                    WriteSearchService(service);
                });
            }
        }
        public void CanAddAndRemoveServiceIdentity()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();
                string serviceName    = SearchTestUtilities.GenerateServiceName();
                SearchService service = DefineServiceWithSku(SkuName.Basic);
                service.Identity      = null;
                service = searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service);
                Assert.NotNull(service);
                Assert.Equal(IdentityType.None, service.Identity?.Type ?? IdentityType.None);

                // assign an identity of type 'SystemAssigned'
                var serviceUpdateWithIdentity = new SearchServiceUpdate
                {
                    Identity = new Identity(IdentityType.SystemAssigned)
                };

                service = searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, serviceUpdateWithIdentity);
                Assert.NotNull(service);
                Assert.NotNull(service.Identity);
                Assert.Equal(IdentityType.SystemAssigned, service.Identity.Type);

                string principalId = string.IsNullOrWhiteSpace(service.Identity.PrincipalId) ? null : service.Identity.PrincipalId;
                Assert.NotNull(principalId);

                string tenantId = string.IsNullOrWhiteSpace(service.Identity.TenantId) ? null : service.Identity.TenantId;
                Assert.NotNull(tenantId);

                // remove the identity by setting it's type to 'None'
                var serviceUpdateWithIdentityRemoved = new SearchServiceUpdate
                {
                    Identity = new Identity(IdentityType.None)
                };

                service = searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, serviceUpdateWithIdentityRemoved);
                Assert.NotNull(service);
                Assert.Equal(IdentityType.None, service.Identity?.Type ?? IdentityType.None);

                searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name);
            });
        }
 /// <summary>
 /// Updates an existing Search service in the given resource group.
 /// <see href="https://aka.ms/search-manage" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group within the current subscription. You can
 /// obtain this value from the Azure Resource Manager API or the portal.
 /// </param>
 /// <param name='searchServiceName'>
 /// The name of the Azure Cognitive Search service to update.
 /// </param>
 /// <param name='service'>
 /// The definition of the Search service to update.
 /// </param>
 /// <param name='searchManagementRequestOptions'>
 /// Additional parameters for the operation
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <SearchService> UpdateAsync(this IServicesOperations operations, string resourceGroupName, string searchServiceName, SearchServiceUpdate service, SearchManagementRequestOptions searchManagementRequestOptions = default(SearchManagementRequestOptions), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, searchServiceName, service, searchManagementRequestOptions, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Updates an existing Search service in the given resource group.
 /// <see href="https://aka.ms/search-manage" />
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group within the current subscription. You can
 /// obtain this value from the Azure Resource Manager API or the portal.
 /// </param>
 /// <param name='searchServiceName'>
 /// The name of the Azure Cognitive Search service to update.
 /// </param>
 /// <param name='service'>
 /// The definition of the Search service to update.
 /// </param>
 /// <param name='searchManagementRequestOptions'>
 /// Additional parameters for the operation
 /// </param>
 public static SearchService Update(this IServicesOperations operations, string resourceGroupName, string searchServiceName, SearchServiceUpdate service, SearchManagementRequestOptions searchManagementRequestOptions = default(SearchManagementRequestOptions))
 {
     return(operations.UpdateAsync(resourceGroupName, searchServiceName, service, searchManagementRequestOptions).GetAwaiter().GetResult());
 }