mirror of
https://github.com/bitwarden/server
synced 2026-01-10 04:23:31 +00:00
[AC-1504] Allow SM max autoscale limits to be disabled (#3085)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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}, ",
|
||||
|
||||
Reference in New Issue
Block a user