fix(secrets-cli): CRUD flows — escaped validation markup, shared prompt helpers, delete existence check

This commit is contained in:
Joseph Doherty
2026-07-19 09:47:10 -04:00
parent 6ad710bdbd
commit e5a4d0276a
5 changed files with 98 additions and 50 deletions
@@ -23,8 +23,11 @@ public sealed class SetSecretFlow : IInteractiveFlow
ArgumentNullException.ThrowIfNull(console);
ArgumentNullException.ThrowIfNull(session);
ISecretCipher cipher = session.Cipher
?? throw new InvalidOperationException("flow requires an unlocked KEK session");
var name = new SecretName(console.Prompt(
new TextPrompt<string>("Secret [green]name[/]:").Validate(NameValidation)));
new TextPrompt<string>("Secret [green]name[/]:").Validate(FlowPrompts.ValidateSecretName)));
StoredSecret? existing = await session.Store.GetAsync(name, ct).ConfigureAwait(false);
if (existing is { IsDeleted: false } &&
@@ -40,8 +43,8 @@ public sealed class SetSecretFlow : IInteractiveFlow
string description = console.Prompt(
new TextPrompt<string>("Description [grey](optional)[/]:").AllowEmpty());
string actor = string.IsNullOrWhiteSpace(Environment.UserName) ? "cli" : Environment.UserName;
StoredSecret row = session.Cipher!.Encrypt(name, value, contentType) with
string actor = FlowPrompts.Actor;
StoredSecret row = cipher.Encrypt(name, value, contentType) with
{
Description = string.IsNullOrWhiteSpace(description) ? null : description,
CreatedBy = actor,
@@ -51,18 +54,4 @@ public sealed class SetSecretFlow : IInteractiveFlow
console.MarkupLineInterpolated($"[green]Sealed '{name.Value}'.[/]");
}
// Re-prompts on an invalid name by surfacing the SecretName constructor's own diagnostic.
private static ValidationResult NameValidation(string raw)
{
try
{
_ = new SecretName(raw);
return ValidationResult.Success();
}
catch (ArgumentException ex)
{
return ValidationResult.Error(ex.Message);
}
}
}