Skip to content

Commit

Permalink
Merge pull request #159 from OctopusDeploy/bug-3403-list-deployments
Browse files Browse the repository at this point in the history
check multi-tenant feature is on before trying to load them
  • Loading branch information
NickJosevski authored Apr 12, 2017
2 parents 8f10799 + 375ea5d commit 9cdc6f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions source/Octo.Tests/Commands/ListDeploymentsCommandFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public async Task ShouldGetListOfDeployments()
},
}, new LinkCollection());

Repository.FeaturesConfiguration.GetFeaturesConfiguration()
.ReturnsForAnyArgs(new FeaturesConfigurationResource { });

Repository.Deployments
.When(
x =>
Expand Down
19 changes: 13 additions & 6 deletions source/Octo/Commands/ListDeploymentsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
using Octopus.Cli.Util;
using Octopus.Client;
using Octopus.Client.Model;
using Octopus.Client.Repositories.Async;
using Serilog;

namespace Octopus.Cli.Commands
{
[Command("list-deployments", Description = "List a number of releases deployments by project or by environment")]
[Command("list-deployments", Description = "List a number of deployments by project, environment or by tenant")]
public class ListDeploymentsCommand : ApiCommand
{
const int DefaultReturnAmount = 30;
Expand All @@ -25,9 +26,9 @@ public ListDeploymentsCommand(IOctopusAsyncRepositoryFactory repositoryFactory,
: base(clientFactory, repositoryFactory, log, fileSystem)
{
var options = Options.For("Listing");
options.Add("project=", "Name of a project to filter by. Can be specified many times.", v => projects.Add(v));
options.Add("environment=", "Name of an environment to filter by. Can be specified many times.", v => environments.Add(v));
options.Add("tenant=", "Name of a tenant to filter by. Can be specified many times.", v => tenants.Add(v));
options.Add("project=", "[Optional] Name of a project to filter by. Can be specified many times.", v => projects.Add(v));
options.Add("environment=", "[Optional] Name of an environment to filter by. Can be specified many times.", v => environments.Add(v));
options.Add("tenant=", "[Optional] Name of a tenant to filter by. Can be specified many times.", v => tenants.Add(v));
options.Add("number=", $"[Optional] number of results to return, default is {DefaultReturnAmount}", v => numberOfResults = int.Parse(v));
}

Expand All @@ -39,8 +40,14 @@ protected override async Task Execute()
var environmentsById = await LoadEnvironments();
var environmentsFilter = environmentsById.Keys.ToArray();

var tenantsById = await LoadTenants();
var tenantsFilter = tenants.Any() ? tenantsById.Keys.ToArray() : new string[0];
var features = await Repository.FeaturesConfiguration.GetFeaturesConfiguration();
var tenantsFilter = new string[0];
IDictionary<string, string> tenantsById = new Dictionary<string, string>();
if (features.IsMultiTenancyEnabled)
{
tenantsById = await LoadTenants();
tenantsFilter = tenants.Any() ? tenantsById.Keys.ToArray() : new string[0];
}

Log.Debug("Loading deployments...");
var deploymentResources = new List<DeploymentResource>();
Expand Down

0 comments on commit 9cdc6f8

Please sign in to comment.