mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 07:48:57 +00:00
Add vault profile export/import
This commit is contained in:
@@ -14,8 +14,6 @@ from seedpass.core.api import (
|
||||
ConfigService,
|
||||
UtilityService,
|
||||
NostrService,
|
||||
VaultExportRequest,
|
||||
VaultImportRequest,
|
||||
ChangePasswordRequest,
|
||||
UnlockRequest,
|
||||
BackupParentSeedRequest,
|
||||
@@ -402,9 +400,10 @@ def entry_export_totp(
|
||||
def vault_export(
|
||||
ctx: typer.Context, file: str = typer.Option(..., help="Output file")
|
||||
) -> None:
|
||||
"""Export the vault."""
|
||||
"""Export the vault profile to an encrypted file."""
|
||||
vault_service, _profile, _sync = _get_services(ctx)
|
||||
vault_service.export_vault(VaultExportRequest(path=Path(file)))
|
||||
data = vault_service.export_profile()
|
||||
Path(file).write_bytes(data)
|
||||
typer.echo(str(file))
|
||||
|
||||
|
||||
@@ -412,9 +411,10 @@ def vault_export(
|
||||
def vault_import(
|
||||
ctx: typer.Context, file: str = typer.Option(..., help="Input file")
|
||||
) -> None:
|
||||
"""Import a vault from an encrypted JSON file."""
|
||||
"""Import a vault profile from an encrypted file."""
|
||||
vault_service, _profile, _sync = _get_services(ctx)
|
||||
vault_service.import_vault(VaultImportRequest(path=Path(file)))
|
||||
data = Path(file).read_bytes()
|
||||
vault_service.import_profile(data)
|
||||
typer.echo(str(file))
|
||||
|
||||
|
||||
|
@@ -10,6 +10,7 @@ allow easy validation and documentation.
|
||||
from pathlib import Path
|
||||
from threading import Lock
|
||||
from typing import List, Optional, Dict
|
||||
import json
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -102,6 +103,25 @@ class VaultService:
|
||||
self._manager.handle_import_database(req.path)
|
||||
self._manager.sync_vault()
|
||||
|
||||
def export_profile(self) -> bytes:
|
||||
"""Return encrypted profile data for backup."""
|
||||
|
||||
with self._lock:
|
||||
data = self._manager.vault.load_index()
|
||||
payload = json.dumps(data, sort_keys=True, separators=(",", ":")).encode(
|
||||
"utf-8"
|
||||
)
|
||||
return self._manager.vault.encryption_manager.encrypt_data(payload)
|
||||
|
||||
def import_profile(self, data: bytes) -> None:
|
||||
"""Restore a profile from ``data`` and sync."""
|
||||
|
||||
with self._lock:
|
||||
decrypted = self._manager.vault.encryption_manager.decrypt_data(data)
|
||||
index = json.loads(decrypted.decode("utf-8"))
|
||||
self._manager.vault.save_index(index)
|
||||
self._manager.sync_vault()
|
||||
|
||||
def change_password(self, req: ChangePasswordRequest) -> None:
|
||||
"""Change the master password."""
|
||||
|
||||
|
Reference in New Issue
Block a user