diff --git a/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/ISecureStorageProvider.cs b/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/ISecureStorageProvider.cs new file mode 100644 index 0000000..8b5e0db --- /dev/null +++ b/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/ISecureStorageProvider.cs @@ -0,0 +1,39 @@ +namespace StevanFreeborn.Extensions.Configuration.Secure.Storage; + +/// +/// Defines a contract for a provider that stores and retrieves secure configuration data. +/// +public interface ISecureStorageProvider +{ + /// + /// Reads the value associated with the specified key asynchronously. + /// + /// The key of the configuration value to read. + /// A cancellation token that can be used to cancel the read operation. + /// A task that represents the asynchronous read operation. The task result contains the value associated with the specified key, or an empty string if the key is not found. + Task ReadAsync(string key, CancellationToken ct = default); + + /// + /// Reads all configuration values asynchronously. + /// + /// A cancellation token that can be used to cancel the read operation. + /// A task that represents the asynchronous read operation. The task result contains a dictionary of all configuration keys and their encrypted values. + Task> ReadAllAsync(CancellationToken ct = default); + + /// + /// Writes the specified key and encrypted data asynchronously. + /// + /// The key of the configuration value to write. + /// The encrypted configuration data to write. + /// A cancellation token that can be used to cancel the write operation. + /// A task that represents the asynchronous write operation. + Task WriteAsync(string key, string encryptedData, CancellationToken ct = default); + + /// + /// Deletes the configuration value associated with the specified key asynchronously. + /// + /// The key of the configuration value to delete. + /// A cancellation token that can be used to cancel the delete operation. + /// A task that represents the asynchronous delete operation. The task result contains true if the value was successfully deleted; otherwise, false. + Task DeleteAsync(string key, CancellationToken ct = default); +} \ No newline at end of file diff --git a/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/JsonFileStorageProvider.cs b/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/JsonFileStorageProvider.cs index ce280ab..19add1f 100644 --- a/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/JsonFileStorageProvider.cs +++ b/src/StevanFreeborn.Extensions.Configuration.Secure/Storage/JsonFileStorageProvider.cs @@ -6,7 +6,7 @@ namespace StevanFreeborn.Extensions.Configuration.Secure.Storage; /// Provides a mechanism to store and retrieve secure configuration data in a JSON file. /// /// The configuring the storage provider, including file paths. -public sealed class JsonFileStorageProvider(JsonStorageOptions options) +public sealed class JsonFileStorageProvider(JsonStorageOptions options) : ISecureStorageProvider { private static readonly SemaphoreSlim FileLock = new(1, 1); private static readonly JsonSerializerOptions JsonOptions = new() @@ -39,7 +39,7 @@ public sealed class JsonFileStorageProvider(JsonStorageOptions options) /// /// A cancellation token that can be used to cancel the read operation. /// A task that represents the asynchronous read operation. The task result contains a dictionary of all configuration keys and their values. - public Task> ReadAllAsync(CancellationToken ct = default) + public Task> ReadAllAsync(CancellationToken ct = default) { return AcquireLockAndLoadAsync(ct); } @@ -95,7 +95,7 @@ public sealed class JsonFileStorageProvider(JsonStorageOptions options) /// /// A cancellation token to observe while waiting for the lock or during the load operation. /// A dictionary containing the loaded configuration data. - private async Task> AcquireLockAndLoadAsync(CancellationToken ct) + private async Task> AcquireLockAndLoadAsync(CancellationToken ct) { await FileLock.WaitAsync(ct).ConfigureAwait(false);