mirror of
https://github.com/Skyvern-AI/skyvern.git
synced 2025-09-14 09:19:40 +00:00
validate browser session id when running tasks or workflows (#2874)
This commit is contained in:
parent
133cee4358
commit
f832206f38
3 changed files with 28 additions and 0 deletions
|
@ -715,3 +715,11 @@ class MissingBrowserSessionError(SkyvernHTTPException):
|
|||
class MissingBrowserAddressError(SkyvernException):
|
||||
def __init__(self, browser_session_id: str) -> None:
|
||||
super().__init__(f"Browser session {browser_session_id} does not have an address.")
|
||||
|
||||
|
||||
class BrowserSessionNotFound(SkyvernHTTPException):
|
||||
def __init__(self, browser_session_id: str) -> None:
|
||||
super().__init__(
|
||||
f"Browser session {browser_session_id} does not exist or is not live.",
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
|
|
@ -27,6 +27,7 @@ from skyvern.constants import (
|
|||
ScrapeType,
|
||||
)
|
||||
from skyvern.exceptions import (
|
||||
BrowserSessionNotFound,
|
||||
BrowserStateMissingPage,
|
||||
DownloadFileMaxWaitingTime,
|
||||
EmptyScrapePage,
|
||||
|
@ -223,6 +224,15 @@ class ForgeAgent:
|
|||
async def create_task(self, task_request: TaskRequest, organization_id: str) -> Task:
|
||||
webhook_callback_url = str(task_request.webhook_callback_url) if task_request.webhook_callback_url else None
|
||||
totp_verification_url = str(task_request.totp_verification_url) if task_request.totp_verification_url else None
|
||||
# validate browser session id
|
||||
if task_request.browser_session_id:
|
||||
browser_session = await app.DATABASE.get_persistent_browser_session(
|
||||
session_id=task_request.browser_session_id,
|
||||
organization_id=organization_id,
|
||||
)
|
||||
if not browser_session:
|
||||
raise BrowserSessionNotFound(browser_session_id=task_request.browser_session_id)
|
||||
|
||||
task = await app.DATABASE.create_task(
|
||||
url=str(task_request.url),
|
||||
title=task_request.title,
|
||||
|
|
|
@ -10,6 +10,7 @@ from skyvern import analytics
|
|||
from skyvern.config import settings
|
||||
from skyvern.constants import GET_DOWNLOADED_FILES_TIMEOUT, SAVE_DOWNLOADED_FILES_TIMEOUT
|
||||
from skyvern.exceptions import (
|
||||
BrowserSessionNotFound,
|
||||
FailedToSendWebhook,
|
||||
InvalidCredentialId,
|
||||
MissingValueForParameter,
|
||||
|
@ -779,6 +780,15 @@ class WorkflowService:
|
|||
organization_id: str,
|
||||
parent_workflow_run_id: str | None = None,
|
||||
) -> WorkflowRun:
|
||||
# validate the browser session id
|
||||
if workflow_request.browser_session_id:
|
||||
browser_session = await app.DATABASE.get_persistent_browser_session(
|
||||
session_id=workflow_request.browser_session_id,
|
||||
organization_id=organization_id,
|
||||
)
|
||||
if not browser_session:
|
||||
raise BrowserSessionNotFound(browser_session_id=workflow_request.browser_session_id)
|
||||
|
||||
return await app.DATABASE.create_workflow_run(
|
||||
workflow_permanent_id=workflow_permanent_id,
|
||||
workflow_id=workflow_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue