mirror of
https://github.com/bitwarden/server.git
synced 2025-01-02 18:47:44 +01:00
QA-689/BEEEP-public-api-GET-subscription-details (#5041)
* added GET operation to org subscription endpoint * adding back removed using statement * addressing unused import and lint warnings * whitespace lint fix * successful local format * add NotSelfHostOnly attribute * add endpoint summary and return details
This commit is contained in:
parent
b907935eda
commit
ecbfc05683
@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using Bit.Api.Billing.Public.Models;
|
||||
using Bit.Api.Models.Public.Response;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationSubscriptions.Interface;
|
||||
@ -35,6 +36,49 @@ public class OrganizationController : Controller
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the subscription details for the current organization.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// Returns an object containing the subscription details if successful.
|
||||
/// </returns>
|
||||
[HttpGet("subscription")]
|
||||
[SelfHosted(NotSelfHostedOnly = true)]
|
||||
[ProducesResponseType(typeof(OrganizationSubscriptionDetailsResponseModel), (int)HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> GetSubscriptionAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var organizationId = _currentContext.OrganizationId.Value;
|
||||
var organization = await _organizationRepository.GetByIdAsync(organizationId);
|
||||
|
||||
var subscriptionDetails = new OrganizationSubscriptionDetailsResponseModel
|
||||
{
|
||||
PasswordManager = new PasswordManagerSubscriptionDetails
|
||||
{
|
||||
Seats = organization.Seats,
|
||||
MaxAutoScaleSeats = organization.MaxAutoscaleSeats,
|
||||
Storage = organization.MaxStorageGb
|
||||
},
|
||||
SecretsManager = new SecretsManagerSubscriptionDetails
|
||||
{
|
||||
Seats = organization.SmSeats,
|
||||
MaxAutoScaleSeats = organization.MaxAutoscaleSmSeats,
|
||||
ServiceAccounts = organization.SmServiceAccounts,
|
||||
MaxAutoScaleServiceAccounts = organization.MaxAutoscaleSmServiceAccounts
|
||||
}
|
||||
};
|
||||
|
||||
return Ok(subscriptionDetails);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Unhandled error while retrieving the subscription details");
|
||||
return StatusCode(500, new { Message = "An error occurred while retrieving the subscription details." });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the organization's current subscription for Password Manager and/or Secrets Manager.
|
||||
/// </summary>
|
||||
|
@ -0,0 +1,32 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.Billing.Public.Models;
|
||||
|
||||
public class OrganizationSubscriptionDetailsResponseModel : IValidatableObject
|
||||
{
|
||||
public PasswordManagerSubscriptionDetails PasswordManager { get; set; }
|
||||
public SecretsManagerSubscriptionDetails SecretsManager { get; set; }
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (PasswordManager == null && SecretsManager == null)
|
||||
{
|
||||
yield return new ValidationResult("At least one of PasswordManager or SecretsManager must be provided.");
|
||||
}
|
||||
|
||||
yield return ValidationResult.Success;
|
||||
}
|
||||
}
|
||||
public class PasswordManagerSubscriptionDetails
|
||||
{
|
||||
public int? Seats { get; set; }
|
||||
public int? MaxAutoScaleSeats { get; set; }
|
||||
public short? Storage { get; set; }
|
||||
}
|
||||
|
||||
public class SecretsManagerSubscriptionDetails
|
||||
{
|
||||
public int? Seats { get; set; }
|
||||
public int? MaxAutoScaleSeats { get; set; }
|
||||
public int? ServiceAccounts { get; set; }
|
||||
public int? MaxAutoScaleServiceAccounts { get; set; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user