diff --git a/README.md b/README.md index 9bbe8f2..03546fe 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # SecureStore.Contrib.Configuration [![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/SecureStore.Contrib.Configuration?color=blue)](https://www.nuget.org/packages/SecureStore.Contrib.Configuration) +[![Nuget](https://img.shields.io/nuget/dt/SecureStore.Contrib.Configuration?color=blue)](https://www.nuget.org/packages/SecureStore.Contrib.Configuration) ![build](https://github.com/gowon/SecureStore.Contrib.Configuration/workflows/build/badge.svg) [![codecov](https://codecov.io/gh/gowon/SecureStore.Contrib.Configuration/branch/master/graph/badge.svg)](https://codecov.io/gh/gowon/SecureStore.Contrib.Configuration) diff --git a/src/SecureStore.Contrib.Configuration/KeyType.cs b/src/SecureStore.Contrib.Configuration/KeyType.cs index 81d6ddc..10f38da 100644 --- a/src/SecureStore.Contrib.Configuration/KeyType.cs +++ b/src/SecureStore.Contrib.Configuration/KeyType.cs @@ -1,8 +1,18 @@ namespace SecureStore.Contrib.Configuration { + /// + /// SecureStore key types. + /// public enum KeyType { + /// + /// File key. + /// File, + + /// + /// Password key. + /// Password } } \ No newline at end of file diff --git a/src/SecureStore.Contrib.Configuration/SecureStore.Contrib.Configuration.csproj b/src/SecureStore.Contrib.Configuration/SecureStore.Contrib.Configuration.csproj index b5f9ba0..1be8c28 100644 --- a/src/SecureStore.Contrib.Configuration/SecureStore.Contrib.Configuration.csproj +++ b/src/SecureStore.Contrib.Configuration/SecureStore.Contrib.Configuration.csproj @@ -4,7 +4,7 @@ netstandard2.0 latest $(NoWarn);1591 - 1.0.0-alpha + 1.0.0 Gowon Patterson A SecureStore configuration provider to use with Microsoft.Extensions.Configuration. © Gowon Patterson. All rights reserved. diff --git a/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationExtensions.cs b/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationExtensions.cs index f18c2be..8048650 100644 --- a/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationExtensions.cs +++ b/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationExtensions.cs @@ -5,20 +5,53 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.FileProviders; + /// + /// Extension methods for adding . + /// public static class SecureStoreConfigurationExtensions { + /// + /// Adds the SecureStore configuration provider at to . + /// + /// The to add to. + /// Path relative to the base path stored in + /// of . + /// The SecureStore key. + /// The key type. + /// The . public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilder builder, string path, string key, KeyType keyType) { return AddSecureStoreFile(builder, path, key, keyType, false); } + /// + /// Adds the SecureStore configuration provider at to . + /// + /// The to add to. + /// Path relative to the base path stored in + /// of . + /// The SecureStore key. + /// The key type. + /// Whether the file is optional. + /// The . public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilder builder, string path, string key, KeyType keyType, bool optional) { return AddSecureStoreFile(builder, path, key, keyType, optional, false); } + /// + /// Adds the SecureStore configuration provider at to . + /// + /// The to add to. + /// Path relative to the base path stored in + /// of . + /// The SecureStore key. + /// The key type. + /// Whether the file is optional. + /// Whether the configuration should be reloaded if the file changes. + /// The . public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilder builder, string path, string key, KeyType keyType, bool optional, bool reloadOnChange) @@ -26,6 +59,18 @@ public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilde return AddSecureStoreFile(builder, null, path, key, keyType, optional, reloadOnChange); } + /// + /// Adds a SecureStore configuration source to . + /// + /// The to add to. + /// The to use to access the file. + /// Path relative to the base path stored in + /// of . + /// The SecureStore key. + /// The key type. + /// Whether the file is optional. + /// Whether the configuration should be reloaded if the file changes. + /// The . public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilder builder, IFileProvider provider, string path, string key, KeyType keyType, bool optional, bool reloadOnChange) @@ -51,18 +96,24 @@ public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilde path = Path.GetFileName(path); } - var source = new SecureStoreConfigurationSource + return builder.AddSecureStoreFile(source => { - FileProvider = provider, - Path = path, - Key = key, - KeyType = keyType, - Optional = optional, - ReloadOnChange = reloadOnChange - }; - - builder.Add(source); - return builder; + source.FileProvider = provider; + source.Path = path; + source.Key = key; + source.KeyType = keyType; + source.Optional = optional; + source.ReloadOnChange = reloadOnChange; + }); } + + /// + /// Adds a SecureStore configuration source to . + /// + /// The to add to. + /// Configures the source. + /// The . + public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilder builder, Action configureSource) + => builder.Add(configureSource); } } \ No newline at end of file diff --git a/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationProvider.cs b/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationProvider.cs index 531674b..d043675 100644 --- a/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationProvider.cs +++ b/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationProvider.cs @@ -6,12 +6,23 @@ using Microsoft.Extensions.Configuration; using NeoSmart.SecureStore; + /// + /// A SecureStore file based . + /// public class SecureStoreConfigurationProvider : FileConfigurationProvider { + /// + /// Initializes a new instance with the specified source. + /// + /// The source settings. public SecureStoreConfigurationProvider(SecureStoreConfigurationSource source) : base(source) { } + /// + /// Loads the SecureStore data from a stream. + /// + /// The stream to read. public override void Load(Stream stream) { var source = (SecureStoreConfigurationSource)Source; diff --git a/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationSource.cs b/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationSource.cs index 42c48d8..9fa33ca 100644 --- a/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationSource.cs +++ b/src/SecureStore.Contrib.Configuration/SecureStoreConfigurationSource.cs @@ -2,14 +2,29 @@ { using Microsoft.Extensions.Configuration; + /// + /// Represents a SecureStore file as an . + /// public class SecureStoreConfigurationSource : FileConfigurationSource { + /// + /// The key to decrypt the SecureStore file. + /// public string Key { get; set; } + + /// + /// Determines if the key is a password or a key file. + /// public KeyType KeyType { get; set; } + /// + /// Builds the for this source. + /// + /// The . + /// A public override IConfigurationProvider Build(IConfigurationBuilder builder) { - FileProvider ??= builder.GetFileProvider(); + EnsureDefaults(builder); return new SecureStoreConfigurationProvider(this); } }