The core infrastructure backend (API, database, Docker, etc).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
1.2 KiB

using Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationConnections.Interfaces;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationConnections;
public class ValidateBillingSyncKeyCommand : IValidateBillingSyncKeyCommand
{
private readonly IOrganizationApiKeyRepository _apiKeyRepository;
public ValidateBillingSyncKeyCommand(
IOrganizationApiKeyRepository organizationApiKeyRepository)
{
_apiKeyRepository = organizationApiKeyRepository;
}
public async Task<bool> ValidateBillingSyncKeyAsync(Organization organization, string billingSyncKey)
{
if (organization == null)
{
throw new BadRequestException("Invalid organization");
}
if (string.IsNullOrWhiteSpace(billingSyncKey))
{
return false;
}
var orgApiKey = (await _apiKeyRepository.GetManyByOrganizationIdTypeAsync(organization.Id, Core.Enums.OrganizationApiKeyType.BillingSync)).FirstOrDefault();
if (string.Equals(orgApiKey.ApiKey, billingSyncKey))
{
return true;
}
return false;
}
}