using Core.Blueprint.Service.Domain.Entities; using Core.Blueprint.Service.External.Clients.SecretClient; using Core.Blueprint.Service.UseCases.GetSampleItems.Input; using Core.Blueprint.Service.UseCases.GetSampleItems.Ports; using Core.Blueprint.Service.UseCases.GetSecret.Input; using Core.Blueprint.Service.UseCases.GetSecret.Ports; using FluentValidation; using Lib.Architecture.BuildingBlocks; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Core.Blueprint.Service.UseCases.GetSecret { public class GetSecretHandler(IGetSecretPort port, IValidator validator, ISecretService secretService) : IComponentHandler { private readonly IGetSecretPort _port = port; private readonly IValidator _validator = validator; private readonly ISecretService _secretService = secretService; public async ValueTask ExecuteAsync(GetSecretRequest command, CancellationToken cancellationToken = default) { try { if (!command.IsValid(_validator)) { _port.ValidationErrors(command.Notifications); } var result = await _secretService.GetSecretAsync(command.Secret); if (result is null || string.IsNullOrWhiteSpace(result.Value)) { _port.NoContentSuccess(); return; } _port.Success(result); } catch (Exception ex) { _port.BusinessError(ex.Message); } } } }