diff --git a/src/Confix.Tool/src/Confix.Library/ThrowHelper.cs b/src/Confix.Tool/src/Confix.Library/ThrowHelper.cs index 3d8500f5..f048caa9 100644 --- a/src/Confix.Tool/src/Confix.Library/ThrowHelper.cs +++ b/src/Confix.Tool/src/Confix.Library/ThrowHelper.cs @@ -41,8 +41,11 @@ public static Exception VariablesNotFound(string[] names) => public static Exception CouldNotParseJsonFile(FileInfo file) => throw new ExitException($"File {file.FullName} has invalid content."); - public static Exception SecretNotFound(Exception innerException) => - new ExitException("Secret does not exist in this provider.", innerException) + public static Exception SecretNotFound(Exception innerException, string? path = null) => + new ExitException( + path is null + ? "Secret does not exist in this provider." + : $"Secret {path.AsHighlighted()} does not exist in this provider.", innerException) { Help = $"try running {"confix variable list".AsHighlighted()} to list all available variables" }; @@ -53,7 +56,7 @@ public static Exception AccessToKeyVaultFailed(RequestFailedException innerExcep details.AppendLine($"Message: {innerException.Message}"); details.AppendLine($"Error code: {innerException.ErrorCode}"); details.AppendLine($"Status code: {innerException.Status}"); - + return new ExitException("Access to Key Vault failed", innerException) { Help = "check if you have the required permissions to access the Key Vault", @@ -66,4 +69,4 @@ public static Exception AuthenticationFailedForVault(Exception innerException) = { Help = $"try running {"az login".AsHighlighted()} to authenticate with Azure" }; -} +} \ No newline at end of file diff --git a/src/Confix.Tool/src/Confix.Library/Utilities/Azure/KeyVaultExtension.cs b/src/Confix.Tool/src/Confix.Library/Utilities/Azure/KeyVaultExtension.cs index 0deb6d9b..a20ab1c0 100644 --- a/src/Confix.Tool/src/Confix.Library/Utilities/Azure/KeyVaultExtension.cs +++ b/src/Confix.Tool/src/Confix.Library/Utilities/Azure/KeyVaultExtension.cs @@ -1,13 +1,12 @@ using Azure; using Azure.Identity; using Confix.Tool; -using Confix.Tool.Commands.Logging; namespace Confix.Utilities.Azure; public static class KeyVaultExtension { - public static async Task HandleKeyVaultException(Func> action) + public static async Task HandleKeyVaultException(Func> action, string? path = null) { try { @@ -15,7 +14,7 @@ public static async Task HandleKeyVaultException(Func> action) } catch (RequestFailedException ex) when (ex.ErrorCode == "SecretNotFound") { - throw ThrowHelper.SecretNotFound(ex); + throw ThrowHelper.SecretNotFound(ex, path); } catch (RequestFailedException ex) { @@ -26,4 +25,4 @@ public static async Task HandleKeyVaultException(Func> action) throw ThrowHelper.AuthenticationFailedForVault(ex); } } -} +} \ No newline at end of file diff --git a/src/Confix.Tool/src/Confix.Library/Variables/Providers/AzureKeyVault/AzureKeyVaultProvider.cs b/src/Confix.Tool/src/Confix.Library/Variables/Providers/AzureKeyVault/AzureKeyVaultProvider.cs index 5fc5573c..a864ff25 100644 --- a/src/Confix.Tool/src/Confix.Library/Variables/Providers/AzureKeyVault/AzureKeyVaultProvider.cs +++ b/src/Confix.Tool/src/Confix.Library/Variables/Providers/AzureKeyVault/AzureKeyVaultProvider.cs @@ -38,7 +38,7 @@ public Task> ListAsync(CancellationToken cancellationToken => KeyVaultExtension.HandleKeyVaultException>(async () => { App.Log.ListSecrets(_client.VaultUri); - + var secrets = new List(); await foreach (var secret in _client.GetPropertiesOfSecretsAsync(cancellationToken)) { @@ -54,7 +54,7 @@ public Task ResolveAsync(string path, CancellationToken cancellationTo KeyVaultSecret result = await _client.GetSecretAsync(path.ToKeyVaultCompatiblePath(), cancellationToken: cancellationToken); return JsonValue.Create(result.Value)!; - }); + }, path); public Task> ResolveManyAsync( IReadOnlyList paths, @@ -70,9 +70,9 @@ public Task SetAsync(string path, JsonNode value, CancellationToken ct) } KeyVaultSecret result = await _client - .SetSecretAsync(path.ToKeyVaultCompatiblePath(), (string) value!, ct); + .SetSecretAsync(path.ToKeyVaultCompatiblePath(), (string)value!, ct); return result.Name.ToConfixPath(); - }); + }, path); public ValueTask DisposeAsync() { @@ -93,4 +93,4 @@ public static void ListSecrets(this IConsoleLogger log, Uri vaultUri) { log.Information($"List all secrets from Azure Kev Vault '{vaultUri}'"); } -} +} \ No newline at end of file