Skip to content

Commit

Permalink
use existing debug_file to decide if to save logs
Browse files Browse the repository at this point in the history
  • Loading branch information
chkp-royl committed Nov 18, 2021
1 parent b7b2500 commit b86eae3
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions cpapi/mgmt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class APIClientArgs:
def __init__(self, port=None, fingerprint=None, sid=None, server="127.0.0.1", http_debug_level=0,
api_calls=None, debug_file="", proxy_host=None, proxy_port=8080,
api_version=None, unsafe=False, unsafe_auto_accept=False, context="web_api", single_conn=True,
user_agent="python-api-wrapper", save_logs=True):
user_agent="python-api-wrapper"):
self.port = port
# management server fingerprint
self.fingerprint = fingerprint
Expand Down Expand Up @@ -72,8 +72,6 @@ def __init__(self, port=None, fingerprint=None, sid=None, server="127.0.0.1", ht
self.single_conn = single_conn
# User agent will be use in api call request header
self.user_agent = user_agent
# Flag whether or not save logs of api calls
self.save_logs = save_logs


class APIClient:
Expand Down Expand Up @@ -122,8 +120,6 @@ def __init__(self, api_client_args=None):
self.single_conn = api_client_args.single_conn
# User agent will be use in api call request header
self.user_agent = api_client_args.user_agent
# Flag whether or not save logs of api calls
self.save_logs = api_client_args.save_logs

def __enter__(self):
return self
Expand All @@ -134,9 +130,8 @@ def __exit__(self, exc_type, exc_value, traceback):
if self.sid:
self.api_call("logout")
self.close_connection()
if self.save_logs:
# save debug data with api calls to disk
self.save_debug_data()
# save debug data with api calls to disk
self.save_debug_data()

def get_port(self):
"""returns the port of the API client (int)"""
Expand Down Expand Up @@ -350,7 +345,7 @@ def api_call(self, command, payload=None, sid=None, wait_for_task=True, timeout=
json_data["password"] = "****"
_data = json.dumps(json_data)

if self.save_logs:
if self.debug_file:
# Store the request and the reply (for debug purpose).
_api_log = {
"request": {
Expand Down

0 comments on commit b86eae3

Please sign in to comment.