mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-07 06:48:52 +00:00
Add SSH and managed account modify handling
This commit is contained in:
@@ -2974,18 +2974,14 @@ class PasswordManager:
|
||||
custom_fields=custom_fields,
|
||||
tags=tags,
|
||||
)
|
||||
elif entry_type in (
|
||||
EntryType.KEY_VALUE.value,
|
||||
EntryType.MANAGED_ACCOUNT.value,
|
||||
):
|
||||
elif entry_type == EntryType.SSH.value:
|
||||
label = entry.get("label", "")
|
||||
value = entry.get("value", "")
|
||||
blacklisted = entry.get("archived", False)
|
||||
notes = entry.get("notes", "")
|
||||
|
||||
print(
|
||||
colored(
|
||||
f"Modifying key/value entry '{label}' (Index: {index}):",
|
||||
f"Modifying SSH key entry '{label}' (Index: {index}):",
|
||||
"cyan",
|
||||
)
|
||||
)
|
||||
@@ -2999,9 +2995,86 @@ class PasswordManager:
|
||||
input(f'Enter new label (leave blank to keep "{label}"): ').strip()
|
||||
or label
|
||||
)
|
||||
new_key = input(
|
||||
f'Enter new key (leave blank to keep "{entry.get("key", "")}"): '
|
||||
).strip() or entry.get("key", "")
|
||||
blacklist_input = (
|
||||
input(
|
||||
f'Archive this entry? (Y/N, current: {"Y" if blacklisted else "N"}): '
|
||||
)
|
||||
.strip()
|
||||
.lower()
|
||||
)
|
||||
if blacklist_input == "":
|
||||
new_blacklisted = blacklisted
|
||||
elif blacklist_input == "y":
|
||||
new_blacklisted = True
|
||||
elif blacklist_input == "n":
|
||||
new_blacklisted = False
|
||||
else:
|
||||
self.notify(
|
||||
"Invalid input for archived status. Keeping the current status.",
|
||||
level="WARNING",
|
||||
)
|
||||
new_blacklisted = blacklisted
|
||||
|
||||
new_notes = (
|
||||
input(
|
||||
f'Enter new notes (leave blank to keep "{notes or "N/A"}"): '
|
||||
).strip()
|
||||
or notes
|
||||
)
|
||||
|
||||
tags_input = input(
|
||||
"Enter tags (comma-separated, leave blank to keep current): "
|
||||
).strip()
|
||||
tags = (
|
||||
[t.strip() for t in tags_input.split(",") if t.strip()]
|
||||
if tags_input
|
||||
else None
|
||||
)
|
||||
|
||||
self.entry_manager.modify_entry(
|
||||
index,
|
||||
archived=new_blacklisted,
|
||||
notes=new_notes,
|
||||
label=new_label,
|
||||
tags=tags,
|
||||
)
|
||||
elif entry_type in (
|
||||
EntryType.KEY_VALUE.value,
|
||||
EntryType.MANAGED_ACCOUNT.value,
|
||||
):
|
||||
label = entry.get("label", "")
|
||||
value = entry.get("value", "")
|
||||
blacklisted = entry.get("archived", False)
|
||||
notes = entry.get("notes", "")
|
||||
|
||||
entry_label = (
|
||||
"key/value entry"
|
||||
if entry_type == EntryType.KEY_VALUE.value
|
||||
else "managed account"
|
||||
)
|
||||
|
||||
print(
|
||||
colored(
|
||||
f"Modifying {entry_label} '{label}' (Index: {index}):",
|
||||
"cyan",
|
||||
)
|
||||
)
|
||||
print(
|
||||
colored(
|
||||
f"Current Archived Status: {'Archived' if blacklisted else 'Active'}",
|
||||
"cyan",
|
||||
)
|
||||
)
|
||||
new_label = (
|
||||
input(f'Enter new label (leave blank to keep "{label}"): ').strip()
|
||||
or label
|
||||
)
|
||||
if entry_type == EntryType.KEY_VALUE.value:
|
||||
new_key = input(
|
||||
f'Enter new key (leave blank to keep "{entry.get("key", "")}"): '
|
||||
).strip() or entry.get("key", "")
|
||||
else:
|
||||
new_key = None
|
||||
new_value = (
|
||||
input("Enter new value (leave blank to keep current): ").strip()
|
||||
or value
|
||||
@@ -3058,15 +3131,20 @@ class PasswordManager:
|
||||
else None
|
||||
)
|
||||
|
||||
modify_kwargs = {
|
||||
"archived": new_blacklisted,
|
||||
"notes": new_notes,
|
||||
"label": new_label,
|
||||
"value": new_value,
|
||||
"custom_fields": custom_fields,
|
||||
"tags": tags,
|
||||
}
|
||||
if entry_type == EntryType.KEY_VALUE.value:
|
||||
modify_kwargs["key"] = new_key
|
||||
|
||||
self.entry_manager.modify_entry(
|
||||
index,
|
||||
archived=new_blacklisted,
|
||||
notes=new_notes,
|
||||
label=new_label,
|
||||
key=new_key,
|
||||
value=new_value,
|
||||
custom_fields=custom_fields,
|
||||
tags=tags,
|
||||
**modify_kwargs,
|
||||
)
|
||||
else:
|
||||
website_name = entry.get("label", entry.get("website"))
|
||||
|
56
src/tests/test_modify_ssh_managed_entries.py
Normal file
56
src/tests/test_modify_ssh_managed_entries.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from helpers import create_vault, TEST_SEED, TEST_PASSWORD
|
||||
|
||||
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from seedpass.core.entry_management import EntryManager
|
||||
from seedpass.core.backup import BackupManager
|
||||
from seedpass.core.config_manager import ConfigManager
|
||||
|
||||
|
||||
def setup_mgr(tmp_path: Path) -> EntryManager:
|
||||
vault, _ = create_vault(tmp_path, TEST_SEED, TEST_PASSWORD)
|
||||
cfg = ConfigManager(vault, tmp_path)
|
||||
backup = BackupManager(tmp_path, cfg)
|
||||
return EntryManager(vault, backup)
|
||||
|
||||
|
||||
def test_modify_ssh_entry():
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
tmp_path = Path(tmpdir)
|
||||
em = setup_mgr(tmp_path)
|
||||
|
||||
idx = em.add_ssh_key("ssh", TEST_SEED)
|
||||
em.modify_entry(idx, label="newssh", notes="n", archived=True, tags=["x"])
|
||||
entry = em.retrieve_entry(idx)
|
||||
|
||||
assert entry["label"] == "newssh"
|
||||
assert entry["notes"] == "n"
|
||||
assert entry["archived"] is True
|
||||
assert entry["tags"] == ["x"]
|
||||
|
||||
|
||||
def test_modify_managed_account_entry():
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
tmp_path = Path(tmpdir)
|
||||
em = setup_mgr(tmp_path)
|
||||
|
||||
idx = em.add_managed_account("acct", TEST_SEED)
|
||||
em.modify_entry(
|
||||
idx,
|
||||
label="acct2",
|
||||
value="val",
|
||||
notes="note",
|
||||
archived=True,
|
||||
tags=["tag"],
|
||||
)
|
||||
entry = em.retrieve_entry(idx)
|
||||
|
||||
assert entry["label"] == "acct2"
|
||||
assert entry["value"] == "val"
|
||||
assert entry["notes"] == "note"
|
||||
assert entry["archived"] is True
|
||||
assert entry["tags"] == ["tag"]
|
Reference in New Issue
Block a user