Created
February 24, 2016 00:27
-
-
Save kamranayub/eb6518356ac2b2f1a72a to your computer and use it in GitHub Desktop.
Secrets provider interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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