@@ -139,6 +139,44 @@ def save_debug_data(self):
139139 out_file = open (self .debug_file , 'w+' )
140140 out_file .write (json .dumps (self .api_calls , indent = 4 , sort_keys = True ))
141141
142+ def _common_login_logic (self , credentials , continue_last_session , domain , read_only , payload ):
143+ if self .context == "web_api" :
144+ credentials .update ({"continue-last-session" : continue_last_session ,
145+ "read-only" : read_only })
146+
147+ if domain :
148+ credentials .update ({"domain" : domain })
149+ if isinstance (payload , dict ):
150+ credentials .update (payload )
151+
152+ login_res = self .api_call ("login" , credentials )
153+
154+ if login_res .success :
155+ self .sid = login_res .data ["sid" ]
156+ self .domain = domain
157+ if self .api_version is None :
158+ self .api_version = login_res .data ["api-server-version" ]
159+ return login_res
160+
161+ def login_with_api_key (self , api_key , continue_last_session = False , domain = None , read_only = False ,
162+ payload = None ):
163+ """
164+ performs a 'login' API call to the management server
165+
166+ :param api_key: Check Point api-key
167+ :param continue_last_session: [optional] It is possible to continue the last Check Point session
168+ or to create a new one
169+ :param domain: [optional] The name, UID or IP-Address of the domain to login.
170+ :param read_only: [optional] Login with Read Only permissions. This parameter is not considered in case
171+ continue-last-session is true.
172+ :param payload: [optional] More settings for the login command
173+ :returns: APIResponse object
174+ :side-effects: updates the class's uid and server variables
175+ """
176+ credentials = {"api-key" : api_key }
177+
178+ return self ._common_login_logic (credentials , continue_last_session , domain , read_only , payload )
179+
142180 def login (self , username , password , continue_last_session = False , domain = None , read_only = False ,
143181 payload = None ):
144182 """
@@ -157,23 +195,7 @@ def login(self, username, password, continue_last_session=False, domain=None, re
157195 """
158196 credentials = {"user" : username , "password" : password }
159197
160- if self .context == "web_api" :
161- credentials .update ({"continue-last-session" : continue_last_session ,
162- "read-only" : read_only })
163-
164- if domain :
165- credentials .update ({"domain" : domain })
166- if isinstance (payload , dict ):
167- credentials .update (payload )
168-
169- login_res = self .api_call ("login" , credentials )
170-
171- if login_res .success :
172- self .sid = login_res .data ["sid" ]
173- self .domain = domain
174- if self .api_version is None :
175- self .api_version = login_res .data ["api-server-version" ]
176- return login_res
198+ return self ._common_login_logic (credentials , continue_last_session , domain , read_only , payload )
177199
178200 def login_as_root (self , domain = None , payload = None ):
179201 """
0 commit comments