public static Stream ListSitePublishingProfileXml(this IWebAppsOperations webApp,
                                                   string resourceGroupName,
                                                   string name,
                                                   CsmPublishingProfileOptions publishingProfileOptions)
 {
     return(webApp.ListPublishingProfileXmlWithSecrets(resourceGroupName, name, publishingProfileOptions));
 }
        public string ResetWebAppPublishingCredentials(string resourceGroupName, string webSiteName, string slotName)
        {
            string qualifiedSiteName;

            if (CmdletHelpers.ShouldUseDeploymentSlot(webSiteName, slotName, out qualifiedSiteName))
            {
                WrappedWebsitesClient.WebApps().GenerateNewSitePublishingPasswordSlot(resourceGroupName, webSiteName,
                                                                                      slotName);
            }
            else
            {
                WrappedWebsitesClient.WebApps().GenerateNewSitePublishingPassword(resourceGroupName, webSiteName);
            }

            var options = new CsmPublishingProfileOptions
            {
                Format = "WebDeploy"
            };

            var publishingXml = (CmdletHelpers.ShouldUseDeploymentSlot(webSiteName, slotName, out qualifiedSiteName) ?
                                 WrappedWebsitesClient.WebApps().ListSitePublishingProfileXmlSlot(resourceGroupName, webSiteName, options, slotName) :
                                 WrappedWebsitesClient.WebApps().ListSitePublishingProfileXml(resourceGroupName, webSiteName, options));
            var doc     = XDocument.Load(publishingXml, LoadOptions.None);
            var profile = doc.Root == null ? null : doc.Root.Element("publishData") == null ? null : doc.Root.Element("publishData").Elements("publishProfile")
                          .Single(p => p.Attribute("publishMethod").Value == "MSDeploy");

            return(profile == null ? null : profile.Attribute("userPWD").Value);
        }
        public static async Task <PublishingProfile> GetPublishingProfile(TargetSite targetSite,
                                                                          ServicePrincipalAccount account)
        {
            string mgmtEndpoint = account.ResourceManagementEndpointBaseUri;
            var    token        = new TokenCredentials(await Auth.GetAuthTokenAsync(account));

            var azureCredentials = new AzureCredentials(
                token,
                token,
                account.TenantId,
                new AzureKnownEnvironment(account.AzureEnvironment).AsAzureSDKEnvironment())
                                   .WithDefaultSubscription(account.SubscriptionNumber);

            var restClient = RestClient
                             .Configure()
                             .WithBaseUri(mgmtEndpoint)
                             .WithEnvironment(new AzureKnownEnvironment(account.AzureEnvironment).AsAzureSDKEnvironment())
                             .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                             .WithCredentials(azureCredentials)
                             .Build();

            var webAppClient = new WebSiteManagementClient(restClient)
            {
                SubscriptionId = account.SubscriptionNumber
            };

            var options = new CsmPublishingProfileOptions {
                Format = PublishingProfileFormat.WebDeploy
            };

            await webAppClient.WebApps.GetWithHttpMessagesAsync(targetSite.ResourceGroupName, targetSite.Site);

            using var publishProfileStream = targetSite.HasSlot
                ? await webAppClient.WebApps.ListPublishingProfileXmlWithSecretsSlotAsync(targetSite.ResourceGroupName,
                                                                                          targetSite.Site, options, targetSite.Slot)
                : await webAppClient.WebApps.ListPublishingProfileXmlWithSecretsAsync(targetSite.ResourceGroupName,
                                                                                      targetSite.Site,
                                                                                      options);

            using var streamReader = new StreamReader(publishProfileStream);
            var document = XDocument.Parse(await streamReader.ReadToEndAsync());

            var profile = (from el in document.Descendants("publishProfile")
                           where string.Compare(el.Attribute("publishMethod")?.Value, "MSDeploy",
                                                StringComparison.OrdinalIgnoreCase) == 0
                           select new PublishingProfile
            {
                PublishUrl = $"https://{el.Attribute("publishUrl")?.Value}",
                Username = el.Attribute("userName")?.Value,
                Password = el.Attribute("userPWD")?.Value,
                Site = el.Attribute("msdeploySite")?.Value
            }).FirstOrDefault();

            if (profile == null)
            {
                throw new Exception("Failed to retrieve publishing profile.");
            }

            return(profile);
        }
