void ConfirmWebAppExists(AzureAccount certificateAccount, string resourceGroupName, string siteName) { log.Warn("Azure have announced they will be retiring Service Management API support on June 30th 2018. Please switch to using Service Principals for your Octopus Azure accounts https://g.octopushq.com/AzureServicePrincipalAccount"); using (var azureClient = certificateAccount.CreateWebSiteManagementClient(certificateStore)) { var response = azureClient.WebSpaces.List(); if (response.StatusCode != HttpStatusCode.OK) { throw new Exception("Azure returned HTTP status-code getting WebSpaces: " + response.StatusCode); } // Confirm the site exists. var matchingSite = response.WebSpaces .SelectMany(webSpace => { var webAppsResponse = azureClient.WebSpaces.ListWebSites( webSpace.Name, new WebSiteListParameters { PropertiesToInclude = new List <string> { "Name", "WebSpace" } }); if (webAppsResponse.StatusCode != HttpStatusCode.OK) { throw new Exception($"Azure returned HTTP status-code getting WebApps for the WebSpace '{webSpace}': {webAppsResponse.StatusCode}"); } return(webAppsResponse.WebSites.Where( x => string.Equals(x.Name, siteName, StringComparison.CurrentCultureIgnoreCase) && x.WebSpace.ToLower().Contains(resourceGroupName.ToLower()) )); }).FirstOrDefault(); if (matchingSite == null) { throw new Exception($"Could not find site {siteName} in resource group {resourceGroupName}, using Management Certificate with subscription {certificateAccount.SubscriptionNumber}"); } } }