From 375ea5d7be2126378de5d281ff5c9c2379b7d026 Mon Sep 17 00:00:00 2001 From: Nick Josevski Date: Wed, 12 Apr 2017 14:07:01 +1000 Subject: [PATCH] check multi-tenant feature is on before trying to load them --- .../Commands/ListDeploymentsCommandFixture.cs | 3 +++ .../Octo/Commands/ListDeploymentsCommand.cs | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/source/Octo.Tests/Commands/ListDeploymentsCommandFixture.cs b/source/Octo.Tests/Commands/ListDeploymentsCommandFixture.cs index bc943ab24..b23edf0f9 100644 --- a/source/Octo.Tests/Commands/ListDeploymentsCommandFixture.cs +++ b/source/Octo.Tests/Commands/ListDeploymentsCommandFixture.cs @@ -42,6 +42,9 @@ public async Task ShouldGetListOfDeployments() }, }, new LinkCollection()); + Repository.FeaturesConfiguration.GetFeaturesConfiguration() + .ReturnsForAnyArgs(new FeaturesConfigurationResource { }); + Repository.Deployments .When( x => diff --git a/source/Octo/Commands/ListDeploymentsCommand.cs b/source/Octo/Commands/ListDeploymentsCommand.cs index a7779d0e8..fb701b41e 100644 --- a/source/Octo/Commands/ListDeploymentsCommand.cs +++ b/source/Octo/Commands/ListDeploymentsCommand.cs @@ -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; @@ -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)); } @@ -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 tenantsById = new Dictionary(); + if (features.IsMultiTenancyEnabled) + { + tenantsById = await LoadTenants(); + tenantsFilter = tenants.Any() ? tenantsById.Keys.ToArray() : new string[0]; + } Log.Debug("Loading deployments..."); var deploymentResources = new List();