diff --git a/docs/preview/features/secret-store/provider/key-vault.md b/docs/preview/features/secret-store/provider/key-vault.md index b5790304..8c17fb71 100644 --- a/docs/preview/features/secret-store/provider/key-vault.md +++ b/docs/preview/features/secret-store/provider/key-vault.md @@ -17,6 +17,7 @@ PM > Install-Package Arcus.Security.Providers.AzureKeyVault After installing the package, the addtional extensions becomes available when building the secret store. ```csharp +using Arcus.Security.Core.Caching.Configuration; using Microsoft.Extensions.Hosting; public class Program @@ -48,7 +49,7 @@ public class Program builder.AddAzureKeyVault(vaultAuthentication, vaultConfiguration); // Adding a default cached variant of the Azure Key Vault provider (default: 5 min caching). - builder.AddAzureKeyVaultWithManagedIdentity(keyVaultUri, allowCaching: true); + builder.AddAzureKeyVaultWithManagedIdentity(keyVaultUri, cacheConfiguration: CacheConfiguration.Default); // Assing a configurable cached variant of the Azure Key Vault provider. var cacheConfiguration = new CacheConfiguration(TimeSpan.FromMinutes(1)); diff --git a/src/Arcus.Security.Core/Caching/CachedSecretProvider.cs b/src/Arcus.Security.Core/Caching/CachedSecretProvider.cs index 962a2209..31e71844 100644 --- a/src/Arcus.Security.Core/Caching/CachedSecretProvider.cs +++ b/src/Arcus.Security.Core/Caching/CachedSecretProvider.cs @@ -62,7 +62,7 @@ public CachedSecretProvider(ISecretProvider secretProvider, ICacheConfiguration /// /// Thrown when the is null. public CachedSecretProvider(ISecretProvider secretProvider) : - this(secretProvider, new CacheConfiguration(), new MemoryCache(new MemoryCacheOptions())) + this(secretProvider, CacheConfiguration.Default, new MemoryCache(new MemoryCacheOptions())) { } diff --git a/src/Arcus.Security.Core/Caching/Configuration/CacheConfiguration.cs b/src/Arcus.Security.Core/Caching/Configuration/CacheConfiguration.cs index 782df1d7..5fcb8593 100644 --- a/src/Arcus.Security.Core/Caching/Configuration/CacheConfiguration.cs +++ b/src/Arcus.Security.Core/Caching/Configuration/CacheConfiguration.cs @@ -9,28 +9,32 @@ namespace Arcus.Security.Core.Caching.Configuration public class CacheConfiguration : ICacheConfiguration { /// - /// Duration for which an entry should be cached + /// Initializes a new instance of the class with default cache entry of 5 minutes. /// - public TimeSpan Duration { get; } + [Obsolete ("Use the " + nameof(Default) + " static property to retrieve a default caching configuration instance")] + public CacheConfiguration() : this(TimeSpan.FromMinutes(5)) + { + } /// - /// Constructor + /// Initializes a new instance of the class. /// /// Duration for which an entry should be cached /// Thrown when the cache duration is not a positive time duration. public CacheConfiguration(TimeSpan duration) { Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration in which the caching should take place"); - Duration = duration; } /// - /// Constructor with default cache entry of 5 minutes + /// Gets the default that takes in 5 minutes as default cache duration. /// - public CacheConfiguration() - { - Duration = TimeSpan.FromMinutes(5); - } + public static ICacheConfiguration Default { get; } = new CacheConfiguration(TimeSpan.FromMinutes(5)); + + /// + /// Gets the duration for which an entry should be cached. + /// + public TimeSpan Duration { get; } } -} \ No newline at end of file +} diff --git a/src/Arcus.Security.Core/Caching/Configuration/ICacheConfiguration.cs b/src/Arcus.Security.Core/Caching/Configuration/ICacheConfiguration.cs index 897cf1b9..388efaff 100644 --- a/src/Arcus.Security.Core/Caching/Configuration/ICacheConfiguration.cs +++ b/src/Arcus.Security.Core/Caching/Configuration/ICacheConfiguration.cs @@ -8,7 +8,7 @@ namespace Arcus.Security.Core.Caching.Configuration public interface ICacheConfiguration { /// - /// Duration for which an entry should be cached + /// Gets the duration for which an entry should be cached. /// TimeSpan Duration { get; } } diff --git a/src/Arcus.Security.Core/Caching/SecretProviderCachingExtensions.cs b/src/Arcus.Security.Core/Caching/SecretProviderCachingExtensions.cs index c47f0af1..a139a453 100644 --- a/src/Arcus.Security.Core/Caching/SecretProviderCachingExtensions.cs +++ b/src/Arcus.Security.Core/Caching/SecretProviderCachingExtensions.cs @@ -24,7 +24,7 @@ public static ICachedSecretProvider WithCaching(this ISecretProvider secretProvi Guard.NotNull(secretProvider, nameof(secretProvider), "Requires a secret provider instance to include caching while retrieving secrets"); Guard.NotLessThan(cachingDuration, TimeSpan.Zero, nameof(cachingDuration), "Requires a positive time duration in which the caching should take place"); Guard.NotNull(memoryCache, nameof(memoryCache), "Requires a memory caching implementation to include caching while retrieving secrets"); - + return new CachedSecretProvider(secretProvider, new CacheConfiguration(cachingDuration), memoryCache); } @@ -41,7 +41,7 @@ public static ICachedSecretProvider WithCaching(this ISecretProvider secretProvi { Guard.NotNull(secretProvider, nameof(secretProvider), "Requires a secret provider instance to include caching while retrieving secrets"); Guard.NotLessThan(cachingDuration, TimeSpan.Zero, nameof(cachingDuration), "Requires a positive time duration in which the caching should take place"); - + return new CachedSecretProvider(secretProvider, new CacheConfiguration(cachingDuration)); } @@ -55,7 +55,7 @@ public static ICachedSecretProvider WithCaching(this ISecretProvider secretProvi public static ICachedSecretProvider WithCaching(this ISecretProvider secretProvider) { Guard.NotNull(secretProvider, nameof(secretProvider), "Requires a secret provider instance to include caching while retrieving secrets"); - + return new CachedSecretProvider(secretProvider); } } diff --git a/src/Arcus.Security.Providers.AzureKeyVault/Extensions/SecretStoreBuilderExtensions.cs b/src/Arcus.Security.Providers.AzureKeyVault/Extensions/SecretStoreBuilderExtensions.cs index 83b066fe..3afd6176 100644 --- a/src/Arcus.Security.Providers.AzureKeyVault/Extensions/SecretStoreBuilderExtensions.cs +++ b/src/Arcus.Security.Providers.AzureKeyVault/Extensions/SecretStoreBuilderExtensions.cs @@ -2,8 +2,6 @@ using System.Net; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; -using Arcus.Security.Core; -using Arcus.Security.Core.Caching; using Arcus.Security.Core.Caching.Configuration; using Arcus.Security.Providers.AzureKeyVault; using Arcus.Security.Providers.AzureKeyVault.Authentication; @@ -102,6 +100,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithCertificateWithOptions( /// The flag to indicate whether to include caching during secret retrieval in Azure key vault. /// Thrown when the or is null. /// Thrown when the or is blank. + [Obsolete("Use the " + nameof(AddAzureKeyVaultWithCertificate) + " method overload with " + nameof(CacheConfiguration.Default) + " instead to allow default caching")] public static SecretStoreBuilder AddAzureKeyVaultWithCertificate( this SecretStoreBuilder builder, string rawVaultUri, @@ -142,6 +141,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithCertificate( /// The optional function to mutate the secret name before looking it up. /// Thrown when the or is null. /// Thrown when the or is blank. + [Obsolete("Use the " + nameof(AddAzureKeyVaultWithCertificate) + " method overload with " + nameof(CacheConfiguration.Default) + " instead to allow default caching")] public static SecretStoreBuilder AddAzureKeyVaultWithCertificate( this SecretStoreBuilder builder, string rawVaultUri, @@ -242,7 +242,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithCertificateWithOptions( /// The Azure Active Directory tenant (directory) ID of the client or application. /// The identifier of the application requesting the authentication token. /// The certificate that is used as credential. - /// The configuration to control how the caching will be done. + /// The configuration to control how the caching will be done, use the for default caching. /// Thrown when the or is null. /// Thrown when the or is blank. public static SecretStoreBuilder AddAzureKeyVaultWithCertificate( @@ -279,7 +279,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithCertificate( /// The Azure Active Directory tenant (directory) ID of the client or application. /// The identifier of the application requesting the authentication token. /// The certificate that is used as credential. - /// The configuration to control how the caching will be done. + /// The configuration to control how the caching will be done, use the for default caching. /// The optional additional options to configure the Azure Key Vault secret source. /// The unique name to register this Azure Key Vault provider in the secret store. /// The optional function to mutate the secret name before looking it up. @@ -382,6 +382,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithManagedServiceIdentityWithO /// The flag to indicate whether to include caching during secret retrieval in Azure key vault. /// Thrown when the is null. /// Thrown when the is blank. + [Obsolete("Use the " + nameof(AddAzureKeyVaultWithManagedIdentity) + " method overload with " + nameof(CacheConfiguration.Default) + " instead to allow default caching")] public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( this SecretStoreBuilder builder, string rawVaultUri, @@ -404,6 +405,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( /// The flag to indicate whether to include caching during secret retrieval in Azure key vault. /// Thrown when the is null. /// Thrown when the is blank. + [Obsolete("Use the " + nameof(AddAzureKeyVaultWithManagedIdentity) + " method overload with " + nameof(CacheConfiguration.Default) + " instead to allow default caching")] public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( this SecretStoreBuilder builder, string rawVaultUri, @@ -434,6 +436,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( /// The optional function to mutate the secret name before looking it up. /// Thrown when the is null. /// Thrown when the is blank. + [Obsolete("Use the " + nameof(AddAzureKeyVaultWithManagedIdentity) + " method overload with " + nameof(CacheConfiguration.Default) + " instead to allow default caching")] public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( this SecretStoreBuilder builder, string rawVaultUri, @@ -469,6 +472,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( /// The optional function to mutate the secret name before looking it up. /// Thrown when the is null. /// Thrown when the is blank. + [Obsolete("Use the " + nameof(AddAzureKeyVaultWithManagedIdentity) + " method overload with " + nameof(CacheConfiguration.Default) + " instead to allow default caching")] public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( this SecretStoreBuilder builder, string rawVaultUri, @@ -520,7 +524,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithManagedServiceIdentity( /// /// The builder to create the secret store. /// The Uri of the Azure Key Vault you want to connect to. - /// The configuration to control how the caching will be done. + /// The configuration to control how the caching will be done, use the for default caching. /// The connection string to use to authenticate, if applicable. /// The azure AD instance to use to authenticate, if applicable. /// The optional function to mutate the secret name before looking it up. @@ -558,7 +562,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithManagedServiceIdentityWithO /// /// The builder to create the secret store. /// The Uri of the Azure Key Vault you want to connect to. - /// The configuration to control how the caching will be done. + /// The configuration to control how the caching will be done, use the for default caching. /// Thrown when the is null. /// Thrown when the is blank. public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( @@ -584,7 +588,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( /// /// The optional client id to authenticate for a user assigned managed identity. /// More information on user assigned managed identities can be found here: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview#how-a-user-assigned-managed-identity-works-with-an-azure-vm - /// The configuration to control how the caching will be done. + /// The configuration to control how the caching will be done, use the for default caching. /// Thrown when the is null. /// Thrown when the is blank. public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( @@ -611,7 +615,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( /// /// The builder to create the secret store. /// The Uri of the Azure Key Vault you want to connect to. - /// The configuration to control how the caching will be done. + /// The configuration to control how the caching will be done, use the for default caching. /// The optional additional options to configure the Azure Key Vault secret source. /// The unique name to register this Azure Key Vault provider in the secret store. /// The optional function to mutate the secret name before looking it up. @@ -646,7 +650,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithManagedIdentity( /// /// The optional client id to authenticate for a user assigned managed identity. /// More information on user assigned managed identities can be found here: https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview#how-a-user-assigned-managed-identity-works-with-an-azure-vm - /// The configuration to control how the caching will be done. + /// The configuration to control how the caching will be done, use the for default caching. /// The optional additional options to configure the Azure Key Vault secret source. /// The unique name to register this Azure Key Vault provider in the secret store. /// The optional function to mutate the secret name before looking it up. @@ -751,6 +755,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithServicePrincipalWithOptions /// The flag to indicate whether to include caching during secret retrieval in Azure key vault. /// Thrown when the is null. /// Thrown when the , , or is blank. + [Obsolete("Use the " + nameof(AddAzureKeyVaultWithServicePrincipal) + " method overload with " + nameof(CacheConfiguration.Default) + " instead to allow default caching")] public static SecretStoreBuilder AddAzureKeyVaultWithServicePrincipal( this SecretStoreBuilder builder, string rawVaultUri, @@ -791,6 +796,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithServicePrincipal( /// The optional function to mutate the secret name before looking it up. /// Thrown when the is null. /// Thrown when the , , or is blank. + [Obsolete("Use the " + nameof(AddAzureKeyVaultWithServicePrincipal) + " method overload with " + nameof(CacheConfiguration.Default) + " instead to allow default caching")] public static SecretStoreBuilder AddAzureKeyVaultWithServicePrincipal( this SecretStoreBuilder builder, string rawVaultUri, @@ -892,7 +898,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithServicePrincipalWithOptions /// The Azure Active Directory tenant (directory) Id of the service principal. /// The ClientId of the service principal, used to connect to Azure Key Vault /// The Secret ClientKey of the service principal, used to connect to Azure Key Vault - /// The configuration to control how the caching will be done. + /// The configuration to control how the caching will be done, use the for default caching. /// Thrown when the is null. /// Thrown when the , , or is blank. public static SecretStoreBuilder AddAzureKeyVaultWithServicePrincipal( @@ -929,7 +935,7 @@ public static SecretStoreBuilder AddAzureKeyVaultWithServicePrincipal( /// The Azure Active Directory tenant (directory) Id of the service principal. /// The ClientId of the service principal, used to connect to Azure Key Vault /// The Secret ClientKey of the service principal, used to connect to Azure Key Vault - /// The configuration to control how the caching will be done. + /// The configuration to control how the caching will be done, use the for default caching. /// The optional additional options to configure the Azure Key Vault secret source. /// The unique name to register this Azure Key Vault provider in the secret store. /// The optional function to mutate the secret name before looking it up. @@ -1066,7 +1072,7 @@ private static SecretStoreBuilder AddAzureKeyVault( Func mutateSecretName = null, Action configureOptions = null) { - ICacheConfiguration cacheConfiguration = allowCaching ? new CacheConfiguration() : null; + ICacheConfiguration cacheConfiguration = allowCaching ? CacheConfiguration.Default : null; return AddAzureKeyVault(builder, createAuthentication, configuration, cacheConfiguration, mutateSecretName, configureOptions); } @@ -1119,6 +1125,7 @@ private static SecretStoreBuilder AddAzureKeyVault( /// The configuration related to the Azure Key Vault instance to use. /// The flag to indicate whether to include caching during secret retrieval in Azure key vault. /// Thrown when the , , or is null. + [Obsolete("Use the " + nameof(AddAzureKeyVault) + " method overload with " + nameof(CacheConfiguration.Default) + " instead to allow default caching")] public static SecretStoreBuilder AddAzureKeyVault( this SecretStoreBuilder builder, TokenCredential tokenCredential, @@ -1150,6 +1157,7 @@ public static SecretStoreBuilder AddAzureKeyVault( /// The unique name to register this Azure Key Vault provider in the secret store. /// The optional function to mutate the secret name before looking it up. /// Thrown when the , , or is null. + [Obsolete("Use the " + nameof(AddAzureKeyVault) + " method overload with " + nameof(CacheConfiguration.Default) + " instead to allow default caching")] public static SecretStoreBuilder AddAzureKeyVault( this SecretStoreBuilder builder, TokenCredential tokenCredential, @@ -1163,7 +1171,7 @@ public static SecretStoreBuilder AddAzureKeyVault( Guard.NotNull(tokenCredential, nameof(tokenCredential), "Requires an Azure Key Vault authentication instance to add the secret provider to the secret store"); Guard.NotNull(configuration, nameof(configuration), "Requires an Azure Key Vault configuration instance to add the secret provider to the secret store"); - ICacheConfiguration cacheConfiguration = allowCaching ? new CacheConfiguration() : null; + ICacheConfiguration cacheConfiguration = allowCaching ? CacheConfiguration.Default : null; return AddAzureKeyVault(builder, tokenCredential, configuration, cacheConfiguration, configureOptions, name, mutateSecretName); } @@ -1173,7 +1181,7 @@ public static SecretStoreBuilder AddAzureKeyVault( /// The builder to create the secret store. /// The requested authentication type for connecting to the Azure Key Vault instance. /// The configuration related to the Azure Key Vault instance to use. - /// The configuration to control how the caching will be done. + /// The configuration to control how the caching will be done, use the for default caching. /// Thrown when the , , or is null. public static SecretStoreBuilder AddAzureKeyVault( this SecretStoreBuilder builder, @@ -1201,7 +1209,7 @@ public static SecretStoreBuilder AddAzureKeyVault( /// The builder to create the secret store. /// The requested authentication type for connecting to the Azure Key Vault instance. /// The configuration related to the Azure Key Vault instance to use. - /// The configuration to control how the caching will be done. + /// The configuration to control how the caching will be done, use the for default caching. /// The optional additional options to configure the Azure Key Vault secret source. /// The unique name to register this Azure Key Vault provider in the secret store. /// The optional function to mutate the secret name before looking it up.