Skip to content

Commit 1ac19db

Browse files
committed
Improve verify command extensibility
1 parent 03e0eb7 commit 1ac19db

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/EasySign.CommandLine/BundleWorker.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected bool LoadBundle(bool readOnly = true)
4949
catch (Exception ex)
5050
{
5151
Logger.LogError(ex, "Failed to load bundle from file: {BundlePath}", Bundle.BundlePath);
52-
AnsiConsole.MarkupLine($"[{Color.Red}]Failed to load bundle from file: {Bundle.BundlePath}[/]");
52+
AnsiConsole.MarkupLine($"[{Color.Red}]Failed to load file: {Bundle.BundlePath}[/]");
5353
AnsiConsole.MarkupLine($"[{Color.Red}]Error:[/] {ex.GetType().Name}: {ex.Message}");
5454
}
5555

@@ -194,12 +194,12 @@ protected virtual void RunAdd(StatusContext statusContext, string[] files, bool
194194
Bundle.Update();
195195

196196
Logger.LogInformation("Bundle saved successfully");
197-
AnsiConsole.MarkupLine($"[green]Bundle file: {Bundle.BundlePath} Saved successfully[/]");
197+
AnsiConsole.MarkupLine($"[green]File: {Bundle.BundlePath} Saved successfully[/]");
198198
}
199199
else
200200
{
201201
Logger.LogInformation("No changes were made to the bundle");
202-
AnsiConsole.MarkupLine("[yellow]No changes were made to the bundle[/]");
202+
AnsiConsole.MarkupLine("[yellow]No changes were made to the file[/]");
203203
}
204204
}
205205

@@ -354,15 +354,16 @@ protected virtual void RunSign(StatusContext statusContext, X509Certificate2Coll
354354
Bundle.Update();
355355

356356
Logger.LogInformation("Bundle saved successfully");
357-
AnsiConsole.MarkupLine($"[green]Bundle file: {Bundle.BundlePath} Saved successfully[/]");
357+
AnsiConsole.MarkupLine($"[green]File: {Bundle.BundlePath} Saved successfully[/]");
358358
}
359359

360360
/// <summary>
361361
/// Runs the verify command.
362362
/// </summary>
363363
/// <param name="statusContext">The status context for interacting with <see cref="AnsiConsole.Status"/>.</param>
364364
/// <param name="ignoreTime">A value indicating whether to ignore time validity checks for certificate verification.</param>
365-
protected virtual void RunVerify(StatusContext statusContext, bool ignoreTime)
365+
/// <returns><see langword="true"></see> if the verification was successful; otherwise, <see langword="false"></see></returns>
366+
protected virtual bool RunVerify(StatusContext statusContext, bool ignoreTime)
366367
{
367368
Logger.LogInformation("Running verify command");
368369

@@ -381,7 +382,7 @@ protected virtual void RunVerify(StatusContext statusContext, bool ignoreTime)
381382

382383
Logger.LogDebug("Loading bundle");
383384
statusContext.Status("[yellow]Loading Bundle[/]");
384-
if (!LoadBundle()) return;
385+
if (!LoadBundle()) return false;
385386

386387
Logger.LogInformation("Starting certificate and signature verification");
387388
statusContext.Status("[yellow]Verification Phase 1: Certificates and signatures[/]");
@@ -425,12 +426,12 @@ protected virtual void RunVerify(StatusContext statusContext, bool ignoreTime)
425426
if (Bundle.Signatures.Entries.Count == 0)
426427
{
427428
Logger.LogWarning("Bundle is not signed");
428-
AnsiConsole.MarkupLine($"[red]This bundle is not signed[/]");
429+
AnsiConsole.MarkupLine($"[red]The file is not signed[/]");
429430
}
430431

431432
Logger.LogWarning("No certificates were verified");
432433
AnsiConsole.MarkupLine($"[red]Verification failed[/]");
433-
return;
434+
return false;
434435
}
435436

436437
if (verifiedCerts == Bundle.Signatures.Entries.Count)
@@ -512,11 +513,13 @@ protected virtual void RunVerify(StatusContext statusContext, bool ignoreTime)
512513
{
513514
Logger.LogWarning("File verification failed");
514515
AnsiConsole.MarkupLine($"[red]File Verification Failed[/]");
515-
return;
516+
return false;
516517
}
517518

518-
Logger.LogInformation("Bundle verification completed successfully");
519-
AnsiConsole.MarkupLine("[green]Bundle Verification Completed Successfully[/]");
519+
Logger.LogInformation("File verification completed successfully");
520+
AnsiConsole.MarkupLine("[green]All Files Verified Successfully[/]");
521+
522+
return true;
520523
}
521524

522525
/// <summary>

0 commit comments

Comments
 (0)