From e0e6b544fe86ea141d9ec6b7d57eb3c3d7c24db4 Mon Sep 17 00:00:00 2001 From: Romazes Date: Fri, 20 Dec 2024 16:50:43 +0200 Subject: [PATCH] refactor: use negative local id if cloud id is not provided --- lean/components/api/auth0_client.py | 4 ++-- .../config/project_config_manager.py | 2 +- lean/components/util/auth0_helper.py | 2 +- lean/models/json_module.py | 24 +------------------ 4 files changed, 5 insertions(+), 27 deletions(-) diff --git a/lean/components/api/auth0_client.py b/lean/components/api/auth0_client.py index 313c7528..b55bda37 100644 --- a/lean/components/api/auth0_client.py +++ b/lean/components/api/auth0_client.py @@ -52,7 +52,7 @@ def read(self, brokerage_id: str) -> QCAuth0Authorization: return QCAuth0Authorization(authorization=None) @staticmethod - def authorize(brokerage_id: str, logger: Logger, project_id: str = None) -> None: + def authorize(brokerage_id: str, logger: Logger, project_id: int) -> None: """Starts the authorization process for a brokerage. :param brokerage_id: the id of the brokerage to start the authorization process for @@ -63,7 +63,7 @@ def authorize(brokerage_id: str, logger: Logger, project_id: str = None) -> Non full_url = f"{API_BASE_URL}live/auth0/authorize?brokerage={brokerage_id}" - if project_id: + if project_id > 0: full_url += f"&projectId={project_id}" logger.info(f"Please open the following URL in your browser to authorize the LEAN CLI.") diff --git a/lean/components/config/project_config_manager.py b/lean/components/config/project_config_manager.py index dd0b7609..5c8d1595 100644 --- a/lean/components/config/project_config_manager.py +++ b/lean/components/config/project_config_manager.py @@ -81,7 +81,7 @@ def get_cloud_id(self, project_directory: Path) -> int: """ project_config = self.get_project_config(project_directory) - return project_config.get("cloud-id", default=0) + return project_config.get("cloud-id") or -project_config.get("local-id") def get_latest_live_directory(self, project_directory: Path) -> Path: """Returns the path of the latest live directory. diff --git a/lean/components/util/auth0_helper.py b/lean/components/util/auth0_helper.py index 929d6e1f..8450a7be 100644 --- a/lean/components/util/auth0_helper.py +++ b/lean/components/util/auth0_helper.py @@ -16,7 +16,7 @@ from lean.components.util.logger import Logger -def get_authorization(auth0_client: Auth0Client, brokerage_id: str, logger: Logger, project_id: str = None) -> QCAuth0Authorization: +def get_authorization(auth0_client: Auth0Client, brokerage_id: str, logger: Logger, project_id: int) -> QCAuth0Authorization: """Gets the authorization data for a brokerage, authorizing if necessary. :param auth0_client: An instance of Auth0Client, containing methods to interact with live/auth0/* API endpoints. diff --git a/lean/models/json_module.py b/lean/models/json_module.py index 347d11ea..dfca26d3 100644 --- a/lean/models/json_module.py +++ b/lean/models/json_module.py @@ -175,27 +175,6 @@ def convert_variable_to_lean_key(self, variable_key: str) -> str: """ return variable_key.replace('_', '-') - def validate_project_id(self, project_id: int, display_name: str) -> str: - """ - Validates the given project ID and raises an exception for specific conditions. - - Args: - project_id (int): The project ID to validate. - display_name (str): The display name of the module. - - Returns: - int: The validated project ID. - - Raises: - NotImplementedError: If the project ID is 0 and the display name is "CharlesSchwab". - """ - if project_id == 0 and display_name.strip().lower() == "CharlesSchwab".lower(): - raise NotImplementedError( - "Cloud ID is missing from the project configuration for the module 'CharlesSchwabBrokerage'. " - "Please ensure the project is synchronized with the cloud by pushing or pulling the project." - ) - return str(project_id) - def config_build(self, lean_config: Dict[str, Any], logger: Logger, @@ -240,9 +219,8 @@ def config_build(self, logger.debug(f"skipping configuration '{configuration._id}': no choices available.") continue elif isinstance(configuration, AuthConfiguration): - project_id = self.validate_project_id(lean_config.get("project-id"), self._display_name.lower()) auth_authorizations = get_authorization(container.api_client.auth0, self._display_name.lower(), - logger, project_id) + logger, lean_config.get("project-id")) logger.debug(f'auth: {auth_authorizations}') configuration._value = auth_authorizations.get_authorization_config_without_account() for inner_config in self._lean_configs: