From 35965591f57d941931bf8ca5034edf09a9c02193 Mon Sep 17 00:00:00 2001 From: Sergio Matias Date: Sun, 20 Jul 2025 20:42:52 -0600 Subject: [PATCH] Stryong typed keyvault response --- .../Contracts/IKeyVaultProvider.cs | 6 +++--- Core.Blueprint.KeyVault/Provider/KeyVaultProvider.cs | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Core.Blueprint.KeyVault/Contracts/IKeyVaultProvider.cs b/Core.Blueprint.KeyVault/Contracts/IKeyVaultProvider.cs index b0025c6..a6067fe 100644 --- a/Core.Blueprint.KeyVault/Contracts/IKeyVaultProvider.cs +++ b/Core.Blueprint.KeyVault/Contracts/IKeyVaultProvider.cs @@ -22,7 +22,7 @@ namespace Core.Blueprint.KeyVault /// /// A containing a status message and a boolean indicating whether the secret was successfully deleted. /// - ValueTask> DeleteSecretAsync(string secretName, CancellationToken cancellationToken); + ValueTask<(string Message, bool Deleted)> DeleteSecretAsync(string secretName, CancellationToken cancellationToken); /// /// Retrieves a secret from Azure Key Vault. @@ -33,7 +33,7 @@ namespace Core.Blueprint.KeyVault /// A containing the with secret details /// and an optional error message if the secret was not found. /// - ValueTask> GetSecretAsync(string secretName, CancellationToken cancellationToken); + ValueTask<(KeyVaultResponse Secret, string? Message)> GetSecretAsync(string secretName, CancellationToken cancellationToken); /// /// Updates an existing secret in Azure Key Vault. If the secret does not exist, an error is returned. @@ -43,6 +43,6 @@ namespace Core.Blueprint.KeyVault /// /// A containing the updated and an optional error message if the secret was not found. /// - ValueTask> UpdateSecretAsync(KeyVaultRequest newSecret, CancellationToken cancellationToken); + ValueTask<(KeyVaultResponse Secret, string? Message)> UpdateSecretAsync(KeyVaultRequest newSecret, CancellationToken cancellationToken); } } diff --git a/Core.Blueprint.KeyVault/Provider/KeyVaultProvider.cs b/Core.Blueprint.KeyVault/Provider/KeyVaultProvider.cs index e20a9bc..c0cf4fa 100644 --- a/Core.Blueprint.KeyVault/Provider/KeyVaultProvider.cs +++ b/Core.Blueprint.KeyVault/Provider/KeyVaultProvider.cs @@ -1,10 +1,10 @@ using Azure.Security.KeyVault.Secrets; -using VaultSharp; -using VaultSharp.V1.AuthMethods.Token; using Core.Blueprint.KeyVault.Configuration; using Microsoft.Extensions.Configuration; using System.Net.Http.Json; +using VaultSharp; using VaultSharp.Core; +using VaultSharp.V1.AuthMethods.Token; namespace Core.Blueprint.KeyVault; @@ -67,7 +67,7 @@ public sealed class KeyVaultProvider : IKeyVaultProvider /// /// A containing a status message and a boolean indicating whether the secret was successfully deleted. /// - public async ValueTask> DeleteSecretAsync(string secretName, CancellationToken cancellationToken) + public async ValueTask<(string Message, bool Deleted)> DeleteSecretAsync(string secretName, CancellationToken cancellationToken) { if (environment == "Local") { @@ -88,7 +88,7 @@ public sealed class KeyVaultProvider : IKeyVaultProvider /// /// Retrieves a secret from Azure Key Vault or HashiCorp Vault. /// - public async ValueTask> GetSecretAsync(string secretName, CancellationToken cancellationToken) + public async ValueTask<(KeyVaultResponse Secret, string? Message)> GetSecretAsync(string secretName, CancellationToken cancellationToken) { if (environment == "Local") { @@ -108,7 +108,7 @@ public sealed class KeyVaultProvider : IKeyVaultProvider } catch (VaultSharp.Core.VaultApiException ex) when (ex.HttpStatusCode == System.Net.HttpStatusCode.NotFound) { - return new(new KeyVaultResponse(), "Key Not Found"); + return new(new KeyVaultResponse { }, "Key Not Found"); } } @@ -126,7 +126,7 @@ public sealed class KeyVaultProvider : IKeyVaultProvider /// /// Updates an existing secret in Azure Key Vault or HashiCorp Vault. If the secret does not exist, an error is returned. /// - public async ValueTask> UpdateSecretAsync(KeyVaultRequest newSecret, CancellationToken cancellationToken) + public async ValueTask<(KeyVaultResponse Secret, string? Message)> UpdateSecretAsync(KeyVaultRequest newSecret, CancellationToken cancellationToken) { var existingSecret = await this.GetSecretAsync(newSecret.Name, cancellationToken); if (!string.IsNullOrEmpty(existingSecret.Item2)) -- 2.49.1