Пример #1
0
        public PsApiManagement(ApiServiceResource apiServiceResource)
            : this()
        {
            if (apiServiceResource == null)
            {
                throw new ArgumentNullException("apiServiceResource");
            }

            Id                = apiServiceResource.Id;
            Name              = apiServiceResource.Name;
            Location          = apiServiceResource.Location;
            Sku               = Mapper.Map <SkuType, PsApiManagementSku>(apiServiceResource.Properties.SkuProperties.SkuType);
            Capacity          = apiServiceResource.Properties.SkuProperties.Capacity ?? 1;
            ProvisioningState = apiServiceResource.Properties.ProvisioningState;
            RuntimeUrl        = apiServiceResource.Properties.ProxyEndpoint;
            PortalUrl         = apiServiceResource.Properties.ManagementPortalEndpoint;
            StaticIPs         = apiServiceResource.Properties.StaticIPs.ToArray();

            if (apiServiceResource.Properties.AdditionalRegions != null)
            {
                AdditionalRegions =
                    apiServiceResource.Properties.AdditionalRegions
                    .Select(region => new PsApiManagementRegion(region))
                    .ToList();
            }

            if (apiServiceResource.Properties.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(apiServiceResource.Properties.VirtualNetworkConfiguration);
            }

            if (apiServiceResource.Properties.HostnameConfigurations != null)
            {
                var portalHostnameResource = apiServiceResource.Properties.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Portal);
                if (portalHostnameResource != null)
                {
                    PortalHostnameConfiguration = new PsApiManagementHostnameConfiguration(portalHostnameResource);
                }

                var proxyHostnameResource = apiServiceResource.Properties.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Proxy);
                if (proxyHostnameResource != null)
                {
                    ProxyHostnameConfiguration = new PsApiManagementHostnameConfiguration(proxyHostnameResource);
                }
            }

            if (apiServiceResource.Tags != null)
            {
                Tags = apiServiceResource.Tags;
            }
        }
