From 4cc54c0771c677fd3be48374d1dc789515effddc Mon Sep 17 00:00:00 2001 From: sharinetmc Date: Mon, 6 Jan 2025 16:56:06 -0800 Subject: [PATCH] add validation --- parsons/newmode/newmode.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/parsons/newmode/newmode.py b/parsons/newmode/newmode.py index 88140c0454..501f1379e3 100644 --- a/parsons/newmode/newmode.py +++ b/parsons/newmode/newmode.py @@ -36,8 +36,8 @@ def __init__(self, api_user=None, api_password=None, api_version=None): logger.warning( "Newmode V1 API will be sunset in Feburary 2025. To use V2, set api_version=v2.1" ) - self.api_user = check_env.check("NEWMODE_API_USER", api_user) - self.api_password = check_env.check("NEWMODE_API_PASSWORD", api_password) + self.api_user = api_user + self.api_password = api_password self.api_version = api_version self.client = Client(api_user, api_password, api_version) @@ -358,8 +358,8 @@ def __init__( """ self.api_version = api_version self.base_url = V2_API_URL - self.client_id = check_env.check("NEWMODE_API_CLIENT_ID", client_id) - self.client_secret = check_env.check("NEWMODE_API_CLIENT_SECRET", client_secret) + self.client_id = client_id + self.client_secret = client_secret self.headers = {"content-type": "application/json"} def base_request( @@ -601,17 +601,15 @@ def __new__( NewMode Class """ api_version = check_env.check("NEWMODE_API_VERSION", api_version) + client_id = check_env.check("NEWMODE_API_CLIENT_ID", client_id) + client_secret = check_env.check("NEWMODE_API_CLIENT_SECRET", client_secret) + api_user = check_env.check("NEWMODE_API_USER", api_user) + api_password = check_env.check("NEWMODE_API_PASSWORD", api_password) + if api_version.startswith("v2"): - if not client_id: - raise ValueError("Missing client_id") - if not client_secret: - raise ValueError("Missing client_secret") return NewmodeV2( client_id=client_id, client_secret=client_secret, api_version=api_version ) - else: - if not api_user: - raise ValueError("Missing api_user") - if not api_password: - raise ValueError("Missing api_password") + if api_version.startswith("v1"): return NewmodeV1(api_user=api_user, api_password=api_password, api_version=api_version) + raise ValueError(f"{api_version} not supported.")