/// <summary>
        /// Initializes a new instance of the <see cref="AuthorizedSecretProvider"/> class.
        /// </summary>
        /// <param name="permittedRole">The role that is required to access the <paramref name="secretProvider"/>.</param>
        /// <param name="authorization">The instance to determine if the <paramref name="permittedRole"/> is considered authorized.</param>
        /// <param name="secretProvider">The actual provider to access the secrets.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="authorization"/> or <paramref name="secretProvider"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="permittedRole"/> is outside the bounds of the enumeration.</exception>
        public AuthorizedSecretProvider(Role permittedRole, IRoleAuthorization authorization, ISecretProvider secretProvider)
        {
            Guard.NotNull(authorization, nameof(authorization), "Requires an instance to determine if the current role is considered authorized");
            Guard.NotNull(secretProvider, nameof(secretProvider), "Requires an instance to access the authorized secrets");
            Guard.For <ArgumentOutOfRangeException>(() => !Enum.IsDefined(typeof(Role), permittedRole), "Requires the role to be inside the bounds of the enumeration");

            _permittedRole  = permittedRole;
            _authorization  = authorization;
            _secretProvider = secretProvider;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthorizedSecretProvider"/> class.
 /// </summary>
 /// <param name="permittedRole">The role that is required to access the <paramref name="cachedSecretProvider"/>.</param>
 /// <param name="authorization">The instance to determine if the <paramref name="permittedRole"/> is considered authorized.</param>
 /// <param name="cachedSecretProvider">The actual provider to access the secrets.</param>
 /// <exception cref="ArgumentNullException">Thrown when the <paramref name="authorization"/> or <paramref name="cachedSecretProvider"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="permittedRole"/> is outside the bounds of the enumeration.</exception>
 public AuthorizedCachedSecretProvider(Role permittedRole, IRoleAuthorization authorization, ICachedSecretProvider cachedSecretProvider)
     : base(permittedRole, authorization, cachedSecretProvider)
 {
     Guard.NotNull(cachedSecretProvider, nameof(cachedSecretProvider), "Requires an instance to access the authorized secrets");
     _cachedSecretProvider = cachedSecretProvider;
 }
Ejemplo n.º 3
0
        private static ISecretProvider CreateAuthorizedSecretProvider(SecretStoreSource source, Role role, IRoleAuthorization authorization)
        {
            if (source.CachedSecretProvider is null)
            {
                return(new AuthorizedSecretProvider(role, authorization, source.SecretProvider));
            }

            return(new AuthorizedCachedSecretProvider(role, authorization, source.CachedSecretProvider));
        }