public SecretService(Configuration config) { var tokenProvider = ResolveTokenProvider(config); _client = new AuthedClient(tokenProvider); _vaultAliases = config.VaultAliases; }
public void GivenAConfig_ThenTheMockValuesAreReplacedFromKeyVault() { var service = Substitute.For <ISecretService>(); var client = Substitute.For <IKeyVaultClient>(); client.GetSecretWithHttpMessagesAsync(Arg.Any <string>(), Arg.Is("test1"), Arg.Any <string>(), Arg.Any <Dictionary <string, List <string> > >(), Arg.Any <CancellationToken>()) .Returns(Task.FromResult(new AzureOperationResponse <SecretBundle> { Body = new SecretBundle("secret1") })); var authedClient = new AuthedClient(client); var reader = new ReadKey(authedClient, "keyvaultbuild", "test1"); service.ResolveSingleKey(Arg.Is("#{keyvault:keyvaultbuild:test1}")).Returns(reader); var keys = new TransformKeys(service); var snippet = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <appSettings> <add key=""key1"" value=""#{keyvault:keyvaultbuild:test1}"" /> </appSettings> </configuration>"; var expected = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <appSettings> <add key=""key1"" value=""secret1"" /> </appSettings> </configuration>"; var val = keys.ReplaceKeys(snippet); Assert.AreEqual(expected, val); }
public SecretService(AuthedClient client, IDictionary <string, string> vaultAliases = null) { _client = client; _vaultAliases = vaultAliases ?? new Dictionary <string, string>(); }