Пример #2
0
        public PsApiManagement(ApiServiceResource apiServiceResource)
            : this()
        {
            if (apiServiceResource == null)
            {
                throw new ArgumentNullException("apiServiceResource");
            }

            Id = apiServiceResource.Id;
            Name = apiServiceResource.Name;
            Location = apiServiceResource.Location;
            Sku = Mapper.Map<SkuType, PsApiManagementSku>(apiServiceResource.Properties.SkuProperties.SkuType);
            Capacity = apiServiceResource.Properties.SkuProperties.Capacity ?? 1;
            ProvisioningState = apiServiceResource.Properties.ProvisioningState;
            RuntimeUrl = apiServiceResource.Properties.ProxyEndpoint;
            PortalUrl = apiServiceResource.Properties.ManagementPortalEndpoint;
            StaticIPs = apiServiceResource.Properties.StaticIPs.ToArray();

            if (apiServiceResource.Properties.AdditionalRegions != null)
            {
                AdditionalRegions =
                    apiServiceResource.Properties.AdditionalRegions
                        .Select(region => new PsApiManagementRegion(region))
                        .ToList();
            }

            if (apiServiceResource.Properties.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(apiServiceResource.Properties.VirtualNetworkConfiguration);
            }

            if (apiServiceResource.Properties.HostnameConfigurations != null)
            {
                var portalHostnameResource = apiServiceResource.Properties.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Portal);
                if (portalHostnameResource != null)
                {
                    PortalHostnameConfiguration = new PsApiManagementHostnameConfiguration(portalHostnameResource);
                }

                var proxyHostnameResource = apiServiceResource.Properties.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Proxy);
                if (proxyHostnameResource != null)
                {
                    ProxyHostnameConfiguration = new PsApiManagementHostnameConfiguration(proxyHostnameResource);
                }
            }

            if (apiServiceResource.Tags != null)
            {
                Tags = apiServiceResource.Tags;
            }
        }
        private static IEnumerable<HostnameType> GetHostnamesToDelete(
            PsApiManagementHostnameConfiguration portalHostnameConfiguration,
            PsApiManagementHostnameConfiguration proxyHostnameConfiguration,
            PsApiManagement currentState)
        {
            if (portalHostnameConfiguration == null && currentState.PortalHostnameConfiguration != null)
            {
                yield return HostnameType.Portal;
            }

            if (proxyHostnameConfiguration == null && currentState.ProxyHostnameConfiguration != null)
            {
                yield return HostnameType.Proxy;
            }
        }
        private static IEnumerable<HostnameConfiguration> GetHostnamesToCreateOrUpdate(
            PsApiManagementHostnameConfiguration portalHostnameConfiguration,
            PsApiManagementHostnameConfiguration proxyHostnameConfiguration,
            PsApiManagement currentState)
        {
            if (portalHostnameConfiguration != null)
            {
                yield return new HostnameConfiguration(
                    HostnameType.Portal,
                    portalHostnameConfiguration.Hostname,
                    new CertificateInformation
                    {
                        Thumbprint = portalHostnameConfiguration.HostnameCertificate.Thumbprint,
                        Subject = string.IsNullOrWhiteSpace(portalHostnameConfiguration.HostnameCertificate.Subject) ? "dummy" : portalHostnameConfiguration.HostnameCertificate.Subject
                    });
            }

            if (proxyHostnameConfiguration != null)
            {
                yield return new HostnameConfiguration(
                    HostnameType.Proxy,
                    proxyHostnameConfiguration.Hostname,
                    new CertificateInformation
                    {
                        Thumbprint = proxyHostnameConfiguration.HostnameCertificate.Thumbprint,
                        Subject = string.IsNullOrWhiteSpace(proxyHostnameConfiguration.HostnameCertificate.Subject) ? "dummy" : proxyHostnameConfiguration.HostnameCertificate.Subject
                    });
            }
        }
        public ApiManagementLongRunningOperation BeginSetHostnames(
            string resourceGroupName,
            string serviceName,
            PsApiManagementHostnameConfiguration portalHostnameConfiguration,
            PsApiManagementHostnameConfiguration proxyHostnameConfiguration)
        {
            var currentStateResource = Client.ResourceProvider.Get(resourceGroupName, serviceName);
            var currentState = new PsApiManagement(currentStateResource.Value);

            var parameters = new ApiServiceUpdateHostnameParameters
            {
                HostnamesToDelete = GetHostnamesToDelete(portalHostnameConfiguration, proxyHostnameConfiguration, currentState).ToList(),
                HostnamesToCreateOrUpdate = GetHostnamesToCreateOrUpdate(portalHostnameConfiguration, proxyHostnameConfiguration, currentState).ToList()
            };

            var longrunningResponse = Client.ResourceProvider.BeginUpdatingHostname(resourceGroupName, serviceName, parameters);
            AdjustRetryAfter(longrunningResponse, _client.LongRunningOperationInitialTimeout);
            return ApiManagementLongRunningOperation.CreateLongRunningOperation("Set-AzureRmApiManagementHostnames", longrunningResponse);
        }
        private static IEnumerable<HostnameConfiguration> GetHostnamesToCreateOrUpdate(
            PsApiManagementHostnameConfiguration portalHostnameConfiguration,
            PsApiManagementHostnameConfiguration proxyHostnameConfiguration,
            PsApiManagement currentState)
        {
            if (portalHostnameConfiguration != null && currentState.PortalHostnameConfiguration != null)
            {
                yield return new HostnameConfiguration(
                    HostnameType.Portal,
                    portalHostnameConfiguration.Hostname,
                    new CertificateInformation(
                        portalHostnameConfiguration.HostnameCertificate.Expiry,
                        portalHostnameConfiguration.HostnameCertificate.Thumbprint,
                        portalHostnameConfiguration.HostnameCertificate.Subject));
            }

            if (proxyHostnameConfiguration != null && currentState.ProxyHostnameConfiguration != null)
            {
                yield return new HostnameConfiguration(
                    HostnameType.Proxy,
                    proxyHostnameConfiguration.Hostname,
                    new CertificateInformation(
                        proxyHostnameConfiguration.HostnameCertificate.Expiry,
                        proxyHostnameConfiguration.HostnameCertificate.Thumbprint,
                        proxyHostnameConfiguration.HostnameCertificate.Subject));
            }
        }
