public async Task Should_retrieve_secret_using_MSI() { var provider = new KeyVaultProvider("https://keyvaultplugin.vault.azure.net/secrets/storage-connection-string/39fa2e560eaf4b8eab7bf0e1a33d2357"); var connectionString = await provider.GetConnectionString(); Assert.Equal("UseDevelopmentStorage=true", connectionString); }
internal static string GetConnectionString(Secrets secrets) { var appsettings = new AppSettings { ClientId = secrets.ClientId, ClientSecret = secrets.ClientSecret, DirectoryId = secrets.DirectoryId, SecretName = secrets.SecretName, KeyVaultUrl = secrets.KeyVaultUrl }; return(KeyVaultProvider.GetConnectionString(appsettings)); }
public async Task Should_retrieve_secret_using_application_id_and_key_vault_secret() { var environmentVariable = Environment.GetEnvironmentVariable("AzureServicesAuthConnectionString", EnvironmentVariableTarget.Machine); //"RunAs=App;AppId=aabbccdd-1234-5678-90ab-ffeeddccbbaa;TenantId=aabbccdd-1234-5678-90ab-ffeeddccbbaa;AppKey=oiafQ#jafi0a9fu#kaofjas43ifj@jasdf09jlakjsd=" var elements = environmentVariable.Split(';'); var clientId = elements[1].Replace("AppId=", string.Empty); var clientSecret = elements[3].Replace("AppKey=", string.Empty); var provider = new KeyVaultProvider(clientId: clientId, clientSecret: clientSecret, secretIdentifier: "https://keyvaultplugin.vault.azure.net/secrets/storage-connection-string/39fa2e560eaf4b8eab7bf0e1a33d2357"); var connectionString = await provider.GetConnectionString(); Assert.Equal("UseDevelopmentStorage=true", connectionString); }
public override void Initialize(string name, NameValueCollection config) { try { // this should be moved to another entry point hook, but this is the easiest way for now. AzureKeyVaultConfigurationProvider.Initialize(); var connectionString = KeyVaultProvider.GetConnectionString(); config.Add(ConnectionStringName, connectionString); base.Initialize(name, config); } catch (KeyMasterException ex) { var logger = LoggerSource.Instance.GetLogger("KeyMaster"); logger.Fatal("Unrecoverable Key Master error", ex); throw ex; } }