From eb9ed0b606bfecbc567402c464e53fe4247c7270 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Fri, 27 Mar 2026 12:25:46 +0800 Subject: [PATCH] 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 --- utils/auth.py | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/utils/auth.py b/utils/auth.py index e806f87..c104b0e 100644 --- a/utils/auth.py +++ b/utils/auth.py @@ -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)