-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Long lived feature branch for Secrets Manager Co-authored-by: Thomas Avery <[email protected]> Co-authored-by: cd-bitwarden <[email protected]> Co-authored-by: CarleyDiaz-Bitwarden <[email protected]> Co-authored-by: Thomas Avery <[email protected]> Co-authored-by: Colton Hurst <[email protected]>
- Loading branch information
1 parent
09e524c
commit 1f0fc43
Showing
188 changed files
with
21,344 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...icense/src/Commercial.Core/SecretManagerFeatures/AccessTokens/CreateAccessTokenCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Bit.Core.Entities; | ||
using Bit.Core.Repositories; | ||
using Bit.Core.SecretManagerFeatures.AccessTokens.Interfaces; | ||
using Bit.Core.Utilities; | ||
|
||
namespace Bit.Commercial.Core.SecretManagerFeatures.AccessTokens; | ||
|
||
public class CreateAccessTokenCommand : ICreateAccessTokenCommand | ||
{ | ||
private readonly int _clientSecretMaxLength = 30; | ||
private readonly IApiKeyRepository _apiKeyRepository; | ||
|
||
public CreateAccessTokenCommand(IApiKeyRepository apiKeyRepository) | ||
{ | ||
_apiKeyRepository = apiKeyRepository; | ||
} | ||
|
||
public async Task<ApiKey> CreateAsync(ApiKey apiKey) | ||
{ | ||
apiKey.ClientSecret = CoreHelpers.SecureRandomString(_clientSecretMaxLength); | ||
return await _apiKeyRepository.CreateAsync(apiKey); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
bitwarden_license/src/Commercial.Core/SecretManagerFeatures/Projects/CreateProjectCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Bit.Core.Entities; | ||
using Bit.Core.Repositories; | ||
using Bit.Core.SecretManagerFeatures.Projects.Interfaces; | ||
|
||
namespace Bit.Commercial.Core.SecretManagerFeatures.Projects; | ||
|
||
public class CreateProjectCommand : ICreateProjectCommand | ||
{ | ||
private readonly IProjectRepository _projectRepository; | ||
|
||
public CreateProjectCommand(IProjectRepository projectRepository) | ||
{ | ||
_projectRepository = projectRepository; | ||
} | ||
|
||
public async Task<Project> CreateAsync(Project project) | ||
{ | ||
return await _projectRepository.CreateAsync(project); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
bitwarden_license/src/Commercial.Core/SecretManagerFeatures/Projects/DeleteProjectCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Bit.Core.Entities; | ||
using Bit.Core.Exceptions; | ||
using Bit.Core.Repositories; | ||
using Bit.Core.SecretManagerFeatures.Projects.Interfaces; | ||
|
||
namespace Bit.Commercial.Core.SecretManagerFeatures.Projects; | ||
|
||
public class DeleteProjectCommand : IDeleteProjectCommand | ||
{ | ||
private readonly IProjectRepository _projectRepository; | ||
|
||
public DeleteProjectCommand(IProjectRepository projectRepository) | ||
{ | ||
_projectRepository = projectRepository; | ||
} | ||
|
||
public async Task<List<Tuple<Project, string>>> DeleteProjects(List<Guid> ids) | ||
{ | ||
var projects = await _projectRepository.GetManyByIds(ids); | ||
|
||
if (projects?.Any() != true) | ||
{ | ||
throw new NotFoundException(); | ||
} | ||
|
||
var results = ids.Select(id => | ||
{ | ||
var project = projects.FirstOrDefault(project => project.Id == id); | ||
if (project == null) | ||
{ | ||
throw new NotFoundException(); | ||
} | ||
// TODO Once permissions are implemented add check for each project here. | ||
else | ||
{ | ||
return new Tuple<Project, string>(project, ""); | ||
} | ||
}).ToList(); | ||
|
||
await _projectRepository.DeleteManyByIdAsync(ids); | ||
return results; | ||
} | ||
} | ||
|
33 changes: 33 additions & 0 deletions
33
bitwarden_license/src/Commercial.Core/SecretManagerFeatures/Projects/UpdateProjectCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Bit.Core.Entities; | ||
using Bit.Core.Exceptions; | ||
using Bit.Core.Repositories; | ||
using Bit.Core.SecretManagerFeatures.Projects.Interfaces; | ||
|
||
namespace Bit.Commercial.Core.SecretManagerFeatures.Projects; | ||
|
||
public class UpdateProjectCommand : IUpdateProjectCommand | ||
{ | ||
private readonly IProjectRepository _projectRepository; | ||
|
||
public UpdateProjectCommand(IProjectRepository projectRepository) | ||
{ | ||
_projectRepository = projectRepository; | ||
} | ||
|
||
public async Task<Project> UpdateAsync(Project project) | ||
{ | ||
var existingProject = await _projectRepository.GetByIdAsync(project.Id); | ||
if (existingProject == null) | ||
{ | ||
throw new NotFoundException(); | ||
} | ||
|
||
project.OrganizationId = existingProject.OrganizationId; | ||
project.CreationDate = existingProject.CreationDate; | ||
project.DeletedDate = existingProject.DeletedDate; | ||
project.RevisionDate = DateTime.UtcNow; | ||
|
||
await _projectRepository.ReplaceAsync(project); | ||
return project; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...en_license/src/Commercial.Core/SecretManagerFeatures/SecretManagerCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Bit.Commercial.Core.SecretManagerFeatures.AccessTokens; | ||
using Bit.Commercial.Core.SecretManagerFeatures.Projects; | ||
using Bit.Commercial.Core.SecretManagerFeatures.Secrets; | ||
using Bit.Commercial.Core.SecretManagerFeatures.ServiceAccounts; | ||
using Bit.Core.SecretManagerFeatures.AccessTokens.Interfaces; | ||
using Bit.Core.SecretManagerFeatures.Projects.Interfaces; | ||
using Bit.Core.SecretManagerFeatures.Secrets.Interfaces; | ||
using Bit.Core.SecretManagerFeatures.ServiceAccounts.Interfaces; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Bit.Commercial.Core.SecretManagerFeatures; | ||
|
||
public static class SecretManagerCollectionExtensions | ||
{ | ||
public static void AddSecretManagerServices(this IServiceCollection services) | ||
{ | ||
services.AddScoped<ICreateSecretCommand, CreateSecretCommand>(); | ||
services.AddScoped<IUpdateSecretCommand, UpdateSecretCommand>(); | ||
services.AddScoped<IDeleteSecretCommand, DeleteSecretCommand>(); | ||
services.AddScoped<ICreateProjectCommand, CreateProjectCommand>(); | ||
services.AddScoped<IUpdateProjectCommand, UpdateProjectCommand>(); | ||
services.AddScoped<IDeleteProjectCommand, DeleteProjectCommand>(); | ||
services.AddScoped<ICreateServiceAccountCommand, CreateServiceAccountCommand>(); | ||
services.AddScoped<IUpdateServiceAccountCommand, UpdateServiceAccountCommand>(); | ||
services.AddScoped<ICreateAccessTokenCommand, CreateAccessTokenCommand>(); | ||
} | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
bitwarden_license/src/Commercial.Core/SecretManagerFeatures/Secrets/CreateSecretCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Bit.Core.Entities; | ||
using Bit.Core.Repositories; | ||
using Bit.Core.SecretManagerFeatures.Secrets.Interfaces; | ||
|
||
namespace Bit.Commercial.Core.SecretManagerFeatures.Secrets; | ||
|
||
public class CreateSecretCommand : ICreateSecretCommand | ||
{ | ||
private readonly ISecretRepository _secretRepository; | ||
|
||
public CreateSecretCommand(ISecretRepository secretRepository) | ||
{ | ||
_secretRepository = secretRepository; | ||
} | ||
|
||
public async Task<Secret> CreateAsync(Secret secret) | ||
{ | ||
return await _secretRepository.CreateAsync(secret); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
bitwarden_license/src/Commercial.Core/SecretManagerFeatures/Secrets/DeleteSecretCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Bit.Core.Entities; | ||
using Bit.Core.Exceptions; | ||
using Bit.Core.Repositories; | ||
using Bit.Core.SecretManagerFeatures.Secrets.Interfaces; | ||
|
||
namespace Bit.Commercial.Core.SecretManagerFeatures.Secrets; | ||
|
||
public class DeleteSecretCommand : IDeleteSecretCommand | ||
{ | ||
private readonly ISecretRepository _secretRepository; | ||
|
||
public DeleteSecretCommand(ISecretRepository secretRepository) | ||
{ | ||
_secretRepository = secretRepository; | ||
} | ||
|
||
public async Task<List<Tuple<Secret, string>>> DeleteSecrets(List<Guid> ids) | ||
{ | ||
var secrets = await _secretRepository.GetManyByIds(ids); | ||
|
||
if (secrets?.Any() != true) | ||
{ | ||
throw new NotFoundException(); | ||
} | ||
|
||
var results = ids.Select(id => | ||
{ | ||
var secret = secrets.FirstOrDefault(secret => secret.Id == id); | ||
if (secret == null) | ||
{ | ||
throw new NotFoundException(); | ||
} | ||
// TODO Once permissions are implemented add check for each secret here. | ||
else | ||
{ | ||
return new Tuple<Secret, string>(secret, ""); | ||
} | ||
}).ToList(); | ||
|
||
await _secretRepository.SoftDeleteManyByIdAsync(ids); | ||
return results; | ||
} | ||
} | ||
|
33 changes: 33 additions & 0 deletions
33
bitwarden_license/src/Commercial.Core/SecretManagerFeatures/Secrets/UpdateSecretCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Bit.Core.Entities; | ||
using Bit.Core.Exceptions; | ||
using Bit.Core.Repositories; | ||
using Bit.Core.SecretManagerFeatures.Secrets.Interfaces; | ||
|
||
namespace Bit.Commercial.Core.SecretManagerFeatures.Secrets; | ||
|
||
public class UpdateSecretCommand : IUpdateSecretCommand | ||
{ | ||
private readonly ISecretRepository _secretRepository; | ||
|
||
public UpdateSecretCommand(ISecretRepository secretRepository) | ||
{ | ||
_secretRepository = secretRepository; | ||
} | ||
|
||
public async Task<Secret> UpdateAsync(Secret secret) | ||
{ | ||
var existingSecret = await _secretRepository.GetByIdAsync(secret.Id); | ||
if (existingSecret == null) | ||
{ | ||
throw new NotFoundException(); | ||
} | ||
|
||
secret.OrganizationId = existingSecret.OrganizationId; | ||
secret.CreationDate = existingSecret.CreationDate; | ||
secret.DeletedDate = existingSecret.DeletedDate; | ||
secret.RevisionDate = DateTime.UtcNow; | ||
|
||
await _secretRepository.UpdateAsync(secret); | ||
return secret; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
.../src/Commercial.Core/SecretManagerFeatures/ServiceAccounts/CreateServiceAccountCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Bit.Core.Entities; | ||
using Bit.Core.Repositories; | ||
using Bit.Core.SecretManagerFeatures.ServiceAccounts.Interfaces; | ||
|
||
namespace Bit.Commercial.Core.SecretManagerFeatures.ServiceAccounts; | ||
|
||
public class CreateServiceAccountCommand : ICreateServiceAccountCommand | ||
{ | ||
private readonly IServiceAccountRepository _serviceAccountRepository; | ||
|
||
public CreateServiceAccountCommand(IServiceAccountRepository serviceAccountRepository) | ||
{ | ||
_serviceAccountRepository = serviceAccountRepository; | ||
} | ||
|
||
public async Task<ServiceAccount> CreateAsync(ServiceAccount serviceAccount) | ||
{ | ||
return await _serviceAccountRepository.CreateAsync(serviceAccount); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
.../src/Commercial.Core/SecretManagerFeatures/ServiceAccounts/UpdateServiceAccountCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Bit.Core.Entities; | ||
using Bit.Core.Exceptions; | ||
using Bit.Core.Repositories; | ||
using Bit.Core.SecretManagerFeatures.ServiceAccounts.Interfaces; | ||
|
||
namespace Bit.Commercial.Core.SecretManagerFeatures.ServiceAccounts; | ||
|
||
public class UpdateServiceAccountCommand : IUpdateServiceAccountCommand | ||
{ | ||
private readonly IServiceAccountRepository _serviceAccountRepository; | ||
|
||
public UpdateServiceAccountCommand(IServiceAccountRepository serviceAccountRepository) | ||
{ | ||
_serviceAccountRepository = serviceAccountRepository; | ||
} | ||
|
||
public async Task<ServiceAccount> UpdateAsync(ServiceAccount serviceAccount) | ||
{ | ||
var existingServiceAccount = await _serviceAccountRepository.GetByIdAsync(serviceAccount.Id); | ||
if (existingServiceAccount == null) | ||
{ | ||
throw new NotFoundException(); | ||
} | ||
|
||
serviceAccount.OrganizationId = existingServiceAccount.OrganizationId; | ||
serviceAccount.CreationDate = existingServiceAccount.CreationDate; | ||
serviceAccount.RevisionDate = DateTime.UtcNow; | ||
|
||
await _serviceAccountRepository.ReplaceAsync(serviceAccount); | ||
return serviceAccount; | ||
} | ||
} |
10 changes: 8 additions & 2 deletions
10
bitwarden_license/src/Commercial.Core/Utilities/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
using Bit.Commercial.Core.Services; | ||
using Bit.Commercial.Core.SecretManagerFeatures; | ||
using Bit.Commercial.Core.Services; | ||
using Bit.Core.Services; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Bit.Commercial.Core.Utilities; | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
public static void AddCommCoreServices(this IServiceCollection services) | ||
public static void AddCommercialCoreServices(this IServiceCollection services) | ||
{ | ||
services.AddScoped<IProviderService, ProviderService>(); | ||
} | ||
|
||
public static void AddCommercialSecretsManagerServices(this IServiceCollection services) | ||
{ | ||
services.AddSecretManagerServices(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ommercial.Infrastructure.EntityFramework/Commercial.Infrastructure.EntityFramework.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Core\Core.csproj" /> | ||
<ProjectReference Include="..\..\..\src\Infrastructure.EntityFramework\Infrastructure.EntityFramework.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.