using Microsoft.Extensions.Logging;
using JdeScoping.SecureStoreManager.Services;
namespace JdeScoping.SecureStoreManager.Application;
///
/// Secret CRUD use-case operations with logging.
///
public class SecretUseCases
{
private readonly ISecureStoreManager _storeManager;
private readonly ILogger _logger;
///
/// Initializes a new instance of the class.
///
/// The secure store manager.
/// The logger instance.
public SecretUseCases(ISecureStoreManager storeManager, ILogger logger)
{
_storeManager = storeManager ?? throw new ArgumentNullException(nameof(storeManager));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
///
/// Sets a secret with the given key and value.
///
/// The secret key.
/// The secret value.
public void SetSecret(string key, string value)
{
_logger.LogInformation("Setting secret {Key}", key);
_storeManager.SetSecret(key, value);
}
///
/// Removes a secret by key.
///
/// The secret key to remove.
public void RemoveSecret(string key)
{
_logger.LogInformation("Removing secret {Key}", key);
_storeManager.RemoveSecret(key);
}
///
/// Gets all keys in the current store.
///
public IReadOnlyList GetKeys()
{
return _storeManager.GetKeys();
}
///
/// Gets the value of a secret by key.
///
/// The secret key.
/// The secret value.
public string GetSecret(string key)
{
return _storeManager.GetSecret(key);
}
}