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
|
||||
|
||||
# Read default configuration from environment variables
|
||||
username = username or os.getenv("ERP_USERNAME")
|
||||
password = password or os.getenv("ERP_PASSWORD")
|
||||
|
||||
# URL handling: read from environment variable or parameter
|
||||
# Validate required parameters
|
||||
if not username:
|
||||
raise ValueError("username is required")
|
||||
if not password:
|
||||
raise ValueError("password is required")
|
||||
if not url:
|
||||
url = os.getenv("ERP_URL")
|
||||
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")
|
||||
raise ValueError("url is required")
|
||||
|
||||
# Launch browser
|
||||
browser = playwright.chromium.launch(headless=headless)
|
||||
|
||||
Reference in New Issue
Block a user