check bitwarden itemid format (#4508)
This commit is contained in:
@@ -33,6 +33,7 @@ from skyvern.forge.sdk.schemas.credentials import (
|
|||||||
SecretCredential,
|
SecretCredential,
|
||||||
)
|
)
|
||||||
from skyvern.forge.sdk.services.credentials import parse_totp_secret
|
from skyvern.forge.sdk.services.credentials import parse_totp_secret
|
||||||
|
from skyvern.utils.strings import is_uuid
|
||||||
|
|
||||||
LOG = structlog.get_logger()
|
LOG = structlog.get_logger()
|
||||||
BITWARDEN_SERVER_BASE_URL = f"{settings.BITWARDEN_SERVER}:{settings.BITWARDEN_SERVER_PORT or 8002}"
|
BITWARDEN_SERVER_BASE_URL = f"{settings.BITWARDEN_SERVER}:{settings.BITWARDEN_SERVER_PORT or 8002}"
|
||||||
@@ -223,6 +224,9 @@ class BitwardenService:
|
|||||||
if not bw_organization_id and bw_collection_ids and collection_id not in bw_collection_ids:
|
if not bw_organization_id and bw_collection_ids and collection_id not in bw_collection_ids:
|
||||||
raise BitwardenAccessDeniedError()
|
raise BitwardenAccessDeniedError()
|
||||||
|
|
||||||
|
if item_id and not is_uuid(item_id):
|
||||||
|
raise BitwardenGetItemError(f"Invalid item ID: {item_id}. Check if the item ID is correct")
|
||||||
|
|
||||||
for i in range(max_retries):
|
for i in range(max_retries):
|
||||||
# FIXME: just simply double the timeout for the second try. maybe a better backoff policy when needed
|
# FIXME: just simply double the timeout for the second try. maybe a better backoff policy when needed
|
||||||
timeout = (i + 1) * timeout
|
timeout = (i + 1) * timeout
|
||||||
@@ -698,6 +702,9 @@ class BitwardenService:
|
|||||||
"""
|
"""
|
||||||
Get the credit card data from the Bitwarden CLI.
|
Get the credit card data from the Bitwarden CLI.
|
||||||
"""
|
"""
|
||||||
|
if not is_uuid(item_id):
|
||||||
|
raise BitwardenGetItemError(f"Invalid item ID: {item_id}. Check if the item ID is correct")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with asyncio.timeout(settings.BITWARDEN_TIMEOUT_SECONDS):
|
async with asyncio.timeout(settings.BITWARDEN_TIMEOUT_SECONDS):
|
||||||
return await BitwardenService._get_credit_card_data(
|
return await BitwardenService._get_credit_card_data(
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
import uuid
|
||||||
|
|
||||||
RANDOM_STRING_POOL = string.ascii_letters + string.digits
|
RANDOM_STRING_POOL = string.ascii_letters + string.digits
|
||||||
|
|
||||||
@@ -9,3 +10,11 @@ def generate_random_string(length: int = 5) -> str:
|
|||||||
# Use the os.urandom(16) as the seed
|
# Use the os.urandom(16) as the seed
|
||||||
random.seed(os.urandom(16))
|
random.seed(os.urandom(16))
|
||||||
return "".join(random.choices(RANDOM_STRING_POOL, k=length))
|
return "".join(random.choices(RANDOM_STRING_POOL, k=length))
|
||||||
|
|
||||||
|
|
||||||
|
def is_uuid(string: str) -> bool:
|
||||||
|
try:
|
||||||
|
uuid.UUID(string)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user