示例#1
0
        public override async Task RunAsync(CancellationToken cancellationToken)
        {
            var keyVaultUri = GetEnvironmentVariable("KEYVAULT_URL");
            var client      = new MiniSecretClient(new Uri(keyVaultUri), new DefaultAzureCredential());

            while (!cancellationToken.IsCancellationRequested)
            {
                try
                {
                    // Throttle requests to avoid exceeding service limits
                    await Task.Delay(TimeSpan.FromMilliseconds(Options.Delay), cancellationToken);

                    var secret = await client.GetSecretAsync(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);
                }
            }
        }
示例#2
0
        public void GettingASecret()
        {
            var endpoint = TestEnvironment.KeyVaultUri;

            #region Snippet:GetSecret
            var client = new MiniSecretClient(new Uri(endpoint), new DefaultAzureCredential());

            SecretBundle secret = client.GetSecret("TestSecret");

            Console.WriteLine(secret.Value);
            #endregion
        }
        public async Task GettingASecretAsync()
        {
            var endpoint = TestEnvironment.KeyVaultUri;

            #region Snippet:GetSecretAsync
#if SNIPPET
            string endpoint = "https://myvault.vault.azure.net";
#endif
            var client = new MiniSecretClient(new Uri(endpoint), new DefaultAzureCredential());

            SecretBundle secret = await client.GetSecretAsync("TestSecret");

            Console.WriteLine(secret.Value);
            #endregion

            Assert.NotNull(secret.Value);
        }
        public MiniSecretClientTest(MiniSecretClientOptions options) : base(options)
        {
            var keyVaultUri = GetEnvironmentVariable("KEYVAULT_URL");

            _miniSecretClient = new MiniSecretClient(new Uri(keyVaultUri), new DefaultAzureCredential());
        }