Пример #7
0
        public PsApiManagement(ApiManagementServiceResource apiServiceResource)
            : this()
        {
            if (apiServiceResource == null)
            {
                throw new ArgumentNullException("apiServiceResource");
            }

            Id                      = apiServiceResource.Id;
            Name                    = apiServiceResource.Name;
            Location                = apiServiceResource.Location;
            Sku                     = ApiManagementClient.Mapper.Map <string, PsApiManagementSku>(apiServiceResource.Sku.Name);
            Capacity                = apiServiceResource.Sku.Capacity ?? 1;
            PublisherEmail          = apiServiceResource.PublisherEmail;
            OrganizationName        = apiServiceResource.PublisherName;
            NotificationSenderEmail = apiServiceResource.NotificationSenderEmail;
            ProvisioningState       = apiServiceResource.ProvisioningState;
            RuntimeUrl              = apiServiceResource.GatewayUrl;
            RuntimeRegionalUrl      = apiServiceResource.GatewayRegionalUrl;
            PortalUrl               = apiServiceResource.PortalUrl;
            ManagementApiUrl        = apiServiceResource.ManagementApiUrl;
            ScmUrl                  = apiServiceResource.ScmUrl;
            PublicIPAddresses       = apiServiceResource.PublicIPAddresses != null?apiServiceResource.PublicIPAddresses.ToArray() : null;

            PrivateIPAddresses = apiServiceResource.PrivateIPAddresses != null?apiServiceResource.PrivateIPAddresses.ToArray() : null;

            var staticIPList = new List <string>();

            if (apiServiceResource.PublicIPAddresses != null)
            {
                staticIPList.AddRange(apiServiceResource.PublicIPAddresses);
            }
            if (apiServiceResource.PrivateIPAddresses != null)
            {
                staticIPList.AddRange(apiServiceResource.PrivateIPAddresses);
            }
#pragma warning disable CS0618
            StaticIPs = staticIPList.ToArray();
#pragma warning restore CS0618
            VpnType = ApiManagementClient.Mapper.Map <string, PsApiManagementVpnType>(apiServiceResource.VirtualNetworkType);

            if (apiServiceResource.AdditionalLocations != null)
            {
                AdditionalRegions =
                    apiServiceResource.AdditionalLocations
                    .Select(region => new PsApiManagementRegion(region))
                    .ToList();
            }

            if (apiServiceResource.VirtualNetworkConfiguration != null)
            {
                VirtualNetwork = new PsApiManagementVirtualNetwork(apiServiceResource.VirtualNetworkConfiguration);
            }

            if (apiServiceResource.HostnameConfigurations != null &&
                apiServiceResource.HostnameConfigurations.Any())
            {
                var portalHostnameResource = apiServiceResource.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Portal);
                if (portalHostnameResource != null)
                {
#pragma warning disable CS0618
                    PortalHostnameConfiguration = new PsApiManagementHostnameConfiguration(portalHostnameResource);
#pragma warning restore CS0618
                    PortalCustomHostnameConfiguration = new PsApiManagementCustomHostNameConfiguration(portalHostnameResource);
                }

                var proxyHostnameResources = apiServiceResource.HostnameConfigurations.Where(conf => conf.Type == HostnameType.Proxy);
                if (proxyHostnameResources != null && proxyHostnameResources.Any())
                {
#pragma warning disable CS0618
                    ProxyHostnameConfiguration = new PsApiManagementHostnameConfiguration(proxyHostnameResources.First());
#pragma warning restore CS0618
                    var proxyCustomHostnameResources = new List <PsApiManagementCustomHostNameConfiguration>();
                    foreach (var proxyHostNameResource in proxyHostnameResources)
                    {
                        proxyCustomHostnameResources.Add(new PsApiManagementCustomHostNameConfiguration(proxyHostNameResource));
                    }

                    ProxyCustomHostnameConfiguration = proxyCustomHostnameResources.ToArray();
                }

                var managementHostnameResource = apiServiceResource.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Management);
                if (managementHostnameResource != null)
                {
#pragma warning disable CS0618
                    ManagementHostnameConfiguration = new PsApiManagementHostnameConfiguration(managementHostnameResource);
#pragma warning restore CS0618
                    ManagementCustomHostnameConfiguration = new PsApiManagementCustomHostNameConfiguration(managementHostnameResource);
                }

                var scmHostnameResource = apiServiceResource.HostnameConfigurations.FirstOrDefault(conf => conf.Type == HostnameType.Scm);
                if (scmHostnameResource != null)
                {
#pragma warning disable CS0618
                    ScmHostnameConfiguration = new PsApiManagementHostnameConfiguration(scmHostnameResource);
#pragma warning restore CS0618
                    ScmCustomHostnameConfiguration = new PsApiManagementCustomHostNameConfiguration(scmHostnameResource);
                }
            }

            if (apiServiceResource.Certificates != null && apiServiceResource.Certificates.Any())
            {
                var systemCertificates = new List <PsApiManagementSystemCertificate>();
                foreach (var certificate in apiServiceResource.Certificates)
                {
                    systemCertificates.Add(new PsApiManagementSystemCertificate(certificate));
                }
                SystemCertificates = systemCertificates.ToArray();
            }

            if (apiServiceResource.Tags != null)
            {
                Tags = apiServiceResource.Tags;
            }

            if (apiServiceResource.Identity != null)
            {
                this.Identity = new PsApiManagementServiceIdentity(apiServiceResource.Identity);
            }
        }