Ejemplo n.º 1
0
        private async Task ProcessNewOrderAsync(byte[] rawOrder)
        {
            var connectionString = await secretProvider.GetSecretAsync(SecretName);

            var retryPolicy = Policy.Handle <UnauthorizedAccessException>()
                              .RetryAsync(retryCount: 5, onRetryAsync: async(exception, retryCount, context) =>
            {
                telemetryProvider.LogTrace($"Unauthorized to access Azure Service Bus. Reading latest key from Key Vault");
                connectionString = await secretProvider.GetSecretAsync(SecretName, ignoreCache: true);
            });

            await retryPolicy.ExecuteAsync(async() => await QueueMessageAsync(rawOrder, connectionString));
        }
        private async Task ProcessNewOrderAsync(byte[] rawOrder)
        {
            var connectionString = await secretProvider.GetSecretAsync(SecretName);

            var retryPolicy = Policy.Handle <UnauthorizedAccessException>()
                              .RetryAsync(retryCount: 5, onRetryAsync: async(exception, retryCount, context) => connectionString = await secretProvider.GetSecretAsync(SecretName, ignoreCache: true));

            await retryPolicy.ExecuteAsync(async() => await QueueMessageAsync(rawOrder, connectionString));
        }
        /// <summary>
        /// Retrieves the secret value, based on the given name
        /// </summary>
        /// <param name="secretName">The name of the secret key</param>
        /// <param name="ignoreCache">Indicates if the cache should be used or skipped</param>
        /// <returns>Returns a <see cref="Task{TResult}"/> that contains the secret key</returns>
        /// <exception cref="ArgumentException">The name must not be empty</exception>
        /// <exception cref="ArgumentNullException">The name must not be null</exception>
        /// <exception cref="SecretNotFoundException">The secret was not found, using the given name</exception>
        public async Task <Secret> GetSecretAsync(string secretName, bool ignoreCache)
        {
            Guard.NotNullOrWhitespace(secretName, nameof(secretName), "Requires a non-blank secret name when mutating secret names");

            Secret secret = await SafeguardMutateSecretAsync(secretName, mutatedSecretName =>
            {
                return(_implementation.GetSecretAsync(mutatedSecretName, ignoreCache));
            });

            return(secret);
        }
 /// <summary>
 /// Retrieves the secret value, based on the given name.
 /// </summary>
 /// <param name="secretName">The name of the secret key</param>
 /// <param name="ignoreCache">Indicates if the cache should be used or skipped</param>
 /// <returns>Returns a <see cref="T:System.Threading.Tasks.Task`1" /> that contains the secret key</returns>
 /// <exception cref="T:System.ArgumentException">The name must not be empty</exception>
 /// <exception cref="T:System.ArgumentNullException">The name must not be null</exception>
 /// <exception cref="T:Arcus.Security.Core.SecretNotFoundException">The secret was not found, using the given name</exception>
 public async Task <Secret> GetSecretAsync(string secretName, bool ignoreCache)
 {
     Guard.NotNullOrWhitespace(secretName, nameof(secretName), "Requires a non-blank secret name to access the secret");
     return(await WhenAuthorized(() => _cachedSecretProvider.GetSecretAsync(secretName, ignoreCache)));
 }