From c58fe3929fa91b3ea3de14d01b7f0c003c36fc19 Mon Sep 17 00:00:00 2001 From: edenbr Date: Sun, 17 Apr 2022 16:22:44 +0300 Subject: [PATCH 1/3] Add sg file --- examples_python2/add_simple_gateway.py | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 examples_python2/add_simple_gateway.py diff --git a/examples_python2/add_simple_gateway.py b/examples_python2/add_simple_gateway.py new file mode 100644 index 0000000..1e9c0f9 --- /dev/null +++ b/examples_python2/add_simple_gateway.py @@ -0,0 +1,57 @@ +from __future__ import print_function + +# A package for reading passwords without displaying them on the console. +import argparse +import getpass + +import sys, os +import time + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + +# cpapi is a library that handles the communication with the Check Point management server. +from cpapi import APIClient, APIClientArgs, APIResponse + + +def main(usera="python-api-wrapper"): + + client_args = APIClientArgs(server="172.23.3.10", port=443, user_agent=usera) + + with APIClient(client_args) as client: + + if client.check_fingerprint() is False: + print("Could not get the server's fingerprint - Check connectivity with the server.") + exit(1) + + # login to server: + login_res = client.login_as_root() + + if login_res.success is False: + print("Login failed:\n{}".format(login_res.error_message)) + exit(1) + else: + print("Logged in kululu") + start = time.time() + res = client.api_call("show-session") + end = time.time() - start + if res.success is True: + + print("The script has been executed successfully in "+ str(end)+"seconds") + + # publish the result + publish_res = client.api_call("publish", {}) + if publish_res.success: + for call in client_args.api_calls: + print(call) + else: + print("Failed to publish the changes.") + else: + print("Failed to run: Error:\n{}".format(res.error_message)) + + +if __name__ == "__main__": + if len(sys.argv)>1: + usera = sys.argv[1] + main(usera) + else: + main() From 96648e5b41635cc1a58a372396fd793a22f8a68c Mon Sep 17 00:00:00 2001 From: edenbr Date: Mon, 25 Apr 2022 16:12:24 +0300 Subject: [PATCH 2/3] Revert "Add sg file" This reverts commit 726298c13acc2f51fccda85035d2b56c23ef4f4f. --- examples_python2/add_simple_gateway.py | 57 -------------------------- 1 file changed, 57 deletions(-) delete mode 100644 examples_python2/add_simple_gateway.py diff --git a/examples_python2/add_simple_gateway.py b/examples_python2/add_simple_gateway.py deleted file mode 100644 index 1e9c0f9..0000000 --- a/examples_python2/add_simple_gateway.py +++ /dev/null @@ -1,57 +0,0 @@ -from __future__ import print_function - -# A package for reading passwords without displaying them on the console. -import argparse -import getpass - -import sys, os -import time - -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) - -# cpapi is a library that handles the communication with the Check Point management server. -from cpapi import APIClient, APIClientArgs, APIResponse - - -def main(usera="python-api-wrapper"): - - client_args = APIClientArgs(server="172.23.3.10", port=443, user_agent=usera) - - with APIClient(client_args) as client: - - if client.check_fingerprint() is False: - print("Could not get the server's fingerprint - Check connectivity with the server.") - exit(1) - - # login to server: - login_res = client.login_as_root() - - if login_res.success is False: - print("Login failed:\n{}".format(login_res.error_message)) - exit(1) - else: - print("Logged in kululu") - start = time.time() - res = client.api_call("show-session") - end = time.time() - start - if res.success is True: - - print("The script has been executed successfully in "+ str(end)+"seconds") - - # publish the result - publish_res = client.api_call("publish", {}) - if publish_res.success: - for call in client_args.api_calls: - print(call) - else: - print("Failed to publish the changes.") - else: - print("Failed to run: Error:\n{}".format(res.error_message)) - - -if __name__ == "__main__": - if len(sys.argv)>1: - usera = sys.argv[1] - main(usera) - else: - main() From 1387ab6be5a051f000199226036b45e4fca7ed24 Mon Sep 17 00:00:00 2001 From: edenbr Date: Thu, 6 Feb 2025 14:14:27 +0200 Subject: [PATCH 3/3] hide api-key from debug file --- cpapi/mgmt_api.py | 5 ++++- setup.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cpapi/mgmt_api.py b/cpapi/mgmt_api.py index 83d2396..dc42370 100644 --- a/cpapi/mgmt_api.py +++ b/cpapi/mgmt_api.py @@ -368,7 +368,10 @@ def api_call(self, command, payload=None, sid=None, wait_for_task=True, timeout= # would not appear as plaintext in the debug file. if command == "login": json_data = compatible_loads(_data) - json_data["password"] = "****" + if "password" in json_data: + json_data["password"] = "****" + if "api-key" in json_data: + json_data["api-key"] = "****" _data = json.dumps(json_data) if self.debug_file: diff --git a/setup.py b/setup.py index 9b5a5b1..b35bd99 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="cp-mgmt-api-sdk", - version="1.8.0", + version="1.9.0", author="API team", author_email="api_team@checkpoint.com", license='Apache 2.0',