From 3a6b17bf1904224d7dd7e156ce76b8f0109fd691 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Tue, 11 Jul 2023 19:08:57 +1000 Subject: [PATCH] [AC-1504] Allow SM max autoscale limits to be disabled (#3085) --- ...tsManagerSubscriptionUpdateRequestModel.cs | 11 +++----- ...UpdateSecretsManagerSubscriptionCommand.cs | 28 +++++++++++++------ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/Api/Models/Request/Organizations/SecretsManagerSubscriptionUpdateRequestModel.cs b/src/Api/Models/Request/Organizations/SecretsManagerSubscriptionUpdateRequestModel.cs index 1bd3cde33d..31f071953a 100644 --- a/src/Api/Models/Request/Organizations/SecretsManagerSubscriptionUpdateRequestModel.cs +++ b/src/Api/Models/Request/Organizations/SecretsManagerSubscriptionUpdateRequestModel.cs @@ -17,11 +17,6 @@ public class SecretsManagerSubscriptionUpdateRequestModel { var newTotalSeats = organization.SmSeats.GetValueOrDefault() + SeatAdjustment; var newTotalServiceAccounts = organization.SmServiceAccounts.GetValueOrDefault() + ServiceAccountAdjustment; - var autoscaleSeats = MaxAutoscaleSeats.HasValue && MaxAutoscaleSeats != - organization.MaxAutoscaleSmSeats.GetValueOrDefault(); - var autoscaleServiceAccounts = MaxAutoscaleServiceAccounts.HasValue && - MaxAutoscaleServiceAccounts != - organization.MaxAutoscaleSmServiceAccounts.GetValueOrDefault(); var orgUpdate = new SecretsManagerSubscriptionUpdate { @@ -39,8 +34,10 @@ public class SecretsManagerSubscriptionUpdateRequestModel MaxAutoscaleSmServiceAccounts = MaxAutoscaleServiceAccounts, - MaxAutoscaleSmSeatsChanged = autoscaleSeats, - MaxAutoscaleSmServiceAccountsChanged = autoscaleServiceAccounts + MaxAutoscaleSmSeatsChanged = + MaxAutoscaleSeats.GetValueOrDefault() != organization.MaxAutoscaleSmSeats.GetValueOrDefault(), + MaxAutoscaleSmServiceAccountsChanged = + MaxAutoscaleServiceAccounts.GetValueOrDefault() != organization.MaxAutoscaleSmServiceAccounts.GetValueOrDefault() }; return orgUpdate; diff --git a/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpdateSecretsManagerSubscriptionCommand.cs b/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpdateSecretsManagerSubscriptionCommand.cs index a57c874da7..87db6c83d8 100644 --- a/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpdateSecretsManagerSubscriptionCommand.cs +++ b/src/Core/OrganizationFeatures/OrganizationSubscriptions/UpdateSecretsManagerSubscriptionCommand.cs @@ -61,12 +61,12 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs if (update.MaxAutoscaleSmSeatsChanged) { - ValidateMaxAutoscaleSmSeatsUpdateAsync(organization, update.MaxAutoscaleSmSeats.GetValueOrDefault(), plan); + ValidateMaxAutoscaleSmSeatsUpdateAsync(organization, update.MaxAutoscaleSmSeats, plan); } if (update.MaxAutoscaleSmServiceAccountsChanged) { - ValidateMaxAutoscaleSmServiceAccountUpdate(organization, update.MaxAutoscaleSmServiceAccounts.GetValueOrDefault(), plan); + ValidateMaxAutoscaleSmServiceAccountUpdate(organization, update.MaxAutoscaleSmServiceAccounts, plan); } await FinalizeSubscriptionAdjustmentAsync(organization, plan, update); @@ -299,14 +299,20 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs } } - private void ValidateMaxAutoscaleSmSeatsUpdateAsync(Organization organization, int maxAutoscaleSeats, Plan plan) + private void ValidateMaxAutoscaleSmSeatsUpdateAsync(Organization organization, int? maxAutoscaleSeats, Plan plan) { - if (organization.SmSeats.HasValue && maxAutoscaleSeats < organization.SmSeats.Value) + if (!maxAutoscaleSeats.HasValue) + { + // autoscale limit has been turned off, no validation required + return; + } + + if (organization.SmSeats.HasValue && maxAutoscaleSeats.Value < organization.SmSeats.Value) { throw new BadRequestException($"Cannot set max Secrets Manager seat autoscaling below current Secrets Manager seat count."); } - if (plan.MaxUsers.HasValue && maxAutoscaleSeats > plan.MaxUsers) + if (plan.MaxUsers.HasValue && maxAutoscaleSeats.Value > plan.MaxUsers) { throw new BadRequestException(string.Concat( $"Your plan has a Secrets Manager seat limit of {plan.MaxUsers}, ", @@ -320,9 +326,15 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs } } - private void ValidateMaxAutoscaleSmServiceAccountUpdate(Organization organization, int maxAutoscaleServiceAccounts, Plan plan) + private void ValidateMaxAutoscaleSmServiceAccountUpdate(Organization organization, int? maxAutoscaleServiceAccounts, Plan plan) { - if (organization.SmServiceAccounts.HasValue && maxAutoscaleServiceAccounts < organization.SmServiceAccounts.Value) + if (!maxAutoscaleServiceAccounts.HasValue) + { + // autoscale limit has been turned off, no validation required + return; + } + + if (organization.SmServiceAccounts.HasValue && maxAutoscaleServiceAccounts.Value < organization.SmServiceAccounts.Value) { throw new BadRequestException( $"Cannot set max Service Accounts autoscaling below current Service Accounts count."); @@ -333,7 +345,7 @@ public class UpdateSecretsManagerSubscriptionCommand : IUpdateSecretsManagerSubs throw new BadRequestException("Your plan does not allow Service Accounts autoscaling."); } - if (plan.MaxServiceAccounts.HasValue && maxAutoscaleServiceAccounts > plan.MaxServiceAccounts) + if (plan.MaxServiceAccounts.HasValue && maxAutoscaleServiceAccounts.Value > plan.MaxServiceAccounts) { throw new BadRequestException(string.Concat( $"Your plan has a Service Accounts limit of {plan.MaxServiceAccounts}, ",