refactor: remove environment variable reading from login()
- Remove all os.getenv() calls from login() function - Remove URL construction logic (caller provides complete URL) - Add parameter validation with clear error messages - Function is now pure with no side effects Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,28 +35,13 @@ def login(
|
|||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# Read default configuration from environment variables
|
# Validate required parameters
|
||||||
username = username or os.getenv("ERP_USERNAME")
|
if not username:
|
||||||
password = password or os.getenv("ERP_PASSWORD")
|
raise ValueError("username is required")
|
||||||
|
if not password:
|
||||||
# URL handling: read from environment variable or parameter
|
raise ValueError("password is required")
|
||||||
if not url:
|
if not url:
|
||||||
url = os.getenv("ERP_URL")
|
raise ValueError("url is required")
|
||||||
if url and not url.endswith("login/main/index.html"):
|
|
||||||
url = url.rstrip("/") + "/yonbip/resources/uap/rbac/login/main/index.html"
|
|
||||||
|
|
||||||
if not url:
|
|
||||||
raise ValueError("URL must be provided either as parameter or through ERP_URL environment variable")
|
|
||||||
|
|
||||||
# headless parameter handling
|
|
||||||
if headless is None:
|
|
||||||
headless_str = os.getenv("ERP_HEADLESS", "false").lower()
|
|
||||||
headless = headless_str in ("true", "1", "yes")
|
|
||||||
|
|
||||||
# ignore_https_errors parameter handling
|
|
||||||
if ignore_https_errors is None:
|
|
||||||
ignore_https_errors_str = os.getenv("ERP_IGNORE_HTTPS_ERRORS", "true").lower()
|
|
||||||
ignore_https_errors = ignore_https_errors_str in ("true", "1", "yes")
|
|
||||||
|
|
||||||
# Launch browser
|
# Launch browser
|
||||||
browser = playwright.chromium.launch(headless=headless)
|
browser = playwright.chromium.launch(headless=headless)
|
||||||
|
|||||||
Reference in New Issue
Block a user