Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Secrets provider interface
public class ConfigSecretsProvider : ISecretsProvider
{
private readonly NameValueCollection _secretCollection;
public ConfigSecretsProvider() {
_secretCollection = ConfigurationManager.GetSection("appSecrets") as NameValueCollection;
}
public string GetSecret(string key) {
return Environment.GetEnvironmentVariable(key) ?? _secretCollection[key];
}
public Task<string> GetSecretAsync(string key)
{
return Task.FromResult(GetSecret(key));
}
}
public interface ISecretsProvider
{
/// <summary>
/// Retrieves a secret by key
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
string GetSecret(string key);
/// <summary>
/// Retrieves a secret by key (async)
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
Task<string> GetSecretAsync(string key);
}
<!-- Example -->
<configuration>
<configSections>
<section name="appSecrets" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<appSettings>
<!-- No longer has secrets! -->
</appSettings>
<appSecrets>
<add key="FooSecret" value="SuperSecret"/>
</appSecrets>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.