Add project files.

This commit is contained in:
Sergio Matias Urquin
2025-04-29 18:44:41 -06:00
parent c4ec91852f
commit b2635193dc
133 changed files with 4100 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
using Core.Blueprint.Application.UsesCases.BlobStorage.Ports;
using Core.Blueprint.Storage;
using Core.Blueprint.Storage.Adapters;
using Lib.Architecture.BuildingBlocks;
using Microsoft.AspNetCore.Mvc;
namespace Core.Blueprint.Application.UsesCases.BlobStorage.Adapter
{
public class StoragePort : BasePresenter, IStoragePort
{
public void Success(List<BlobFileAdapter> output)
{
ViewModel = new OkObjectResult(output);
}
public void Success(BlobFileAdapter output)
{
ViewModel = new OkObjectResult(output);
}
public void Success(BlobDownloadUriAdapter output)
{
ViewModel = new OkObjectResult(output);
}
}
}

View File

@@ -0,0 +1,14 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
{
public class DeleteBlobRequest : Notificator, ICommand
{
public string BlobName { get; set; }
public bool Validate()
{
return !string.IsNullOrEmpty(BlobName);
}
}
}

View File

@@ -0,0 +1,13 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
{
public class DownloadBlobRequest : Notificator, ICommand
{
public string BlobName { get; set; } = null!;
public bool Validate()
{
return !string.IsNullOrEmpty(BlobName);
}
}
}

View File

@@ -0,0 +1,13 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
{
public class GetBlobListRequest : Notificator, ICommand
{
public string? Prefix { get; set; }
public bool Validate()
{
return true;
}
}
}

View File

@@ -0,0 +1,16 @@
using Lib.Architecture.BuildingBlocks;
namespace Core.Blueprint.Application.UsesCases.KeyVault.Input
{
public class UploadBlobRequest : Notificator, ICommand
{
public string BlobName { get; set; } = null!;
public byte[] File { get; set; } = null!;
public bool Validate()
{
return !string.IsNullOrEmpty(BlobName);
}
}
}

View File

@@ -0,0 +1,16 @@
using Core.Blueprint.Storage;
using Core.Blueprint.Storage.Adapters;
using Lib.Architecture.BuildingBlocks;
namespace Core.Blueprint.Application.UsesCases.BlobStorage.Ports
{
public interface IStoragePort : IBasePort,
ICommandSuccessPort<List<BlobFileAdapter>>,
ICommandSuccessPort<BlobFileAdapter>,
ICommandSuccessPort<BlobDownloadUriAdapter>,
INoContentPort, IBusinessErrorPort, ITimeoutPort, IValidationErrorPort,
INotFoundPort, IForbiddenPort, IUnauthorizedPort, IInternalServerErrorPort,
IBadRequestPort
{
}
}

View 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 Storage :
IComponentHandler<CreateBlobRequest>,
IComponentHandler<GetBlobListRequest>,
IComponentHandler<UpdateBlobRequest>,
IComponentHandler<DeleteBlobRequest>
{
private readonly IKeyVaultPort _port;
private readonly IValidator<CreateBlobRequest> _createKeyVaultValidator;
private readonly IValidator<GetBlobListRequest> _getKeyVaultValidator;
private readonly IValidator<UpdateBlobRequest> _updateKeyVaultValidator;
private readonly IValidator<DeleteBlobRequest> _deleteKeyVaultValidator;
private readonly IBlueprintServiceClient _keyVaultDALService;
public Storage(
IKeyVaultPort port,
IValidator<CreateBlobRequest> createKeyVaultValidator,
IValidator<GetBlobListRequest> getKeyVaultValidator,
IValidator<UpdateBlobRequest> updateKeyVaultValidator,
IValidator<DeleteBlobRequest> deleteKeyVaultValidator,
IBlueprintServiceClient keyVaultDALService)
{
_port = port ?? throw new ArgumentNullException(nameof(port));
_createKeyVaultValidator = createKeyVaultValidator ?? throw new ArgumentNullException(nameof(createKeyVaultValidator));
_getKeyVaultValidator = getKeyVaultValidator ?? throw new ArgumentNullException(nameof(getKeyVaultValidator));
_updateKeyVaultValidator = updateKeyVaultValidator ?? throw new ArgumentNullException(nameof(updateKeyVaultValidator));
_deleteKeyVaultValidator = deleteKeyVaultValidator ?? throw new ArgumentNullException(nameof(deleteKeyVaultValidator));
_keyVaultDALService = keyVaultDALService ?? throw new ArgumentNullException(nameof(keyVaultDALService));
}
public async ValueTask ExecuteAsync(CreateBlobRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_createKeyVaultValidator))
{
_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(GetBlobListRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _keyVaultDALService.GetSecretByNameAsync("", cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(UpdateBlobRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_updateKeyVaultValidator))
{
_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(DeleteBlobRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_deleteKeyVaultValidator))
{
_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);
}
}
}
}

