1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 16:42:50 -05:00

[SM-460] Isolate SecretsManager files (#2616)

Move SecretsManager files to directories called SecretsManager and add CodeOwners
This commit is contained in:
Oscar Hinton
2023-01-24 19:57:28 +01:00
committed by GitHub
parent 4041d7f009
commit 59f5285c88
122 changed files with 449 additions and 419 deletions

View File

@ -1,6 +1,8 @@
using Bit.Core.Enums;
using Bit.Core.Repositories;
using Bit.Core.SecretsManager.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.SecretsManager.Repositories;
using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

View File

@ -1,16 +0,0 @@
using AutoMapper;
namespace Bit.Infrastructure.EntityFramework.Models;
public class ApiKey : Core.Entities.ApiKey
{
public virtual ServiceAccount ServiceAccount { get; set; }
}
public class ApiKeyMapperProfile : Profile
{
public ApiKeyMapperProfile()
{
CreateMap<Core.Entities.ApiKey, ApiKey>().ReverseMap();
}
}

View File

@ -1,6 +1,7 @@
using Bit.Core;
using Bit.Infrastructure.EntityFramework.Converters;
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

View File

@ -1,8 +1,8 @@
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.Configurations;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Configurations;
public class AccessPolicyEntityTypeConfiguration : IEntityTypeConfiguration<AccessPolicy>
{

View File

@ -1,8 +1,8 @@
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.Configurations;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Configurations;
public class ApiKeyEntityTypeConfiguration : IEntityTypeConfiguration<ApiKey>
{

View File

@ -1,8 +1,8 @@
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.Configurations;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Configurations;
public class ProjectEntityTypeConfiguration : IEntityTypeConfiguration<Project>
{

View File

@ -1,8 +1,8 @@
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.Configurations;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Configurations;
public class SecretEntityTypeConfiguration : IEntityTypeConfiguration<Secret>
{

View File

@ -1,7 +1,9 @@
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Configurations;
public class ServiceAccountEntityTypeConfiguration : IEntityTypeConfiguration<ServiceAccount>
{
public void Configure(EntityTypeBuilder<ServiceAccount> builder)

View File

@ -1,8 +1,9 @@
using AutoMapper;
using Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Models;
public class BaseAccessPolicy : Core.Entities.BaseAccessPolicy
public class BaseAccessPolicy : Core.SecretsManager.Entities.BaseAccessPolicy
{
public string Discriminator { get; set; }
}
@ -11,13 +12,13 @@ public class AccessPolicyMapperProfile : Profile
{
public AccessPolicyMapperProfile()
{
CreateMap<Core.Entities.UserProjectAccessPolicy, UserProjectAccessPolicy>().ReverseMap()
CreateMap<Core.SecretsManager.Entities.UserProjectAccessPolicy, UserProjectAccessPolicy>().ReverseMap()
.ForMember(dst => dst.User, opt => opt.MapFrom(src => src.OrganizationUser.User));
CreateMap<Core.Entities.UserServiceAccountAccessPolicy, UserServiceAccountAccessPolicy>().ReverseMap()
CreateMap<Core.SecretsManager.Entities.UserServiceAccountAccessPolicy, UserServiceAccountAccessPolicy>().ReverseMap()
.ForMember(dst => dst.User, opt => opt.MapFrom(src => src.OrganizationUser.User));
CreateMap<Core.Entities.GroupProjectAccessPolicy, GroupProjectAccessPolicy>().ReverseMap();
CreateMap<Core.Entities.GroupServiceAccountAccessPolicy, GroupServiceAccountAccessPolicy>().ReverseMap();
CreateMap<Core.Entities.ServiceAccountProjectAccessPolicy, ServiceAccountProjectAccessPolicy>().ReverseMap();
CreateMap<Core.SecretsManager.Entities.GroupProjectAccessPolicy, GroupProjectAccessPolicy>().ReverseMap();
CreateMap<Core.SecretsManager.Entities.GroupServiceAccountAccessPolicy, GroupServiceAccountAccessPolicy>().ReverseMap();
CreateMap<Core.SecretsManager.Entities.ServiceAccountProjectAccessPolicy, ServiceAccountProjectAccessPolicy>().ReverseMap();
}
}

View File

@ -0,0 +1,16 @@
using AutoMapper;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Models;
public class ApiKey : Core.SecretsManager.Entities.ApiKey
{
public virtual ServiceAccount ServiceAccount { get; set; }
}
public class ApiKeyMapperProfile : Profile
{
public ApiKeyMapperProfile()
{
CreateMap<Core.SecretsManager.Entities.ApiKey, ApiKey>().ReverseMap();
}
}

View File

@ -1,8 +1,9 @@
using AutoMapper;
using Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Models;
public class Project : Core.Entities.Project
public class Project : Core.SecretsManager.Entities.Project
{
public virtual new ICollection<Secret> Secrets { get; set; }
public virtual Organization Organization { get; set; }
@ -15,7 +16,7 @@ public class ProjectMapperProfile : Profile
{
public ProjectMapperProfile()
{
CreateMap<Core.Entities.Project, Project>()
CreateMap<Core.SecretsManager.Entities.Project, Project>()
.PreserveReferences()
.ReverseMap();
}

View File

@ -1,8 +1,9 @@
using AutoMapper;
using Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Models;
public class Secret : Core.Entities.Secret
public class Secret : Core.SecretsManager.Entities.Secret
{
public virtual new ICollection<Project> Projects { get; set; }
public virtual Organization Organization { get; set; }
@ -12,7 +13,7 @@ public class SecretMapperProfile : Profile
{
public SecretMapperProfile()
{
CreateMap<Core.Entities.Secret, Secret>()
CreateMap<Core.SecretsManager.Entities.Secret, Secret>()
.PreserveReferences()
.ReverseMap();
}

View File

@ -1,8 +1,9 @@
using AutoMapper;
using Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.Models;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Models;
public class ServiceAccount : Core.Entities.ServiceAccount
public class ServiceAccount : Core.SecretsManager.Entities.ServiceAccount
{
public virtual Organization Organization { get; set; }
public virtual ICollection<GroupServiceAccountAccessPolicy> GroupAccessPolicies { get; set; }
@ -13,6 +14,6 @@ public class ServiceAccountMapperProfile : Profile
{
public ServiceAccountMapperProfile()
{
CreateMap<Core.Entities.ServiceAccount, ServiceAccount>().ReverseMap();
CreateMap<Core.SecretsManager.Entities.ServiceAccount, ServiceAccount>().ReverseMap();
}
}

View File

@ -1,13 +1,14 @@
using AutoMapper;
using Bit.Core.Models.Data;
using Bit.Core.Repositories;
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Core.SecretsManager.Models.Data;
using Bit.Core.SecretsManager.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.SecretsManager.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework.Repositories;
namespace Bit.Infrastructure.EntityFramework.SecretsManager.Repositories;
public class ApiKeyRepository : Repository<Core.Entities.ApiKey, ApiKey, Guid>, IApiKeyRepository
public class ApiKeyRepository : Repository<Core.SecretsManager.Entities.ApiKey, ApiKey, Guid>, IApiKeyRepository
{
public ApiKeyRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.ApiKeys)
@ -27,12 +28,12 @@ public class ApiKeyRepository : Repository<Core.Entities.ApiKey, ApiKey, Guid>,
return Mapper.Map<ServiceAccountApiKeyDetails>(entity);
}
public async Task<ICollection<Core.Entities.ApiKey>> GetManyByServiceAccountIdAsync(Guid id)
public async Task<ICollection<Core.SecretsManager.Entities.ApiKey>> GetManyByServiceAccountIdAsync(Guid id)
{
using var scope = ServiceScopeFactory.CreateScope();
var dbContext = GetDatabaseContext(scope);
var apiKeys = await GetDbSet(dbContext).Where(e => e.ServiceAccountId == id).ToListAsync();
return Mapper.Map<List<Core.Entities.ApiKey>>(apiKeys);
return Mapper.Map<List<Core.SecretsManager.Entities.ApiKey>>(apiKeys);
}
}