示例#1
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ObjectParameterSet, StringComparison.OrdinalIgnoreCase))
            {
                EndpointName      = InputObject.EndpointName;
                ProfileName       = InputObject.ProfileName;
                ResourceGroupName = InputObject.ResourceGroupName;
                CustomDomainName  = InputObject.Name;
            }

            if (ParameterSetName.Equals(ResourceIdParameterSet, StringComparison.OrdinalIgnoreCase))
            {
                var parsedResourceId = new ResourceIdentifier(ResourceId);
                ResourceGroupName = parsedResourceId.ResourceGroupName;
                ProfileName       = parsedResourceId.GetProfileName();
                EndpointName      = parsedResourceId.GetEndpointName();
                CustomDomainName  = parsedResourceId.ResourceName;
            }

            var existingCustomDomain = CdnManagementClient.CustomDomains
                                       .ListByEndpoint(ResourceGroupName, ProfileName, EndpointName)
                                       .FirstOrDefault(cd => cd.Name.ToLower() == CustomDomainName.ToLower());

            if (existingCustomDomain == null)
            {
                throw new PSArgumentException(string.Format(Resources.Error_NonExistingCustomDomain,
                                                            CustomDomainName,
                                                            EndpointName,
                                                            ProfileName,
                                                            ResourceGroupName));
            }

            var parameters = new Management.Cdn.Models.CdnManagedHttpsParameters
            {
                ProtocolType = Management.Cdn.Models.ProtocolType.IPBased,
                CertificateSourceParameters = new Management.Cdn.Models.CdnCertificateSourceParameters {
                    CertificateType = "Shared"
                }
            };

            ConfirmAction(MyInvocation.InvocationName,
                          String.Format("{0} ({1})", existingCustomDomain.Name, existingCustomDomain.HostName),
                          () => CdnManagementClient.CustomDomains.EnableCustomHttps(
                              ResourceGroupName,
                              ProfileName,
                              EndpointName,
                              CustomDomainName,
                              parameters
                              ));

            if (PassThru)
            {
                WriteObject(true);
            }
        }
示例#2
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ObjectParameterSet, StringComparison.OrdinalIgnoreCase))
            {
                EndpointName      = InputObject.EndpointName;
                ProfileName       = InputObject.ProfileName;
                ResourceGroupName = InputObject.ResourceGroupName;
                CustomDomainName  = InputObject.Name;
            }

            if (ParameterSetName.Equals(ResourceIdParameterSet, StringComparison.OrdinalIgnoreCase))
            {
                var parsedResourceId = new ResourceIdentifier(ResourceId);
                ResourceGroupName = parsedResourceId.ResourceGroupName;
                ProfileName       = parsedResourceId.GetProfileName();
                EndpointName      = parsedResourceId.GetEndpointName();
                CustomDomainName  = parsedResourceId.ResourceName;
            }

            var existingCustomDomain = CdnManagementClient.CustomDomains
                                       .ListByEndpoint(ResourceGroupName, ProfileName, EndpointName)
                                       .FirstOrDefault(cd => cd.Name.ToLower() == CustomDomainName.ToLower());

            if (existingCustomDomain == null)
            {
                throw new PSArgumentException(string.Format(Resources.Error_NonExistingCustomDomain,
                                                            CustomDomainName,
                                                            EndpointName,
                                                            ProfileName,
                                                            ResourceGroupName));
            }

            // Get the Profile so we can lookup its Sku.
            var profile = CdnManagementClient.Profiles.Get(ResourceGroupName, ProfileName);

            // Setup the request parameters according to the profile Sku.
            Management.Cdn.Models.CdnManagedHttpsParameters parameters;
            switch (profile.Sku.Name)
            {
            case Management.Cdn.Models.SkuName.StandardMicrosoft:
                // Microsoft
                parameters = new Management.Cdn.Models.CdnManagedHttpsParameters
                {
                    ProtocolType = Management.Cdn.Models.ProtocolType.ServerNameIndication,
                    CertificateSourceParameters = new Management.Cdn.Models.CdnCertificateSourceParameters {
                        CertificateType = "Dedicated"
                    }
                };
                break;

            case Management.Cdn.Models.SkuName.StandardAkamai:
                // Akamai
                parameters = new Management.Cdn.Models.CdnManagedHttpsParameters
                {
                    ProtocolType = Management.Cdn.Models.ProtocolType.ServerNameIndication,
                    CertificateSourceParameters = new Management.Cdn.Models.CdnCertificateSourceParameters {
                        CertificateType = "Shared"
                    }
                };

                break;

            default:
                // Verizon
                parameters = new Management.Cdn.Models.CdnManagedHttpsParameters
                {
                    ProtocolType = Management.Cdn.Models.ProtocolType.IPBased,
                    CertificateSourceParameters = new Management.Cdn.Models.CdnCertificateSourceParameters {
                        CertificateType = "Shared"
                    }
                };
                break;
            }

            ConfirmAction(MyInvocation.InvocationName,
                          String.Format("{0} ({1})", existingCustomDomain.Name, existingCustomDomain.HostName),
                          () => CdnManagementClient.CustomDomains.EnableCustomHttps(
                              ResourceGroupName,
                              ProfileName,
                              EndpointName,
                              CustomDomainName,
                              parameters
                              ));

            if (PassThru)
            {
                WriteObject(true);
            }
        }