Skip to content

Commit

Permalink
Added Xml docs. Removing pre-release tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
gowon committed Mar 10, 2020
1 parent 2244375 commit b28851b
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
10 changes: 10 additions & 0 deletions src/SecureStore.Contrib.Configuration/KeyType.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
namespace SecureStore.Contrib.Configuration
{
/// <summary>
/// SecureStore key types.
/// </summary>
public enum KeyType
{
/// <summary>
/// File key.
/// </summary>
File,

/// <summary>
/// Password key.
/// </summary>
Password
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<NoWarn>$(NoWarn);1591</NoWarn>
<Version>1.0.0-alpha</Version>
<Version>1.0.0</Version>
<Authors>Gowon Patterson</Authors>
<Description>A SecureStore configuration provider to use with Microsoft.Extensions.Configuration.</Description>
<Copyright>© Gowon Patterson. All rights reserved.</Copyright>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,72 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.FileProviders;

/// <summary>
/// Extension methods for adding <see cref="SecureStoreConfigurationProvider"/>.
/// </summary>
public static class SecureStoreConfigurationExtensions
{
/// <summary>
/// Adds the SecureStore configuration provider at <paramref name="path"/> to <paramref name="builder"/>.
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <param name="path">Path relative to the base path stored in
/// <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>.</param>
/// <param name="key">The SecureStore key.</param>
/// <param name="keyType">The key type.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilder builder, string path,
string key, KeyType keyType)
{
return AddSecureStoreFile(builder, path, key, keyType, false);
}

/// <summary>
/// Adds the SecureStore configuration provider at <paramref name="path"/> to <paramref name="builder"/>.
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <param name="path">Path relative to the base path stored in
/// <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>.</param>
/// <param name="key">The SecureStore key.</param>
/// <param name="keyType">The key type.</param>
/// <param name="optional">Whether the file is optional.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilder builder, string path,
string key, KeyType keyType, bool optional)
{
return AddSecureStoreFile(builder, path, key, keyType, optional, false);
}

/// <summary>
/// Adds the SecureStore configuration provider at <paramref name="path"/> to <paramref name="builder"/>.
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <param name="path">Path relative to the base path stored in
/// <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>.</param>
/// <param name="key">The SecureStore key.</param>
/// <param name="keyType">The key type.</param>
/// <param name="optional">Whether the file is optional.</param>
/// <param name="reloadOnChange">Whether the configuration should be reloaded if the file changes.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilder builder, string path,
string key, KeyType keyType, bool optional,
bool reloadOnChange)
{
return AddSecureStoreFile(builder, null, path, key, keyType, optional, reloadOnChange);
}

/// <summary>
/// Adds a SecureStore configuration source to <paramref name="builder"/>.
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <param name="provider">The <see cref="IFileProvider"/> to use to access the file.</param>
/// <param name="path">Path relative to the base path stored in
/// <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>.</param>
/// <param name="key">The SecureStore key.</param>
/// <param name="keyType">The key type.</param>
/// <param name="optional">Whether the file is optional.</param>
/// <param name="reloadOnChange">Whether the configuration should be reloaded if the file changes.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilder builder,
IFileProvider provider,
string path, string key, KeyType keyType, bool optional, bool reloadOnChange)
Expand All @@ -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;
});
}

/// <summary>
/// Adds a SecureStore configuration source to <paramref name="builder"/>.
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <param name="configureSource">Configures the source.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilder builder, Action<SecureStoreConfigurationSource> configureSource)
=> builder.Add(configureSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@
using Microsoft.Extensions.Configuration;
using NeoSmart.SecureStore;

/// <summary>
/// A SecureStore file based <see cref="FileConfigurationProvider"/>.
/// </summary>
public class SecureStoreConfigurationProvider : FileConfigurationProvider
{
/// <summary>
/// Initializes a new instance with the specified source.
/// </summary>
/// <param name="source">The source settings.</param>
public SecureStoreConfigurationProvider(SecureStoreConfigurationSource source) : base(source)
{
}

/// <summary>
/// Loads the SecureStore data from a stream.
/// </summary>
/// <param name="stream">The stream to read.</param>
public override void Load(Stream stream)
{
var source = (SecureStoreConfigurationSource)Source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@
{
using Microsoft.Extensions.Configuration;

/// <summary>
/// Represents a SecureStore file as an <see cref="IConfigurationSource"/>.
/// </summary>
public class SecureStoreConfigurationSource : FileConfigurationSource
{
/// <summary>
/// The key to decrypt the SecureStore file.
/// </summary>
public string Key { get; set; }

/// <summary>
/// Determines if the key is a password or a key file.
/// </summary>
public KeyType KeyType { get; set; }

/// <summary>
/// Builds the <see cref="SecureStoreConfigurationProvider"/> for this source.
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param>
/// <returns>A <see cref="SecureStoreConfigurationProvider"/></returns>
public override IConfigurationProvider Build(IConfigurationBuilder builder)
{
FileProvider ??= builder.GetFileProvider();
EnsureDefaults(builder);
return new SecureStoreConfigurationProvider(this);
}
}
Expand Down

0 comments on commit b28851b

Please sign in to comment.