using Microsoft.Extensions.Logging;
using JdeScoping.SecureStoreManager.Services;
namespace JdeScoping.SecureStoreManager.Application;
///
/// Store lifecycle use-case operations with logging.
///
public class StoreUseCases
{
private readonly ISecureStoreManager _storeManager;
private readonly ILogger _logger;
///
/// Initializes a new instance of the class.
///
/// The secure store manager instance.
/// The logger instance.
public StoreUseCases(ISecureStoreManager storeManager, ILogger logger)
{
_storeManager = storeManager ?? throw new ArgumentNullException(nameof(storeManager));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
///
/// Creates a new store with key file authentication.
///
/// The path where the store will be created.
/// The path to the key file.
public void CreateStore(string storePath, string keyFilePath)
{
if (string.IsNullOrEmpty(keyFilePath))
throw new ArgumentException("Key file path must be provided.", nameof(keyFilePath));
_logger.LogInformation("Creating store at {StorePath}", storePath);
_storeManager.CreateStore(storePath, keyFilePath);
_logger.LogInformation("Store created with key file: {KeyFilePath}", keyFilePath);
}
///
/// Opens an existing store with key file authentication.
///
/// The path to the existing store.
/// The path to the key file.
public void OpenStore(string storePath, string keyFilePath)
{
if (string.IsNullOrEmpty(keyFilePath))
throw new ArgumentException("Key file path must be provided.", nameof(keyFilePath));
_logger.LogInformation("Opening store at {StorePath}", storePath);
_storeManager.OpenStore(storePath, keyFilePath);
_logger.LogDebug("Store opened with key file");
}
///
/// Closes the currently open store.
///
public void CloseStore()
{
_logger.LogInformation("Closing store");
_storeManager.CloseStore();
}
///
/// Saves changes to the current store.
///
public void Save()
{
_logger.LogInformation("Saving store");
_storeManager.Save();
}
///
/// Generates a new key file at the specified path.
///
/// The path where the key file will be generated.
public void GenerateKeyFile(string path)
{
_logger.LogInformation("Generating key file at {Path}", path);
_storeManager.GenerateKeyFile(path);
_logger.LogInformation("Key file generated successfully");
}
///
/// Exports the current store's key to a file.
///
/// The path where the key will be exported.
public void ExportKey(string path)
{
_logger.LogInformation("Exporting key to {Path}", path);
_storeManager.ExportKey(path);
_logger.LogInformation("Key exported successfully");
}
}