From 51816c0f6029a02044b8de2b6bb8ce98c101a6b3 Mon Sep 17 00:00:00 2001 From: Kerem Yilmaz Date: Thu, 18 Jul 2024 09:07:22 -0700 Subject: [PATCH] Add null check for credentials without emails (#616) --- skyvern/forge/sdk/services/bitwarden.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/skyvern/forge/sdk/services/bitwarden.py b/skyvern/forge/sdk/services/bitwarden.py index 5295375b..b4869018 100644 --- a/skyvern/forge/sdk/services/bitwarden.py +++ b/skyvern/forge/sdk/services/bitwarden.py @@ -18,7 +18,9 @@ from skyvern.exceptions import ( LOG = structlog.get_logger() -def is_valid_email(email: str) -> bool: +def is_valid_email(email: str | None) -> bool: + if not email: + return False pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" return re.match(pattern, email) is not None @@ -140,10 +142,9 @@ class BitwardenService: # if no cred matches the rule, return the first one. # TODO: For now hard code to choose the first valid email username for cred in credentials: - if is_valid_email(cred.get(BitwardenConstants.USERNAME, "")): + if is_valid_email(cred.get(BitwardenConstants.USERNAME)): return cred - - LOG.warning("No credential in Bitwarden matches the rule, returning the frist match") + LOG.warning("No credential in Bitwarden matches the rule, returning the first match") return credentials[0] finally: # Step 4: Log out