public override async Task RunAsync(CancellationToken cancellationToken) { string keyVaultUri = GetEnvironmentVariable("KEYVAULT_URL"); TemplateClient client = new TemplateClient(keyVaultUri, new DefaultAzureCredential()); while (!cancellationToken.IsCancellationRequested) { try { // Throttle requests to avoid exceeding service limits await Task.Delay(TimeSpan.FromMilliseconds(Options.Delay), cancellationToken); Response <SecretBundle> secret = await client.GetSecretValueAsync(Options.SecretName, cancellationToken); Interlocked.Increment(ref Metrics.SecretsReceived); if (secret.Value.Value == "TestValue") { Interlocked.Increment(ref Metrics.CorrectValues); } else { Interlocked.Increment(ref Metrics.IncorrectValues); } } catch (Exception e) when(ContainsOperationCanceledException(e)) { } catch (Exception e) { Metrics.Exceptions.Enqueue(e); } } }
public async Task CanGetSecret() { TemplateClient client = CreateClient(); Response <SecretBundle> secret = await client.GetSecretValueAsync("TestSecret"); Assert.AreEqual("Very secret value", secret.Value.Value); }
public async Task GettingASecretAsync() { #region Snippet:Azure_Template_GetSecretAsync #if SNIPPET string endpoint = "https://myvault.vault.azure.net"; var credential = new DefaultAzureCredential(); #else string endpoint = TestEnvironment.KeyVaultUri; var credential = TestEnvironment.Credential; #endif var client = new TemplateClient(endpoint, credential); SecretBundle secret = await client.GetSecretValueAsync("TestSecret"); Console.WriteLine(secret.Value); #endregion Assert.NotNull(secret.Value); }