/// <summary> /// Stores a secret value with a given secret name. /// </summary> /// <param name="secretName">The name of the secret.</param> /// <param name="secretValue">The value of the secret.</param> /// <returns>Returns a <see cref="Secret"/> that contains the latest information for the given secret.</returns> /// <exception cref="ArgumentException">Thrown when the <paramref name="secretName"/> or the <paramref name="secretValue"/> is blank.</exception> /// <exception cref="SecretNotFoundException">Thrown when the secret was not found, using the given <paramref name="secretName"/>.</exception> /// <exception cref="KeyVaultErrorException">Thrown when the call for a secret resulted in an invalid Azure Key Vault response.</exception> public virtual async Task <Secret> StoreSecretAsync(string secretName, string secretValue) { Guard.NotNullOrWhitespace(secretName, nameof(secretName), "Requires a non-blank secret name to request a secret in Azure Key Vault"); Guard.NotNullOrWhitespace(secretValue, nameof(secretValue), "Requires a non-blank secret value to store a secret in Azure Key Vault"); Secret secret = await _secretProvider.StoreSecretAsync(secretName, secretValue); MemoryCache.Set(secretName, secret, CacheEntry); return(secret); }
/// <summary> /// Stores a secret value with a given secret name. /// </summary> /// <param name="secretName">The name of the secret.</param> /// <param name="secretValue">The value of the secret.</param> /// <returns>Returns a <see cref="Secret"/> that contains the latest information for the given secret.</returns> /// <exception cref="ArgumentException">Thrown when the <paramref name="secretName"/> or the <paramref name="secretValue"/> is blank.</exception> /// <exception cref="SecretNotFoundException">Thrown when the secret was not found, using the given <paramref name="secretName"/>.</exception> /// <exception cref="KeyVaultErrorException">Thrown when the call for a secret resulted in an invalid Azure Key Vault response.</exception> public virtual async Task <Secret> StoreSecretAsync(string secretName, string secretValue) { Guard.NotNullOrWhitespace(secretName, nameof(secretName), "Requires a non-blank secret name to request a secret in Azure Key Vault"); Guard.NotNullOrWhitespace(secretValue, nameof(secretValue), "Requires a non-blank secret value to store a secret in Azure Key Vault"); Guard.For <FormatException>(() => !SecretNameRegex.IsMatch(secretName), "Requires a secret name in the correct format to request a secret in Azure Key Vault, see https://docs.microsoft.com/en-us/azure/key-vault/general/about-keys-secrets-certificates#objects-identifiers-and-versioning"); Secret secret = await _secretProvider.StoreSecretAsync(secretName, secretValue); MemoryCache.Set(secretName, secret, CacheEntry); return(secret); }