View File

@@ -0,0 +1,151 @@
using Core.Blueprint.Application.UsesCases.BlobStorage.Ports;
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
using Core.Blueprint.Service.External.Clients;
using Core.Blueprint.Storage;
using FluentValidation;
using Lib.Architecture.BuildingBlocks;
using Lib.Architecture.BuildingBlocks.Helpers;
namespace Core.Cerberos.Application.UseCases.KeyVault
{
public class StorageHandler :
IComponentHandler<UploadBlobRequest>,
IComponentHandler<GetBlobListRequest>,
IComponentHandler<DownloadBlobRequest>,
IComponentHandler<DeleteBlobRequest>
{
private readonly IStoragePort _port;
private readonly IValidator<UploadBlobRequest> _uploadBlobValidator;
private readonly IValidator<DownloadBlobRequest> _downloadBlobValidator;
private readonly IValidator<DeleteBlobRequest> _deleteBlobValidator;
private readonly IBlueprintServiceClient _storageDALService;
public StorageHandler(
IStoragePort port,
IValidator<UploadBlobRequest> uploadBlobValidator,
IValidator<DownloadBlobRequest> downloadBlobValidator,
IValidator<DeleteBlobRequest> deleteBlobValidator,
IBlueprintServiceClient storageDALService)
{
_port = port ?? throw new ArgumentNullException(nameof(port));
_uploadBlobValidator = uploadBlobValidator ?? throw new ArgumentNullException(nameof(uploadBlobValidator));
_downloadBlobValidator = downloadBlobValidator ?? throw new ArgumentNullException(nameof(downloadBlobValidator));
_deleteBlobValidator = deleteBlobValidator ?? throw new ArgumentNullException(nameof(deleteBlobValidator));
_storageDALService = storageDALService ?? throw new ArgumentNullException(nameof(storageDALService));
}
public async ValueTask ExecuteAsync(UploadBlobRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_uploadBlobValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var request = new BlobAddDto
{
FileName = command.BlobName,
FileContent = command.File
};
var result = await _storageDALService.UploadBlobAsync(request, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(GetBlobListRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
var result = await _storageDALService.GetBlobListAsync(command.Prefix, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(DownloadBlobRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_downloadBlobValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var result = await _storageDALService.DownloadBlobAsync(command.BlobName, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
public async ValueTask ExecuteAsync(DeleteBlobRequest command, CancellationToken cancellationToken = default)
{
try
{
ArgumentNullException.ThrowIfNull(command);
if (!command.IsValid(_deleteBlobValidator))
{
_port.ValidationErrors(command.Notifications);
return;
}
var result = await _storageDALService.DeleteBlobAsync(command.BlobName, cancellationToken).ConfigureAwait(false);
if (result == null)
{
_port.NoContentSuccess();
return;
}
_port.Success(result);
}
catch (Exception ex)
{
ApiResponseHelper.EvaluatePort(ex, _port);
}
}
}
}

View File

@@ -0,0 +1,13 @@
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
using FluentValidation;
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
{
public class DeleteBlobValidator : AbstractValidator<DeleteBlobRequest>
{
public DeleteBlobValidator()
{
RuleFor(i => i.BlobName).NotEmpty().NotNull().OverridePropertyName(x => x.BlobName).WithName("Blob Name").WithMessage("Blob Name is Obligatory.");
}
}
}

View File

@@ -0,0 +1,13 @@
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
using FluentValidation;
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
{
public class DownloadBlobValidator : AbstractValidator<DownloadBlobRequest>
{
public DownloadBlobValidator()
{
RuleFor(i => i.BlobName).NotEmpty().NotNull().OverridePropertyName(x => x.BlobName).WithName("Blob Name").WithMessage("Blob Name is Obligatory.");
}
}
}

View File

@@ -0,0 +1,14 @@
using Core.Blueprint.Application.UsesCases.KeyVault.Input;
using FluentValidation;
namespace Core.Cerberos.Application.UseCases.KeyVault.Validator
{
public class UploadBlobValidator : AbstractValidator<UploadBlobRequest>
{
public UploadBlobValidator()
{
RuleFor(i => i.BlobName).NotEmpty().NotNull().OverridePropertyName(x => x.BlobName).WithName("Blob Name").WithMessage("Blob Name is Obligatory.");
RuleFor(i => i.File).NotNull().OverridePropertyName(x => x.File).WithName("Blob File").WithMessage("Blob File is Obligatory.");
}
}
}