Add RemoveFingerprintCommand

This commit is contained in:
2021-06-04 23:26:22 +02:00
parent 90afa7fe3b
commit 5e303c39f2
4 changed files with 45 additions and 0 deletions

View File

@@ -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;

View File

@@ -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) =>

View File

@@ -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}");

View File

@@ -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);
}
}