Skip to content

Commit

Permalink
Merge pull request #110 from OctopusDeploy/bug-azure-ase
Browse files Browse the repository at this point in the history
Filter Azure Web Apps by ResourceGroupName
  • Loading branch information
slewis74 authored Jul 15, 2016
2 parents e13a5a3 + 8626e83 commit 19911b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using Calamari.Azure.Integration.Websites.Publishing;
using Calamari.Commands.Support;
Expand All @@ -18,9 +17,13 @@ public void Install(RunningDeployment deployment)
{
var variables = deployment.Variables;
var subscriptionId = variables.Get(SpecialVariables.Action.Azure.SubscriptionId);
var resourceGroupName = variables.Get(SpecialVariables.Action.Azure.ResourceGroupName, string.Empty);
var siteName = variables.Get(SpecialVariables.Action.Azure.WebAppName);

Log.Info("Deploying to Azure WebApp '{0}' using subscription-id '{1}'", siteName, subscriptionId);
Log.Info("Deploying to Azure WebApp '{0}'{1}, using subscription-id '{2}'",
siteName,
string.IsNullOrEmpty(resourceGroupName) ? string.Empty : $" in Resource Group {resourceGroupName}",
subscriptionId);

var publishProfile = GetPublishProfile(variables);

Expand Down Expand Up @@ -71,7 +74,9 @@ private static SitePublishProfile GetPublishProfile(VariableDictionary variables
switch (accountType)
{
case AzureAccountTypes.ServicePrincipalAccountType:
return ResourceManagerPublishProfileProvider.GetPublishProperties(subscriptionId, siteName,
return ResourceManagerPublishProfileProvider.GetPublishProperties(subscriptionId,
variables.Get(SpecialVariables.Action.Azure.ResourceGroupName, string.Empty),
siteName,
variables.Get(SpecialVariables.Action.Azure.TenantId),
variables.Get(SpecialVariables.Action.Azure.ClientId),
variables.Get(SpecialVariables.Action.Azure.Password));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ namespace Calamari.Azure.Integration.Websites.Publishing
{
public class ResourceManagerPublishProfileProvider
{
public static SitePublishProfile GetPublishProperties(string subscriptionId, string siteName, string tenantId, string applicationId, string password)
public static SitePublishProfile GetPublishProperties(string subscriptionId, string resourceGroupName, string siteName, string tenantId, string applicationId, string password)
{
var token = ServicePrincipal.GetAuthorizationToken(tenantId, applicationId, password);


using (var resourcesClient = new ResourceManagementClient(new TokenCloudCredentials(subscriptionId, token)))
using (var webSiteClient = new WebSiteManagementClient(new TokenCredentials(token)) { SubscriptionId = subscriptionId})
{
// Because we only know the site name, we need to search the ResourceGroups to find it
var resourceGroups = resourcesClient.ResourceGroups.List(new ResourceGroupListParameters()).ResourceGroups.Select(rg => rg.Name).ToList();
// We may need to search all ResourceGroups, if one isn't specified. New Step template will always provide the Resource Group, it is currently treated as optional here
// for backward compatibility.
var resourceGroups = resourcesClient.ResourceGroups.List(new ResourceGroupListParameters()).ResourceGroups.Where(rg => string.IsNullOrWhiteSpace(resourceGroupName) || string.Equals(rg.Name, resourceGroupName, StringComparison.InvariantCultureIgnoreCase)).Select(rg => rg.Name).ToList();

foreach (var resourceGroup in resourceGroups)
{
Expand Down

0 comments on commit 19911b3

Please sign in to comment.