Introduce collectionid filter for bitwarden parameters (#454)
This commit is contained in:
@@ -27,6 +27,7 @@ class BitwardenConstants(StrEnum):
|
||||
CLIENT_SECRET = "BW_CLIENT_SECRET"
|
||||
MASTER_PASSWORD = "BW_MASTER_PASSWORD"
|
||||
URL = "BW_URL"
|
||||
BW_COLLECTION_ID = "BW_COLLECTION_ID"
|
||||
|
||||
USERNAME = "BW_USERNAME"
|
||||
PASSWORD = "BW_PASSWORD"
|
||||
@@ -68,6 +69,7 @@ class BitwardenService:
|
||||
client_secret: str,
|
||||
master_password: str,
|
||||
url: str,
|
||||
collection_id: str | None = None,
|
||||
) -> dict[str, str]:
|
||||
"""
|
||||
Get the secret value from the Bitwarden CLI.
|
||||
@@ -105,14 +107,6 @@ class BitwardenService:
|
||||
f"Failed to unlock vault. stdout: {unlock_result.stdout} stderr: {unlock_result.stderr}"
|
||||
)
|
||||
|
||||
# This is a part of Bitwarden's client-side telemetry
|
||||
# TODO -- figure out how to disable this telemetry so we never get this error
|
||||
# https://github.com/bitwarden/clients/blob/9d10825dbd891c0f41fe1b4c4dd3ca4171f63be5/libs/common/src/services/api.service.ts#L1473
|
||||
if unlock_result.stderr and "Event post failed" not in unlock_result.stderr:
|
||||
raise BitwardenUnlockError(
|
||||
f"Failed to unlock vault. stdout: {unlock_result.stdout} stderr: {unlock_result.stderr}"
|
||||
)
|
||||
|
||||
# Extract session key
|
||||
try:
|
||||
session_key = BitwardenService._extract_session_key(unlock_result.stdout)
|
||||
@@ -132,6 +126,9 @@ class BitwardenService:
|
||||
"--session",
|
||||
session_key,
|
||||
]
|
||||
if collection_id:
|
||||
LOG.info("Collection ID is provided, filtering items by collection ID", collection_id=collection_id)
|
||||
list_command.extend(["--collectionid", collection_id])
|
||||
items_result = BitwardenService.run_command(list_command)
|
||||
|
||||
if items_result.stderr and "Event post failed" not in items_result.stderr:
|
||||
@@ -144,7 +141,8 @@ class BitwardenService:
|
||||
raise BitwardenListItemsError("Failed to parse items JSON. Output: " + items_result.stdout)
|
||||
|
||||
if not items:
|
||||
raise BitwardenListItemsError("No items found in Bitwarden.")
|
||||
collection_id_str = f" in collection with ID: {collection_id}" if collection_id else ""
|
||||
raise BitwardenListItemsError(f"No items found in Bitwarden for URL: {url}{collection_id_str}")
|
||||
|
||||
totp_command = ["bw", "get", "totp", url, "--session", session_key]
|
||||
totp_result = BitwardenService.run_command(totp_command)
|
||||
|
||||
Reference in New Issue
Block a user