Add RemoveFingerprintCommand
This commit is contained in:
@@ -35,6 +35,32 @@ namespace Akari.Prototype.Server.Cli.Commands
|
||||
}
|
||||
}
|
||||
|
||||
[Command("fp r", Description = "Remove a fingerprint")]
|
||||
public class RemoveFingerprintCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Description = "The fingerprint name")]
|
||||
public string Name { get; init; }
|
||||
|
||||
private readonly IFingerprintManager _fingerprintManager;
|
||||
|
||||
public RemoveFingerprintCommand(IFingerprintManager fingerprintManager)
|
||||
{
|
||||
_fingerprintManager = fingerprintManager;
|
||||
}
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
if (!_fingerprintManager.Remove(Name))
|
||||
{
|
||||
throw new CommandException($"The fingerprint {Name} doesn't exist");
|
||||
}
|
||||
|
||||
console.AsAnsiConsole().Markup($"[green]Successfully deleted {Name}[/]");
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public FingerprintCommands(IFingerprintManager fingerprintManager)
|
||||
{
|
||||
_fingerprintManager = fingerprintManager;
|
||||
|
||||
@@ -75,6 +75,7 @@ namespace Akari.Prototype.Server
|
||||
Startup.ConfigureStandardServices(hostContext.Configuration, services);
|
||||
|
||||
services.AddTransient<FingerprintCommands>();
|
||||
services.AddTransient<FingerprintCommands.RemoveFingerprintCommand>();
|
||||
});
|
||||
|
||||
public static IHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
|
||||
@@ -53,6 +53,22 @@ namespace Akari.Prototype.Server.Services
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveFingerprints()
|
||||
{
|
||||
var path = _akariPath.GetPath(FingerprintsPath);
|
||||
|
||||
File.WriteAllText(path, JsonSerializer.Serialize(_fingerprintsHash));
|
||||
}
|
||||
|
||||
public bool Remove(string name)
|
||||
{
|
||||
var result = _fingerprintsHash.Remove(name);
|
||||
|
||||
SaveFingerprints();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void VerifyFingerprint(string name, string token)
|
||||
{
|
||||
_logger.LogDebug($"Verifying hash for {name}");
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace Akari.Prototype.Server.Services
|
||||
{
|
||||
IEnumerable<KeyValuePair<string, string>> FingerprintsHash { get; }
|
||||
|
||||
bool Remove(string name);
|
||||
|
||||
void VerifyFingerprint(string name, string token);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user