Skip to content

Commit

Permalink
Add support to connect smart-1 cloud (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
chkp-royl authored Jul 27, 2022
1 parent c5f21f4 commit cc61452
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 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", sync_frequency=2):
user_agent="python-api-wrapper", sync_frequency=2, cloud_mgmt_id=""):
self.port = port
# management server fingerprint
self.fingerprint = fingerprint
Expand Down Expand Up @@ -74,6 +74,8 @@ def __init__(self, port=None, fingerprint=None, sid=None, server="127.0.0.1", ht
self.user_agent = user_agent
# Interval size in seconds of the task update
self.sync_frequency = sync_frequency
# Smart-1 Cloud management UID
self.cloud_mgmt_id = cloud_mgmt_id


class APIClient:
Expand Down Expand Up @@ -124,6 +126,8 @@ def __init__(self, api_client_args=None):
self.user_agent = api_client_args.user_agent
# Interval size in seconds of the task update
self.sync_frequency = api_client_args.sync_frequency
# Smart-1 Cloud management UID
self.cloud_mgmt_id = api_client_args.cloud_mgmt_id

def __enter__(self):
return self
Expand Down Expand Up @@ -318,7 +322,18 @@ def api_call(self, command, payload=None, sid=None, wait_for_task=True, timeout=

# init https connection. if single connection is True, use last connection
conn = self.get_https_connection()
url = "/" + self.context + "/" + (("v" + str(self.api_version) + "/") if self.api_version else "") + command

url = ""
if self.cloud_mgmt_id != "":
url += "/" + self.cloud_mgmt_id

url += "/" + self.context

if self.api_version:
url += "/v" + str(self.api_version)

url += "/" + command

response = None
try:
# Send the data to the server
Expand Down

0 comments on commit cc61452

Please sign in to comment.