3939 utils ,
4040)
4141
42-
4342BASE_HEADERS = {
4443 "Content-Type" : "application/json" ,
4544 "User-Agent" : "Ansible" ,
7776 "package" ,
7877 "ignore-errors" ,
7978 "ignore-warnings" ,
80- "gateway-uid"
79+ "gateway-uid" ,
80+ "url"
8181]
8282
8383remove_from_set_payload = {
8888 "main-ip-address" ,
8989 ],
9090 "md-permissions-profile" : ["permission-level" ],
91+ "access-section" : ["position" ],
92+ "nat-section" : ["position" ],
93+ "https-section" : ["position" ],
94+ "mobile-access-section" : ["position" ],
95+ "mobile-access-profile-section" : ["position" ],
9196}
9297
9398remove_from_add_payload = {"lsm-cluster" : ["name" ]}
@@ -265,7 +270,7 @@ def is_checkpoint_param(parameter):
265270
266271
267272def contains_show_identifier_param (payload ):
268- identifier_params = ["name" , "uid" , "assigned-domain" , "task-id" , "signature" ]
273+ identifier_params = ["name" , "uid" , "assigned-domain" , "task-id" , "signature" , "url" ]
269274 for param in identifier_params :
270275 if payload .get (param ) is not None :
271276 return True
@@ -283,9 +288,9 @@ def get_payload_from_parameters(params):
283288 parameter .replace ("_" , "-" )
284289 ] = get_payload_from_parameters (parameter_value )
285290 elif (
286- isinstance (parameter_value , list )
287- and len (parameter_value ) != 0
288- and isinstance (parameter_value [0 ], dict )
291+ isinstance (parameter_value , list )
292+ and len (parameter_value ) != 0
293+ and isinstance (parameter_value [0 ], dict )
289294 ):
290295 payload_list = []
291296 for element_dict in parameter_value :
@@ -296,12 +301,12 @@ def get_payload_from_parameters(params):
296301 else :
297302 # special handle for this param in order to avoid two params called "version"
298303 if (
299- parameter == "gateway_version"
300- or parameter == "cluster_version"
301- or parameter == "server_version"
302- or parameter == "check_point_host_version"
303- or parameter == "target_version"
304- or parameter == "vsx_version"
304+ parameter == "gateway_version"
305+ or parameter == "cluster_version"
306+ or parameter == "server_version"
307+ or parameter == "check_point_host_version"
308+ or parameter == "target_version"
309+ or parameter == "vsx_version"
305310 ):
306311 parameter = "version"
307312
@@ -320,8 +325,8 @@ def wait_for_task(module, version, connection, task_id):
320325 task_complete = False
321326 minutes_until_timeout = 30
322327 if (
323- module .params ["wait_for_task_timeout" ] is not None
324- and module .params ["wait_for_task_timeout" ] >= 0
328+ module .params ["wait_for_task_timeout" ] is not None
329+ and module .params ["wait_for_task_timeout" ] >= 0
325330 ):
326331 minutes_until_timeout = module .params ["wait_for_task_timeout" ]
327332 max_num_iterations = minutes_until_timeout * 30
@@ -1152,7 +1157,7 @@ def build_rulebase_payload(api_call_object, payload, position_number):
11521157
11531158
11541159def build_rulebase_command (api_call_object ):
1155- rulebase_command = "show-" + api_call_object . split ( "-" )[ 0 ] + "-rulebase "
1160+ rulebase_command = "show-" + api_call_object + "base "
11561161
11571162 if api_call_object == "threat-exception" :
11581163 rulebase_command = "show-threat-rule-exception-rulebase"
@@ -1195,17 +1200,22 @@ def get_relevant_show_rulebase_command(api_call_object):
11951200 return "show-threat-rule-exception-rulebase"
11961201 elif api_call_object == 'nat-rule' :
11971202 return 'show-nat-rulebase'
1198- # uncomment code below when https module is added as a crud module
1199- # elif api_call_object == 'https-rule':
1200- # return 'show-https-rulebase'
1203+ elif api_call_object == 'https-rule' :
1204+ return 'show-https-rulebase'
1205+ elif api_call_object == 'mobile-access-rule' :
1206+ return 'show-mobile-access-rulebase'
1207+ elif api_call_object == 'mobile-access-profile-rule' :
1208+ return 'show-mobile-access-profile-rulebase'
12011209
12021210
12031211# returns the show rulebase payload with the relevant required identifiers params
12041212def get_relevant_show_rulebase_identifier_payload (api_call_object , payload ):
1213+ show_rulebase_payload = {}
12051214 if api_call_object == 'nat-rule' :
12061215 show_rulebase_payload = {'package' : payload ['package' ]}
12071216
1208- else :
1217+ # mobile-access-x apis don't have an identifier in show rulebase command
1218+ elif 'mobile-access' not in api_call_object :
12091219 show_rulebase_payload = {'name' : payload ['layer' ]}
12101220
12111221 if api_call_object == 'threat-exception' :
@@ -1229,7 +1239,6 @@ def get_relevant_layer_or_package_identifier(api_call_object, payload):
12291239def is_equals_with_position_param (
12301240 payload , connection , version , api_call_object
12311241):
1232-
12331242 (
12341243 position_number ,
12351244 section_according_to_position ,
@@ -1396,18 +1405,13 @@ def api_call_for_rule(module, api_call_object):
13961405
13971406# check if call is in plural form
13981407def call_is_plural (api_call_object , payload ):
1399- is_plural = False
1400- if "access" in api_call_object and payload .get ("layer" ) is None :
1401- is_plural = True
1402- elif "threat" in api_call_object and payload .get ("layer" ) is None :
1403- is_plural = True
1404- elif (
1405- "nat" in api_call_object
1406- and payload .get ("name" ) is None
1407- and payload .get ("rule-number" ) is None
1408- ):
1409- is_plural = True
1410- return is_plural
1408+ if payload .get ("name" ) is not None or payload .get ("rule-number" ) is not None and \
1409+ ("nat" in api_call_object or "mobile-access" in api_call_object ):
1410+ return False
1411+ if payload .get ("layer" ) is None and \
1412+ ("access" in api_call_object or "threat" in api_call_object or "https" in api_call_object ):
1413+ return True
1414+ return False
14111415
14121416
14131417# handle api call facts for rule
@@ -1418,7 +1422,7 @@ def api_call_facts_for_rule(
14181422 connection = Connection (module ._socket_path )
14191423 version = get_version (module )
14201424
1421- # if there is no layer, the API command will be in plural version (e.g. show-hosts instead of show-host )
1425+ # if there is no layer, the API command will be in plural version (e.g. show-https-rulebase instead of show-https-rule )
14221426 if call_is_plural (api_call_object , payload ):
14231427 api_call_object = api_call_object_plural_version
14241428
@@ -1646,14 +1650,14 @@ def handle_publish(self, connection, version, payload):
16461650
16471651 # handle call
16481652 def handle_call (
1649- self ,
1650- connection ,
1651- version ,
1652- api_url ,
1653- payload ,
1654- to_discard_on_failure ,
1655- session_uid = None ,
1656- to_publish = False ,
1653+ self ,
1654+ connection ,
1655+ version ,
1656+ api_url ,
1657+ payload ,
1658+ to_discard_on_failure ,
1659+ session_uid = None ,
1660+ to_publish = False ,
16571661 ):
16581662 code , response = send_request (connection , version , api_url , payload )
16591663 if code != 200 :
@@ -1662,7 +1666,7 @@ def handle_call(
16621666 code , response , connection , version , session_uid
16631667 )
16641668 elif "object_not_found" not in response .get (
1665- "code"
1669+ "code"
16661670 ) and "not found" not in response .get ("message" ):
16671671 raise _fail_json (
16681672 "Checkpoint session with ID: {0}" .format (session_uid )
@@ -1690,13 +1694,13 @@ def handle_call(
16901694
16911695 # handle the call and set the result with 'changed' and teh response
16921696 def handle_add_and_set_result (
1693- self ,
1694- connection ,
1695- version ,
1696- api_url ,
1697- payload ,
1698- session_uid ,
1699- auto_publish_session = False ,
1697+ self ,
1698+ connection ,
1699+ version ,
1700+ api_url ,
1701+ payload ,
1702+ session_uid ,
1703+ auto_publish_session = False ,
17001704 ):
17011705 code , response = self .handle_call (
17021706 connection ,
@@ -1751,15 +1755,15 @@ def api_call_facts(self, connection, payload, api_call_object, version):
17511755
17521756 # handle api call
17531757 def api_call (
1754- self ,
1755- connection ,
1756- payload ,
1757- remove_keys ,
1758- api_call_object ,
1759- state ,
1760- equals_response ,
1761- version ,
1762- delete_params ,
1758+ self ,
1759+ connection ,
1760+ payload ,
1761+ remove_keys ,
1762+ api_call_object ,
1763+ state ,
1764+ equals_response ,
1765+ version ,
1766+ delete_params ,
17631767 ):
17641768 result = {}
17651769 auto_publish_session = False
0 commit comments