1
0
mirror of https://github.com/bitwarden/server synced 2026-01-15 23:13:56 +00:00

[SG-841] Refactor GetOrganizationApiKeyCommand (#2436)

* Renamed and split up class to only query for an organization key

* Added a command class to create an organization api key

* Updated service registration and controller to include new changes

* Updated test cases to reflect refactor

* fixed lint issues

* Fixed PR comment
This commit is contained in:
Gbubemi Smith
2022-11-28 17:39:09 -07:00
committed by GitHub
parent 5bcacf785f
commit f74730dd2f
9 changed files with 97 additions and 55 deletions

View File

@@ -0,0 +1,30 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.OrganizationFeatures.OrganizationApiKeys.Interfaces;
using Bit.Core.Repositories;
namespace Bit.Core.OrganizationFeatures.OrganizationApiKeys;
public class GetOrganizationApiKeyQuery : IGetOrganizationApiKeyQuery
{
private readonly IOrganizationApiKeyRepository _organizationApiKeyRepository;
public GetOrganizationApiKeyQuery(IOrganizationApiKeyRepository organizationApiKeyRepository)
{
_organizationApiKeyRepository = organizationApiKeyRepository;
}
public async Task<OrganizationApiKey> GetOrganizationApiKeyAsync(Guid organizationId, OrganizationApiKeyType organizationApiKeyType)
{
if (!Enum.IsDefined(organizationApiKeyType))
{
throw new ArgumentOutOfRangeException(nameof(organizationApiKeyType), $"Invalid value for enum {nameof(OrganizationApiKeyType)}");
}
var apiKeys = await _organizationApiKeyRepository
.GetManyByOrganizationIdTypeAsync(organizationId, organizationApiKeyType);
// NOTE: Currently we only allow one type of api key per organization
return apiKeys.Single();
}
}