using System; using System.Threading; using System.Threading.Tasks; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using GB5Shared.Vault; using static FrameworkDAL.Constant.Constant; namespace FrameworkSL.Endpoints.Vault { /// /// Stores/updates a secret in HashiCorp Vault via . /// See for why this is the only supported write path. /// public class SetSecretEndpoint : BaseEndpoint> { private readonly IVaultService _vaultService; public SetSecretEndpoint(IVaultService vaultService) { _vaultService = vaultService; } public override void Configure() { Post("/Vault/SetSecret"); AllowAnonymous(); } public record SetSecretParameters( [property: FromHeader] string Login, string Key, string Value ); protected override async Task> ExecuteAsync(SetSecretParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { await _vaultService.SetSecretAsync(req.Key, req.Value, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( new { Key = req.Key, Saved = true }, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }