From b5032c0dca82b0401aed3d5f2fbc05335eff8fb5 Mon Sep 17 00:00:00 2001 From: Guillaume Dedrie Date: Fri, 6 Dec 2024 16:56:18 +0100 Subject: [PATCH 1/3] [client] simplify url verification using a more Pythonic style --- pycti/api/opencti_api_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycti/api/opencti_api_client.py b/pycti/api/opencti_api_client.py index a6f7e7bcc..0240c0cf4 100644 --- a/pycti/api/opencti_api_client.py +++ b/pycti/api/opencti_api_client.py @@ -120,7 +120,7 @@ def __init__( self.ssl_verify = ssl_verify self.cert = cert self.proxies = proxies - if url is None or len(url) == 0: + if not url: raise ValueError("An URL must be set") if token is None or len(token) == 0 or token == "ChangeMe": raise ValueError("A TOKEN must be set") From f6ce9d8fd4e783944eef8fef2c4bdb3467b24c2a Mon Sep 17 00:00:00 2001 From: Guillaume Dedrie Date: Fri, 6 Dec 2024 16:56:35 +0100 Subject: [PATCH 2/3] [client] simplify token verification using a more Pythonic style --- pycti/api/opencti_api_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycti/api/opencti_api_client.py b/pycti/api/opencti_api_client.py index 0240c0cf4..62a1c27b9 100644 --- a/pycti/api/opencti_api_client.py +++ b/pycti/api/opencti_api_client.py @@ -122,7 +122,7 @@ def __init__( self.proxies = proxies if not url: raise ValueError("An URL must be set") - if token is None or len(token) == 0 or token == "ChangeMe": + if not token or token == "ChangeMe": raise ValueError("A TOKEN must be set") # Configure logger From 46c68384377870671ddc00b01f3d4ad119ee7c1e Mon Sep 17 00:00:00 2001 From: Guillaume Dedrie Date: Fri, 6 Dec 2024 16:57:15 +0100 Subject: [PATCH 3/3] [client] simplify session populate code on bootstrap --- pycti/api/opencti_api_client.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pycti/api/opencti_api_client.py b/pycti/api/opencti_api_client.py index 62a1c27b9..6222cbabf 100644 --- a/pycti/api/opencti_api_client.py +++ b/pycti/api/opencti_api_client.py @@ -137,11 +137,9 @@ def __init__( "Authorization": "Bearer " + token, } - if auth is not None: - self.session = requests.session() + self.session = requests.session() + if auth: self.session.auth = auth - else: - self.session = requests.session() # Define the dependencies self.work = OpenCTIApiWork(self)