Esempio n. 1
0
        public PsApiManagement SetHostnames(
            string resourceGroupName,
            string serviceName,
            PsApiManagementHostnameConfiguration portalHostnameConfiguration,
            PsApiManagementHostnameConfiguration proxyHostnameConfiguration)
        {
            var currentStateResource = Client.ApiManagementService.Get(resourceGroupName, serviceName);
            var currentState         = new PsApiManagement(currentStateResource);

            var parameters = new ApiManagementServiceUpdateHostnameParameters
            {
                Delete = GetHostnamesToDelete(portalHostnameConfiguration, proxyHostnameConfiguration, currentState),
                Update = GetHostnamesToCreateOrUpdate(portalHostnameConfiguration, proxyHostnameConfiguration, currentState).ToList()
            };

            var apiManagementServiceResource = Client.ApiManagementService.UpdateHostname(resourceGroupName, serviceName, parameters);

            return(new PsApiManagement(apiManagementServiceResource));
        }
Esempio n. 2
0
        public async Task UpdateHostNameTests()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var testBase = new ApiManagementTestBase(context);

                var createdService = testBase.client.ApiManagementService.CreateOrUpdate(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName,
                    parameters: testBase.serviceProperties);

                ValidateService(createdService,
                                testBase.serviceName,
                                testBase.rgName,
                                testBase.subscriptionId,
                                testBase.location,
                                testBase.serviceProperties.PublisherEmail,
                                testBase.serviceProperties.PublisherName,
                                testBase.serviceProperties.Sku.Name,
                                testBase.tags);

                var base64ArrayCertificate = Convert.FromBase64String(testBase.base64EncodedTestCertificateData);
                var cert = new X509Certificate2(base64ArrayCertificate, testBase.testCertificatePassword);

                var uploadCertificateParams = new ApiManagementServiceUploadCertificateParameters()
                {
                    Type                = HostnameType.Proxy,
                    Certificate         = testBase.base64EncodedTestCertificateData,
                    CertificatePassword = testBase.testCertificatePassword
                };
                var certificateInformation = await testBase.client.ApiManagementService.UploadCertificateAsync(testBase.rgName, testBase.serviceName, uploadCertificateParams);

                Assert.NotNull(certificateInformation);
                Assert.Equal(cert.Thumbprint, certificateInformation.Thumbprint);
                Assert.Equal(cert.Subject, certificateInformation.Subject);

                var updateHostnameParams = new ApiManagementServiceUpdateHostnameParameters()
                {
                    Update = new List <HostnameConfigurationOld>()
                    {
                        new HostnameConfigurationOld(HostnameType.Proxy, "proxy.msitesting.net", certificateInformation)
                    }
                };

                var serviceResource = await testBase.client.ApiManagementService.UpdateHostnameAsync(
                    testBase.rgName,
                    testBase.serviceName,
                    updateHostnameParams);

                Assert.NotNull(serviceResource);
                Assert.Single(serviceResource.HostnameConfigurations);
                Assert.Equal(HostnameType.Proxy, serviceResource.HostnameConfigurations.First().Type);
                Assert.Equal("proxy.msitesting.net", serviceResource.HostnameConfigurations.First().HostName);

                // Delete
                testBase.client.ApiManagementService.Delete(
                    resourceGroupName: testBase.rgName,
                    serviceName: testBase.serviceName);

                Assert.Throws <CloudException>(() =>
                {
                    testBase.client.ApiManagementService.Get(
                        resourceGroupName: testBase.rgName,
                        serviceName: testBase.serviceName);
                });
            }
        }
 /// <summary>
 /// Creates, updates, or deletes the custom hostnames for an API Management
 /// service. The custom hostname can be applied to the Proxy and Portal
 /// endpoint. This is a long running operation and could take several minutes
 /// to complete. This operation will be deprecated in the next version update.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// The name of the API Management service.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the UpdateHostname operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ApiManagementServiceResource> BeginUpdateHostnameAsync(this IApiManagementServiceOperations operations, string resourceGroupName, string serviceName, ApiManagementServiceUpdateHostnameParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginUpdateHostnameWithHttpMessagesAsync(resourceGroupName, serviceName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Creates, updates, or deletes the custom hostnames for an API Management
 /// service. The custom hostname can be applied to the Proxy and Portal
 /// endpoint. This is a long running operation and could take several minutes
 /// to complete. This operation will be deprecated in the next version update.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// The name of the API Management service.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the UpdateHostname operation.
 /// </param>
 public static ApiManagementServiceResource BeginUpdateHostname(this IApiManagementServiceOperations operations, string resourceGroupName, string serviceName, ApiManagementServiceUpdateHostnameParameters parameters)
 {
     return(operations.BeginUpdateHostnameAsync(resourceGroupName, serviceName, parameters).GetAwaiter().GetResult());
 }