Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Require explicit cloud URL opt-in (#8038)
Aaron Perez382d13e71149
diff --git a/skyvern/cli/credentials.py b/skyvern/cli/credentials.pyindex 6601c4800..9cf5f5573 100644--- a/skyvern/cli/credentials.py+++ b/skyvern/cli/credentials.py@@ -52,6 +52,11 @@ def _get_client(api_key: str | None = None) -> Skyvern:from skyvern.config import settings # noqa: PLC0415key = api_key or os.getenv("SKYVERN_API_KEY") or settings.SKYVERN_API_KEY+ if key != "PLACEHOLDER" and not settings.is_skyvern_base_url_explicitly_configured:+ raise typer.BadParameter(+ "Refusing to send an API key to the default production URL. "+ "Set SKYVERN_BASE_URL=https://api.skyvern.com to explicitly opt in."+ )return Skyvern(base_url=settings.SKYVERN_BASE_URL, api_key=key)diff --git a/skyvern/cli/tasks.py b/skyvern/cli/tasks.pyindex f6387a2e4..121a25633 100644--- a/skyvern/cli/tasks.py+++ b/skyvern/cli/tasks.py@@ -39,6 +39,11 @@ def _get_client(api_key: str | None = None) -> Skyvern:from skyvern.config import settings # noqa: PLC0415key = api_key or os.getenv("SKYVERN_API_KEY") or settings.SKYVERN_API_KEY+ if key != "PLACEHOLDER" and not settings.is_skyvern_base_url_explicitly_configured:+ raise typer.BadParameter(+ "Refusing to send an API key to the default production URL. "+ "Set SKYVERN_BASE_URL=https://api.skyvern.com to explicitly opt in."+ )return Skyvern(base_url=settings.SKYVERN_BASE_URL, api_key=key)diff --git a/skyvern/config.py b/skyvern/config.pyindex 4fce14b41..dc0f90d9e 100644--- a/skyvern/config.py+++ b/skyvern/config.py@@ -861,6 +861,10 @@ class Settings(BaseSettings):LOG.warning("Invalid WORKER_STALL_DUMP_SECONDS=%r; using default 0", value)return 0+ @property+ def is_skyvern_base_url_explicitly_configured(self) -> bool:+ return "SKYVERN_BASE_URL" in self.model_fields_set+def get_model_name_to_llm_key(self, organization_id: str | None = None) -> dict[str, dict[str, str]]:"""Keys are model names available to blocks in the frontend. These map to key namesdiff --git a/tests/unit/test_cli_commands.py b/tests/unit/test_cli_commands.pyindex 64d1ffa6a..812918791 100644--- a/tests/unit/test_cli_commands.py+++ b/tests/unit/test_cli_commands.py@@ -2,6 +2,7 @@from __future__ import annotations+import importlibimport jsonimport shlexfrom datetime import datetime, timezone@@ -902,6 +903,58 @@ class TestTasksCommands:assert parsed["action"] == "tasks.list"[email protected]("module_name", ["skyvern.cli.credentials", "skyvern.cli.tasks"])+class TestCredentialClientBaseUrlGuard:+ def test_rejects_credential_when_base_url_uses_untouched_default(+ self, module_name: str, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ from skyvern import config++ monkeypatch.delenv("SKYVERN_API_KEY", raising=False)+ monkeypatch.delenv("SKYVERN_BASE_URL", raising=False)+ cli_module = importlib.import_module(module_name)+ monkeypatch.setattr(cli_module, "prepare_cli_runtime", lambda **_: None)+ monkeypatch.setattr(config, "settings", config.Settings(_env_file=None))++ with pytest.raises(typer.BadParameter, match="SKYVERN_BASE_URL=https://api.skyvern.com"):+ cli_module._get_client("test-api-key")++ @pytest.mark.parametrize("base_url", ["https://api.skyvern.com", "https://staging.skyvern.com"])+ def test_allows_credential_when_base_url_is_explicitly_configured(+ self, module_name: str, base_url: str, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ from skyvern import config++ monkeypatch.delenv("SKYVERN_API_KEY", raising=False)+ monkeypatch.setenv("SKYVERN_BASE_URL", base_url)+ cli_module = importlib.import_module(module_name)+ client_constructor = MagicMock(return_value=object())+ monkeypatch.setattr(cli_module, "prepare_cli_runtime", lambda **_: None)+ monkeypatch.setattr(cli_module, "Skyvern", client_constructor)+ monkeypatch.setattr(config, "settings", config.Settings(_env_file=None))++ cli_module._get_client("test-api-key")++ client_constructor.assert_called_once_with(base_url=base_url, api_key="test-api-key")++ def test_allows_untouched_default_without_a_credential(+ self, module_name: str, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ from skyvern import config++ monkeypatch.delenv("SKYVERN_API_KEY", raising=False)+ monkeypatch.delenv("SKYVERN_BASE_URL", raising=False)+ cli_module = importlib.import_module(module_name)+ client_constructor = MagicMock(return_value=object())+ monkeypatch.setattr(cli_module, "prepare_cli_runtime", lambda **_: None)+ monkeypatch.setattr(cli_module, "Skyvern", client_constructor)+ monkeypatch.setattr(config, "settings", config.Settings(_env_file=None))++ cli_module._get_client()++ client_constructor.assert_called_once_with(base_url="https://api.skyvern.com", api_key="PLACEHOLDER")++class TestCredentialsCommands:def test_add_credential_invalid_type_json_error_includes_action(self, capsys: pytest.CaptureFixture) -> None:from skyvern.cli import credentials as credentials_cmd