using AutomationDAL.CustomCode.ScriptSecretRef; using AutomationDAL.DTO.ScriptSecretRef; using GB5Shared.DTO.Framework.Login; using GB5Shared.Resource.Response; using Microsoft.Extensions.Logging; namespace AutomationBLL.ScriptSecretRef; public class ScriptSecretRefBLL : IScriptSecretRefBLL { private readonly IScriptSecretRefDAL _dal; private readonly ILogger _logger; public ScriptSecretRefBLL(IScriptSecretRefDAL dal, ILogger logger) { _dal = dal; _logger = logger; } public async Task> GetByScript(int scriptId, LoginDTO login, CancellationToken ct) => await _dal.GetByScript(scriptId, login, ct).ConfigureAwait(false); public async Task Save(ScriptSecretRefDTO dto, LoginDTO login, CancellationToken ct) { try { if (dto.ScriptId <= 0) throw new InvalidOperationException("ScriptId is required."); if (string.IsNullOrWhiteSpace(dto.SecretName)) throw new InvalidOperationException("SecretName is required."); if (string.IsNullOrWhiteSpace(dto.VaultReference)) throw new InvalidOperationException("VaultReference is required — never store the secret value itself."); int newId = await _dal.Insert(dto, login, ct).ConfigureAwait(false); return $"{SuccessResponse.SaveSuccessMessage} {newId}"; } catch (Exception ex) { _logger.LogError(ex, "Save failed for ScriptSecretRef {SecretName}", dto.SecretName); throw; } } public async Task Delete(int secretRefId, LoginDTO login, CancellationToken ct) { await _dal.Delete(secretRefId, login, ct).ConfigureAwait(false); return SuccessResponse.DeleteSuccessMessage; } }