示例#1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var webapp = new PSSite(WebsitesClient.GetWebApp(resourceGroupName, webAppName, slot));

            WriteObject(CmdletHelpers.GetHostNameSslStatesFromSiteResponse(webapp, Name));
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ConfirmAction(
                Force.IsPresent,
                string.Format(Properties.Resources.RemovingWebAppSSLBinding, Name),
                Properties.Resources.RemoveWebAppSSLBinding,
                Name,
                () =>
            {
                var webapp            = WebsitesClient.GetWebApp(resourceGroupName, webAppName, slot);
                var hostNameSslStates = CmdletHelpers.GetHostNameSslStatesFromSiteResponse(webapp, Name).ToList();
                if (hostNameSslStates.Count > 0)
                {
                    var thumbprint = hostNameSslStates[0].Thumbprint;
                    WebsitesClient.UpdateHostNameSslState(resourceGroupName, webAppName, slot, webapp.Location, Name, SslState.Disabled, null);

                    if (!DeleteCertificate.HasValue || DeleteCertificate.Value)
                    {
                        var certificateResourceGroup = CmdletHelpers.GetResourceGroupFromResourceId(webapp.ServerFarmId);
                        var certificates             = CmdletHelpers.GetCertificates(this.ResourcesClient, this.WebsitesClient, certificateResourceGroup, thumbprint);
                        if (certificates.Length > 0)
                        {
                            try
                            {
                                WebsitesClient.RemoveCertificate(certificateResourceGroup, certificates[0].Name);
                            }
                            catch (CloudException e)
                            {
                                // This exception is thrown when there are other Ssl bindings using this certificate. Let's swallow it and continue.
                                if (e.Response.StatusCode != HttpStatusCode.Conflict)
                                {
                                    throw;
                                }
                            }
                        }
                    }
                }
            });
        }
示例#3
0
        protected override void ProcessRecord()
        {
            if (ParameterSetName != ParameterSet1Name &&
                ParameterSetName != ParameterSet2Name &&
                ParameterSetName != ParameterSet3Name &&
                ParameterSetName != ParameterSet4Name)
            {
                throw new ValidationMetadataException("Please input web app and certificate.");
            }

            if (ParameterSetName == ParameterSet3Name ||
                ParameterSetName == ParameterSet4Name)
            {
                CmdletHelpers.ExtractWebAppPropertiesFromWebApp(WebApp, out resourceGroupName, out webAppName, out slot);
            }
            else
            {
                resourceGroupName = ResourceGroupName;
                webAppName        = WebAppName;
                slot = Slot;
            }

            string thumbPrint = null;
            var    webapp     = WebsitesClient.GetWebApp(resourceGroupName, webAppName, slot);

            switch (ParameterSetName)
            {
            case ParameterSet1Name:
            case ParameterSet3Name:
                var certificateBytes   = File.ReadAllBytes(CertificateFilePath);
                var certificateDetails = new X509Certificate2(certificateBytes, CertificatePassword);

                var certificateName = GenerateCertName(certificateDetails.Thumbprint, webapp.HostingEnvironmentProfile != null ? webapp.HostingEnvironmentProfile.Name : null, webapp.Location, resourceGroupName);
                var certificate     = new Certificate
                {
                    PfxBlob  = Convert.ToBase64String(certificateBytes),
                    Password = CertificatePassword,
                    Location = webapp.Location
                };

                if (webapp.HostingEnvironmentProfile != null)
                {
                    certificate.HostingEnvironmentProfile = webapp.HostingEnvironmentProfile;
                }

                var certificateResourceGroup = CmdletHelpers.GetResourceGroupFromResourceId(webapp.ServerFarmId);
                try
                {
                    WebsitesClient.CreateCertificate(certificateResourceGroup, certificateName, certificate);
                }
                catch (CloudException e)
                {
                    // This exception is thrown when certificate already exists. Let's swallow it and continue.
                    if (e.Response.StatusCode != HttpStatusCode.Conflict)
                    {
                        throw;
                    }
                }

                thumbPrint = certificateDetails.Thumbprint;
                break;

            case ParameterSet2Name:
            case ParameterSet4Name:
                thumbPrint = Thumbprint;
                break;
            }

            WriteObject(CmdletHelpers.GetHostNameSslStatesFromSiteResponse(
                            WebsitesClient.UpdateHostNameSslState(
                                resourceGroupName,
                                webAppName,
                                slot,
                                webapp.Location,
                                Name,
                                SslState.HasValue ? SslState.Value : Management.WebSites.Models.SslState.SniEnabled,
                                thumbPrint),
                            Name));
        }