Add project files.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Ports;
|
||||
using Core.Blueprint.KeyVault;
|
||||
using Core.Blueprint.Service.External.Clients.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.MongoStorage.Adapter
|
||||
{
|
||||
public class KeyVaultPort : BasePresenter, IKeyVaultPort
|
||||
{
|
||||
public void Success(KeyVaultResponse output)
|
||||
{
|
||||
ViewModel = new OkObjectResult(output);
|
||||
}
|
||||
public void Success(KeyVaultAdapter output)
|
||||
{
|
||||
ViewModel = new OkObjectResult(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class CreateSecretRequest : Notificator, ICommand
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public string Value { get; set; } = null!;
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return !string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class DeleteSecretRequest : Notificator, ICommand
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return !string.IsNullOrEmpty(Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class GetSecretRequest : Notificator, ICommand
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public bool Validate()
|
||||
{
|
||||
return string.IsNullOrEmpty(Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
|
||||
{
|
||||
public class UpdateSecretRequest : Notificator, ICommand
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
public string Value { get; set; } = null!;
|
||||
public bool Validate()
|
||||
{
|
||||
return !string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
160
Core.Blueprint.Application/UsesCases/KeyVault/KeyVaultHandler.cs
Normal file
160
Core.Blueprint.Application/UsesCases/KeyVault/KeyVaultHandler.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Ports;
|
||||
using Core.Blueprint.KeyVault;
|
||||
using Core.Blueprint.Service.External.Clients;
|
||||
using FluentValidation;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
using Lib.Architecture.BuildingBlocks.Helpers;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault
|
||||
{
|
||||
public class KeyVaultHandler :
|
||||
IComponentHandler<CreateSecretRequest>,
|
||||
IComponentHandler<GetSecretRequest>,
|
||||
IComponentHandler<UpdateSecretRequest>,
|
||||
IComponentHandler<DeleteSecretRequest>
|
||||
{
|
||||
private readonly IKeyVaultPort _port;
|
||||
private readonly IValidator<CreateSecretRequest> _createSecretValidator;
|
||||
private readonly IValidator<GetSecretRequest> _getSecretValidator;
|
||||
private readonly IValidator<UpdateSecretRequest> _updateSecretValidator;
|
||||
private readonly IValidator<DeleteSecretRequest> _deleteSecretValidator;
|
||||
private readonly IBlueprintServiceClient _keyVaultDALService;
|
||||
|
||||
public KeyVaultHandler(
|
||||
IKeyVaultPort port,
|
||||
IValidator<CreateSecretRequest> createSecretValidator,
|
||||
IValidator<GetSecretRequest> getSecretValidator,
|
||||
IValidator<UpdateSecretRequest> updateSecretValidator,
|
||||
IValidator<DeleteSecretRequest> deleteSecretValidator,
|
||||
IBlueprintServiceClient keyVaultDALService)
|
||||
{
|
||||
_port = port ?? throw new ArgumentNullException(nameof(port));
|
||||
_createSecretValidator = createSecretValidator ?? throw new ArgumentNullException(nameof(createSecretValidator));
|
||||
_getSecretValidator = getSecretValidator ?? throw new ArgumentNullException(nameof(getSecretValidator));
|
||||
_updateSecretValidator = updateSecretValidator ?? throw new ArgumentNullException(nameof(updateSecretValidator));
|
||||
_deleteSecretValidator = deleteSecretValidator ?? throw new ArgumentNullException(nameof(deleteSecretValidator));
|
||||
_keyVaultDALService = keyVaultDALService ?? throw new ArgumentNullException(nameof(keyVaultDALService));
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(CreateSecretRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_createSecretValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new KeyVaultRequest
|
||||
{
|
||||
Name = command.Name,
|
||||
Value = command.Value,
|
||||
};
|
||||
|
||||
var result = await _keyVaultDALService.CreateSecretAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask ExecuteAsync(GetSecretRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
var result = await _keyVaultDALService.GetSecretByNameAsync(command.Name, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async ValueTask ExecuteAsync(UpdateSecretRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_updateSecretValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = new KeyVaultRequest
|
||||
{
|
||||
Name = command.Name,
|
||||
Value = command.Value,
|
||||
};
|
||||
|
||||
var result = await _keyVaultDALService.UpdateSecretAsync(request, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async ValueTask ExecuteAsync(DeleteSecretRequest command, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
|
||||
if (!command.IsValid(_deleteSecretValidator))
|
||||
{
|
||||
_port.ValidationErrors(command.Notifications);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _keyVaultDALService.DeleteSecretAsync(command.Name, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_port.NoContentSuccess();
|
||||
return;
|
||||
}
|
||||
|
||||
_port.Success(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ApiResponseHelper.EvaluatePort(ex, _port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Core.Blueprint.KeyVault;
|
||||
using Core.Blueprint.Service.External.Clients.Adapters;
|
||||
using Lib.Architecture.BuildingBlocks;
|
||||
|
||||
namespace Core.Blueprint.Application.UsesCases.KeyVault.Ports
|
||||
{
|
||||
public interface IKeyVaultPort : IBasePort,
|
||||
ICommandSuccessPort<KeyVaultResponse>,
|
||||
ICommandSuccessPort<KeyVaultAdapter>,
|
||||
INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort,
|
||||
INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort,
|
||||
IBadRequestPort
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
|
||||
{
|
||||
public class CreateSecretValidator : AbstractValidator<CreateSecretRequest>
|
||||
{
|
||||
public CreateSecretValidator()
|
||||
{
|
||||
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Secret Name").WithMessage("Secret Name is Obligatory.");
|
||||
RuleFor(i => i.Value).NotEmpty().NotNull().OverridePropertyName(x => x.Value).WithName("Secret Name").WithMessage("Secret Value is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
|
||||
{
|
||||
public class DeleteSecretValidator : AbstractValidator<DeleteSecretRequest>
|
||||
{
|
||||
public DeleteSecretValidator()
|
||||
{
|
||||
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Secret Name").WithMessage("Secret Name is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
|
||||
{
|
||||
public class GetSecretValidator : AbstractValidator<GetSecretRequest>
|
||||
{
|
||||
public GetSecretValidator()
|
||||
{
|
||||
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Secret Name").WithMessage("Secret Name is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
|
||||
{
|
||||
public class UpdateSecretValidator : AbstractValidator<UpdateSecretRequest>
|
||||
{
|
||||
public UpdateSecretValidator()
|
||||
{
|
||||
RuleFor(i => i.Name).NotEmpty().NotNull().OverridePropertyName(x => x.Name).WithName("Secret Name").WithMessage("Secret Name is Obligatory.");
|
||||
RuleFor(i => i.Value).NotEmpty().NotNull().OverridePropertyName(x => x.Value).WithName("Secret Value").WithMessage("Secret Value is Obligatory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user