Core.Blueprint.DAL/Core.Blueprint.DAL.Service/SecretService.cs
Sergio Matias Urquin 6358f5f199 Add project files.
2025-04-29 18:39:57 -06:00

77 lines
2.8 KiB
C#

using Core.Blueprint.DAL.Infrastructure.Contracts;
using Core.Blueprint.DAL.Service.Contracts;
using Core.Blueprint.Domain.Entities;
using Serilog;
using SharpCompress.Common;
namespace Core.Blueprint.DAL.Service
{
public class SecretService : ISecretService
{
private readonly ISecretRepository _repository;
private readonly ILogger _logger;
public SecretService(ISecretRepository repository, ILogger logger)
{
_repository = repository;
_logger = logger;
}
public async Task<Secret> GetSecret(string secretName, CancellationToken cancellationToken)
{
try
{
_logger.Information("Starting to get the secret | Method: {method} | Class: {class}", nameof(GetSecret), nameof(SecretService));
var ret = await _repository.GetSecret(secretName, cancellationToken);
_logger.Information("Finishing to get the secret | Method: {method} | Class: {class}", nameof(GetSecret), nameof(SecretService));
return ret;
}
catch (Exception ex)
{
_logger.Error(ex, "{error} | Method: {method} | Class: {class}", ex.Message, nameof(GetSecret), nameof(SecretService));
return default;
}
}
public async Task SetSecret(string secretName, string secretValue, CancellationToken cancellationToken)
{
try
{
_logger.Information("Starting to set the secret | Method: {method} | Class: {class}", nameof(SetSecret), nameof(SecretService));
await _repository.SetSecret(secretName, secretValue, cancellationToken);
_logger.Information("Finishing to set the secret | Method: {method} | Class: {class}", nameof(SetSecret), nameof(SecretService));
}
catch (Exception ex)
{
_logger.Error(ex, "{error} | Method: {method} | Class: {class}", ex.Message, nameof(SetSecret), nameof(SecretService));
}
}
public async Task RemoveSecret(string secretName, CancellationToken cancellationToken)
{
try
{
_logger.Information("Starting to remove the secret | Method: {method} | Class: {class}", nameof(RemoveSecret), nameof(SecretService));
await _repository.RemoveSecret(secretName, cancellationToken);
_logger.Information("Finishing to remove the secret | Method: {method} | Class: {class}", nameof(RemoveSecret), nameof(SecretService));
}
catch (Exception ex)
{
_logger.Error(ex, "{error} | Method: {method} | Class: {class}", ex.Message, nameof(RemoveSecret), nameof(SecretService));
}
}
}
}