mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 07:48:57 +00:00
Add key field to key/value entries
This commit is contained in:
@@ -173,6 +173,7 @@ def create_entry(
|
||||
if etype == "key_value":
|
||||
index = _pm.entry_manager.add_key_value(
|
||||
entry.get("label"),
|
||||
entry.get("key"),
|
||||
entry.get("value"),
|
||||
notes=entry.get("notes", ""),
|
||||
)
|
||||
|
@@ -315,12 +315,13 @@ def entry_add_seed(
|
||||
def entry_add_key_value(
|
||||
ctx: typer.Context,
|
||||
label: str,
|
||||
key: str = typer.Option(..., "--key", help="Key name"),
|
||||
value: str = typer.Option(..., "--value", help="Stored value"),
|
||||
notes: str = typer.Option("", "--notes", help="Entry notes"),
|
||||
) -> None:
|
||||
"""Add a key/value entry and output its index."""
|
||||
service = _get_entry_service(ctx)
|
||||
idx = service.add_key_value(label, value, notes=notes)
|
||||
idx = service.add_key_value(label, key, value, notes=notes)
|
||||
typer.echo(str(idx))
|
||||
|
||||
|
||||
|
@@ -379,9 +379,13 @@ class EntryService:
|
||||
self._manager.start_background_vault_sync()
|
||||
return idx
|
||||
|
||||
def add_key_value(self, label: str, value: str, *, notes: str = "") -> int:
|
||||
def add_key_value(
|
||||
self, label: str, key: str, value: str, *, notes: str = ""
|
||||
) -> int:
|
||||
with self._lock:
|
||||
idx = self._manager.entry_manager.add_key_value(label, value, notes=notes)
|
||||
idx = self._manager.entry_manager.add_key_value(
|
||||
label, key, value, notes=notes
|
||||
)
|
||||
self._manager.start_background_vault_sync()
|
||||
return idx
|
||||
|
||||
|
@@ -412,6 +412,7 @@ class EntryManager:
|
||||
def add_key_value(
|
||||
self,
|
||||
label: str,
|
||||
key: str,
|
||||
value: str,
|
||||
*,
|
||||
notes: str = "",
|
||||
@@ -429,6 +430,7 @@ class EntryManager:
|
||||
"type": EntryType.KEY_VALUE.value,
|
||||
"kind": EntryType.KEY_VALUE.value,
|
||||
"label": label,
|
||||
"key": key,
|
||||
"modified_ts": int(time.time()),
|
||||
"value": value,
|
||||
"notes": notes,
|
||||
@@ -720,6 +722,7 @@ class EntryManager:
|
||||
label: Optional[str] = None,
|
||||
period: Optional[int] = None,
|
||||
digits: Optional[int] = None,
|
||||
key: Optional[str] = None,
|
||||
value: Optional[str] = None,
|
||||
custom_fields: List[Dict[str, Any]] | None = None,
|
||||
tags: list[str] | None = None,
|
||||
@@ -736,6 +739,7 @@ class EntryManager:
|
||||
:param label: (Optional) The new label for the entry.
|
||||
:param period: (Optional) The new TOTP period in seconds.
|
||||
:param digits: (Optional) The new number of digits for TOTP codes.
|
||||
:param key: (Optional) New key for key/value entries.
|
||||
:param value: (Optional) New value for key/value entries.
|
||||
"""
|
||||
try:
|
||||
@@ -764,6 +768,7 @@ class EntryManager:
|
||||
"label": label,
|
||||
"period": period,
|
||||
"digits": digits,
|
||||
"key": key,
|
||||
"value": value,
|
||||
"custom_fields": custom_fields,
|
||||
"tags": tags,
|
||||
@@ -790,6 +795,7 @@ class EntryManager:
|
||||
},
|
||||
EntryType.KEY_VALUE.value: {
|
||||
"label",
|
||||
"key",
|
||||
"value",
|
||||
"archived",
|
||||
"notes",
|
||||
@@ -870,6 +876,9 @@ class EntryManager:
|
||||
EntryType.KEY_VALUE.value,
|
||||
EntryType.MANAGED_ACCOUNT.value,
|
||||
):
|
||||
if key is not None and entry_type == EntryType.KEY_VALUE.value:
|
||||
entry["key"] = key
|
||||
logger.debug(f"Updated key for index {index}.")
|
||||
if value is not None:
|
||||
entry["value"] = value
|
||||
logger.debug(f"Updated value for index {index}.")
|
||||
|
@@ -1888,6 +1888,10 @@ class PasswordManager:
|
||||
if not label:
|
||||
print(colored("Error: Label cannot be empty.", "red"))
|
||||
return
|
||||
key_field = input("Key: ").strip()
|
||||
if not key_field:
|
||||
print(colored("Error: Key cannot be empty.", "red"))
|
||||
return
|
||||
value = input("Value: ").strip()
|
||||
notes = input("Notes (optional): ").strip()
|
||||
tags_input = input("Enter tags (comma-separated, optional): ").strip()
|
||||
@@ -1915,6 +1919,7 @@ class PasswordManager:
|
||||
|
||||
index = self.entry_manager.add_key_value(
|
||||
label,
|
||||
key_field,
|
||||
value,
|
||||
notes=notes,
|
||||
custom_fields=custom_fields,
|
||||
@@ -2886,6 +2891,9 @@ 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", "")
|
||||
new_value = (
|
||||
input("Enter new value (leave blank to keep current): ").strip()
|
||||
or value
|
||||
@@ -2947,6 +2955,7 @@ class PasswordManager:
|
||||
archived=new_blacklisted,
|
||||
notes=new_notes,
|
||||
label=new_label,
|
||||
key=new_key,
|
||||
value=new_value,
|
||||
custom_fields=custom_fields,
|
||||
tags=tags,
|
||||
@@ -3237,7 +3246,8 @@ class PasswordManager:
|
||||
print(color_text(f" Tags: {', '.join(tags)}", "index"))
|
||||
elif etype == EntryType.KEY_VALUE.value:
|
||||
print(color_text(" Type: Key/Value", "index"))
|
||||
print(color_text(f" Label (key): {entry.get('label', '')}", "index"))
|
||||
print(color_text(f" Label: {entry.get('label', '')}", "index"))
|
||||
print(color_text(f" Key: {entry.get('key', '')}", "index"))
|
||||
print(color_text(f" Value: {entry.get('value', '')}", "index"))
|
||||
notes = entry.get("notes", "")
|
||||
if notes:
|
||||
|
Reference in New Issue
Block a user