feat(admincli): add generate key command
This commit is contained in:
@@ -3,7 +3,9 @@ namespace FiscalOS.AdminCLI;
|
||||
internal sealed class App(
|
||||
IAnsiConsole console,
|
||||
IPasswordHasher passwordHasher,
|
||||
IServiceScopeFactory serviceScopeFactory
|
||||
IServiceScopeFactory serviceScopeFactory,
|
||||
IEncryptor encryptor,
|
||||
IKeyRing keyRing
|
||||
) : IHostedService
|
||||
{
|
||||
private readonly IAnsiConsole _console = console;
|
||||
@@ -32,13 +34,19 @@ internal sealed class App(
|
||||
);
|
||||
|
||||
var hashedPassword = passwordHasher.Hash(password);
|
||||
var user = User.From(username, hashedPassword);
|
||||
var userEncryptionKey = await encryptor.GenerateEncryptedKeyAsync(cancellationToken);
|
||||
var user = User.From(username, hashedPassword, userEncryptionKey);
|
||||
|
||||
await appDbContext.Users.AddAsync(user, cancellationToken);
|
||||
await appDbContext.SaveChangesAsync(cancellationToken);
|
||||
|
||||
_console.MarkupLine($"User [green]{username}[/] created successfully.");
|
||||
break;
|
||||
case Commands.GenerateKey:
|
||||
var key = encryptor.GenerateKey();
|
||||
var keyRingEntry = await keyRing.SaveKeyAsync(key);
|
||||
_console.MarkupLine($"Key generated with id [green]{keyRingEntry.KeyId}[/] generated successfully.");
|
||||
break;
|
||||
case Commands.Exit:
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -3,7 +3,12 @@ namespace FiscalOS.AdminCLI;
|
||||
internal static class Commands
|
||||
{
|
||||
public const string CreateUser = "Create User";
|
||||
public const string GenerateKey = "Generate Key";
|
||||
public const string Exit = "Exit";
|
||||
|
||||
public static readonly string[] All = [CreateUser, Exit];
|
||||
public static readonly string[] All = [
|
||||
CreateUser,
|
||||
GenerateKey,
|
||||
Exit
|
||||
];
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
global using FiscalOS.AdminCLI;
|
||||
global using FiscalOS.Core.Authentication;
|
||||
global using FiscalOS.Core.Identity;
|
||||
global using FiscalOS.Core.Security;
|
||||
global using FiscalOS.Infra.Data;
|
||||
global using FiscalOS.Infra.DependencyInjection;
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
{
|
||||
"AppDbContextOptions": {
|
||||
"DatabaseFilePath": "DatabaseFilePath"
|
||||
},
|
||||
"FileKeyRingOptions": {
|
||||
"KeysDirectoryPath": "KeysDirectoryPath",
|
||||
"PrimaryKeyId": "PrimaryKeyId"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user