Пример #4
0
        public string GetWebAppPublishingProfile(string resourceGroupName, string webSiteName, string slotName, string outputFile, string format)
        {
            string qualifiedSiteName;
            var    options = new CsmPublishingProfileOptions
            {
                Format = format
            };

            var publishingXml = (CmdletHelpers.ShouldUseDeploymentSlot(webSiteName, slotName, out qualifiedSiteName) ? WrappedWebsitesClient.Sites.ListSitePublishingProfileXmlSlot(resourceGroupName, webSiteName, options, slotName) : WrappedWebsitesClient.Sites.ListSitePublishingProfileXml(resourceGroupName, webSiteName, options));
            var doc           = XDocument.Load(publishingXml, LoadOptions.None);

            doc.Save(outputFile, SaveOptions.OmitDuplicateNamespaces);
            return(doc.ToString());
        }
Пример #5
0
        public string GetWebAppPublishingProfile(string resourceGroupName, string webSiteName, string slotName, string outputFile, string format, bool?includeDRTEndpoint)
        {
            string qualifiedSiteName;
            var    options = new CsmPublishingProfileOptions
            {
                Format = format,
                IncludeDisasterRecoveryEndpoints = includeDRTEndpoint
            };

            var publishingXml = (CmdletHelpers.ShouldUseDeploymentSlot(webSiteName, slotName, out qualifiedSiteName) ?
                                 WrappedWebsitesClient.WebApps().ListPublishingProfileXmlWithSecretsSlot(resourceGroupName, webSiteName, options, slotName) :
                                 WrappedWebsitesClient.WebApps().ListPublishingProfileXmlWithSecrets(resourceGroupName, webSiteName, options));
            var doc = XDocument.Load(publishingXml, LoadOptions.None);

            if (outputFile != null)
            {
                doc.Save(outputFile, SaveOptions.OmitDuplicateNamespaces);
            }
            return(doc.ToString());
        }
Пример #6
0
        public string ResetWebAppPublishingCredentials(string resourceGroupName, string webSiteName, string slotName)
        {
            string qualifiedSiteName;
            if(CmdletHelpers.ShouldUseDeploymentSlot(webSiteName, slotName, out qualifiedSiteName))
            {
                WrappedWebsitesClient.Sites.GenerateNewSitePublishingPasswordSlot(resourceGroupName, webSiteName,
                    slotName);
            }
            else
            {
                WrappedWebsitesClient.Sites.GenerateNewSitePublishingPassword(resourceGroupName, webSiteName);
            }

            var options = new CsmPublishingProfileOptions
            {
                Format = "WebDeploy"
            };

            var publishingXml = (CmdletHelpers.ShouldUseDeploymentSlot(webSiteName, slotName, out qualifiedSiteName) ? WrappedWebsitesClient.Sites.ListSitePublishingProfileXmlSlot(resourceGroupName, webSiteName, options, slotName) : WrappedWebsitesClient.Sites.ListSitePublishingProfileXml(resourceGroupName, webSiteName, options));
            var doc = XDocument.Load(publishingXml, LoadOptions.None);
            var profile = doc.Root == null ? null : doc.Root.Element("publishData") == null ? null : doc.Root.Element("publishData").Elements("publishProfile")
                .Single(p => p.Attribute("publishMethod").Value == "MSDeploy");
            return profile == null ? null: profile.Attribute("userPWD").Value;
        }
Пример #7
0
        public string GetWebAppPublishingProfile(string resourceGroupName, string webSiteName, string slotName, string outputFile, string format)
        {
            string qualifiedSiteName;
            var options = new CsmPublishingProfileOptions
            {
                Format = format
            };

            var publishingXml = (CmdletHelpers.ShouldUseDeploymentSlot(webSiteName, slotName, out qualifiedSiteName) ? WrappedWebsitesClient.Sites.ListSitePublishingProfileXmlSlot(resourceGroupName, webSiteName, options, slotName) : WrappedWebsitesClient.Sites.ListSitePublishingProfileXml(resourceGroupName, webSiteName, options));
             var doc = XDocument.Load(publishingXml, LoadOptions.None);
             doc.Save(outputFile, SaveOptions.OmitDuplicateNamespaces);
            return doc.ToString();
        }