mirror of
https://github.com/bitwarden/server
synced 2026-01-03 09:03:44 +00:00
[PM-12607] Move key rotation & validators to km ownership (#4941)
* Move key rotation & validators to km ownership * Fix build errors * Fix build errors * Fix import ordering * Update validator namespace * Move key rotation data to km ownership * Fix linting * Fix namespaces * Fix namespace * Fix namespaces * Move rotateuserkeycommandtests to km ownership
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
using Bit.Api.Auth.Validators;
|
||||
using Bit.Api.Vault.Models.Request;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Vault.Entities;
|
||||
using Bit.Core.Vault.Repositories;
|
||||
|
||||
namespace Bit.Api.Vault.Validators;
|
||||
|
||||
public class CipherRotationValidator : IRotationValidator<IEnumerable<CipherWithIdRequestModel>, IEnumerable<Cipher>>
|
||||
{
|
||||
private readonly ICipherRepository _cipherRepository;
|
||||
|
||||
public CipherRotationValidator(ICipherRepository cipherRepository)
|
||||
{
|
||||
_cipherRepository = cipherRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Cipher>> ValidateAsync(User user, IEnumerable<CipherWithIdRequestModel> ciphers)
|
||||
{
|
||||
var result = new List<Cipher>();
|
||||
|
||||
var existingCiphers = await _cipherRepository.GetManyByUserIdAsync(user.Id);
|
||||
if (existingCiphers == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var existingUserCiphers = existingCiphers.Where(c => c.OrganizationId == null);
|
||||
if (existingUserCiphers.Count() == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (var existing in existingUserCiphers)
|
||||
{
|
||||
var cipher = ciphers.FirstOrDefault(c => c.Id == existing.Id);
|
||||
if (cipher == null)
|
||||
{
|
||||
throw new BadRequestException("All existing ciphers must be included in the rotation.");
|
||||
}
|
||||
result.Add(cipher.ToCipher(existing));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
using Bit.Api.Auth.Validators;
|
||||
using Bit.Api.Vault.Models.Request;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Vault.Entities;
|
||||
using Bit.Core.Vault.Repositories;
|
||||
|
||||
namespace Bit.Api.Vault.Validators;
|
||||
|
||||
public class FolderRotationValidator : IRotationValidator<IEnumerable<FolderWithIdRequestModel>, IEnumerable<Folder>>
|
||||
{
|
||||
private readonly IFolderRepository _folderRepository;
|
||||
|
||||
public FolderRotationValidator(IFolderRepository folderRepository)
|
||||
{
|
||||
_folderRepository = folderRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Folder>> ValidateAsync(User user, IEnumerable<FolderWithIdRequestModel> folders)
|
||||
{
|
||||
var result = new List<Folder>();
|
||||
|
||||
var existingFolders = await _folderRepository.GetManyByUserIdAsync(user.Id);
|
||||
if (existingFolders == null || existingFolders.Count == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (var existing in existingFolders)
|
||||
{
|
||||
var folder = folders.FirstOrDefault(c => c.Id == existing.Id);
|
||||
if (folder == null)
|
||||
{
|
||||
throw new BadRequestException("All existing folders must be included in the rotation.");
|
||||
}
|
||||
result.Add(folder.ToFolder(existing));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user