Skip to content

Commit 0659d96

Browse files
committed
Updated modules batch 3
1 parent 584351e commit 0659d96

34 files changed

+205
-133
lines changed

plugins/httpapi/checkpoint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
DOCUMENTATION = """
99
---
10-
author: Ansible Networking Team
11-
httpapi : checkpoint
10+
author: Ansible Networking Team (@rcarrillocruz)
11+
name: checkpoint
1212
short_description: HttpApi Plugin for Checkpoint devices
1313
description:
1414
- This HttpApi plugin provides methods to connect to Checkpoint
1515
devices over a HTTP(S)-based api.
16-
version_added: "2.8"
16+
version_added: "2.8.0"
1717
options:
1818
domain:
1919
type: str

plugins/module_utils/checkpoint.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060

6161
delete_params = ['name', 'uid', 'layer', 'exception-group-name', 'rule-name', 'package']
6262

63+
remove_from_set_payload = {'lsm-cluster': ['security-profile', 'name-prefix', 'name-suffix', 'main-ip-address'],
64+
'md-permissions-profile': ['permission-level']}
65+
66+
remove_from_add_payload = {'lsm-cluster': ['name']}
67+
6368

6469
# parse failure message with code and response
6570
def parse_fail_message(code, response):
@@ -84,6 +89,14 @@ def is_checkpoint_param(parameter):
8489
return True
8590

8691

92+
def contains_show_identifier_param(payload):
93+
identifier_params = ["name", "uid", "assigned-domain"]
94+
for param in identifier_params:
95+
if payload.get(param) is not None:
96+
return True
97+
return False
98+
99+
87100
# build the payload from the parameters which has value (not None), and they are parameter of checkpoint API as well
88101
def get_payload_from_parameters(params):
89102
payload = {}
@@ -210,7 +223,7 @@ def discard_and_fail(module, code, response, connection, version):
210223

211224
# handle publish command, and wait for it to end if the user asked so
212225
def handle_publish(module, connection, version):
213-
if module.params['auto_publish_session']:
226+
if 'auto_publish_session' in module.params and module.params['auto_publish_session']:
214227
publish_code, publish_response = send_request(connection, version, 'publish')
215228
if publish_code != 200:
216229
discard_and_fail(module, publish_code, publish_response, connection, version)
@@ -275,6 +288,8 @@ def api_command(module, command):
275288
del response['tasks']
276289

277290
result[command] = response
291+
292+
handle_publish(module, connection, version)
278293
else:
279294
discard_and_fail(module, code, response, connection, version)
280295

@@ -287,8 +302,8 @@ def api_call_facts(module, api_call_object, api_call_object_plural_version):
287302
connection = Connection(module._socket_path)
288303
version = get_version(module)
289304

290-
# if there is neither name nor uid, the API command will be in plural version (e.g. show-hosts instead of show-host)
291-
if payload.get("name") is None and payload.get("uid") is None:
305+
# if there isn't an identifier param, the API command will be in plural version (e.g. show-hosts instead of show-host)
306+
if not contains_show_identifier_param(payload):
292307
api_call_object = api_call_object_plural_version
293308

294309
response = handle_call(connection, version, 'show-' + api_call_object, payload, module, False, False)
@@ -331,12 +346,10 @@ def api_call(module, api_call_object):
331346
if equals_code == 200:
332347
# else objects are equals and there is no need for set request
333348
if not equals_response['equals']:
334-
if 'lsm-cluster' == api_call_object:
335-
build_lsm_cluster_payload(payload, 'set')
349+
build_payload(api_call_object, payload, remove_from_set_payload)
336350
handle_call_and_set_result(connection, version, 'set-' + api_call_object, payload, module, result)
337351
elif equals_code == 404:
338-
if 'lsm-cluster' == api_call_object:
339-
build_lsm_cluster_payload(payload, 'add')
352+
build_payload(api_call_object, payload, remove_from_add_payload)
340353
handle_call_and_set_result(connection, version, 'add-' + api_call_object, payload, module, result)
341354
elif module.params['state'] == 'absent':
342355
handle_delete(equals_code, payload, delete_params, connection, version, api_call_object, module, result)
@@ -406,17 +419,6 @@ def build_rulebase_payload(api_call_object, payload, position_number):
406419
return rulebase_payload
407420

408421

409-
def build_lsm_cluster_payload(payload, operator):
410-
fields = ['security-profile', 'name-prefix', 'name-suffix', 'main-ip-address']
411-
if operator == 'add':
412-
del payload['name']
413-
else:
414-
for field in fields:
415-
if field in payload.keys():
416-
del payload[field]
417-
return payload
418-
419-
420422
def build_rulebase_command(api_call_object):
421423
rulebase_command = 'show-' + api_call_object.split('-')[0] + '-rulebase'
422424

@@ -426,6 +428,14 @@ def build_rulebase_command(api_call_object):
426428
return rulebase_command
427429

428430

431+
# remove from payload unrecognized params (used for cases where add payload differs from that of a set)
432+
def build_payload(api_call_object, payload, params_to_remove):
433+
if api_call_object in params_to_remove:
434+
for param in params_to_remove[api_call_object]:
435+
del payload[param]
436+
return payload
437+
438+
429439
# extract rule from rulebase response
430440
def extract_rule_from_rulebase_response(response):
431441
rule = response['rulebase'][0]

plugins/modules/cp_mgmt_show_software_package_details.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
description:
3333
- Gets the software package information from the cloud.
3434
- All operations are performed over Web Services API.
35-
version_added: "2.9"
35+
version_added: "2.0.0"
3636
author: "Or Soffer (@chkp-orso)"
3737
options:
3838
name:

plugins/modules/cp_mgmt_show_task.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232
description:
3333
- Show task progress and details.
3434
- All operations are performed over Web Services API.
35-
version_added: "2.9"
35+
version_added: "2.0.0"
3636
author: "Or Soffer (@chkp-orso)"
3737
options:
3838
task_id:
3939
description:
4040
- Unique identifier of one or more tasks.
4141
type: list
42+
elements: str
4243
details_level:
4344
description:
4445
- The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed
@@ -67,7 +68,7 @@
6768

6869
def main():
6970
argument_spec = dict(
70-
task_id=dict(type='list'),
71+
task_id=dict(type='list', elements='str'),
7172
details_level=dict(type='str', choices=['uid', 'standard', 'full'])
7273
)
7374
argument_spec.update(checkpoint_argument_spec_for_commands)

plugins/modules/cp_mgmt_show_tasks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
description:
3333
- Retrieve all tasks and show their progress and details.
3434
- All operations are performed over Web Services API.
35-
version_added: "2.9"
35+
version_added: "2.0.0"
3636
author: "Or Soffer (@chkp-orso)"
3737
options:
3838
initiator:
@@ -66,6 +66,7 @@
6666
description:
6767
- Sorts results by the given field. By default the results are sorted in the descending order by the task's last update date.
6868
type: list
69+
elements: dict
6970
suboptions:
7071
ASC:
7172
description:
@@ -113,7 +114,7 @@ def main():
113114
to_date=dict(type='str'),
114115
limit=dict(type='int'),
115116
offset=dict(type='int'),
116-
order=dict(type='list', options=dict(
117+
order=dict(type='list', elements='dict', options=dict(
117118
ASC=dict(type='str', choices=['name']),
118119
DESC=dict(type='str', choices=['name'])
119120
)),

plugins/modules/cp_mgmt_simple_gateway.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
description:
3333
- Manages simple-gateway objects on Check Point devices including creating, updating and removing objects.
3434
- All operations are performed over Web Services API.
35-
version_added: "2.9"
35+
version_added: "1.0.0"
3636
author: "Or Soffer (@chkp-orso)"
3737
options:
3838
name:
@@ -105,6 +105,7 @@
105105
description:
106106
- Network interfaces. When a gateway is updated with a new interfaces, the existing interfaces are removed.
107107
type: list
108+
elements: dict
108109
suboptions:
109110
name:
110111
description:
@@ -183,6 +184,7 @@
183184
description:
184185
- Collection of tag identifiers.
185186
type: list
187+
elements: str
186188
topology:
187189
description:
188190
- N/A
@@ -381,18 +383,22 @@
381383
description:
382384
- Server(s) to send alerts to.
383385
type: list
386+
elements: str
384387
send_logs_to_backup_server:
385388
description:
386389
- Backup server(s) to send logs to.
387390
type: list
391+
elements: str
388392
send_logs_to_server:
389393
description:
390394
- Server(s) to send logs to.
391395
type: list
396+
elements: str
392397
tags:
393398
description:
394399
- Collection of tag identifiers.
395400
type: list
401+
elements: str
396402
threat_emulation:
397403
description:
398404
- Threat Emulation blade enabled.
@@ -447,6 +453,7 @@
447453
description:
448454
- Collection of group identifiers.
449455
type: list
456+
elements: str
450457
ignore_warnings:
451458
description:
452459
- Apply changes ignoring warnings.
@@ -512,7 +519,7 @@ def main():
512519
maximum_memory_pool_size=dict(type='int'),
513520
memory_pool_size=dict(type='int')
514521
)),
515-
interfaces=dict(type='list', options=dict(
522+
interfaces=dict(type='list', elements='dict', options=dict(
516523
name=dict(type='str'),
517524
anti_spoofing=dict(type='bool'),
518525
anti_spoofing_settings=dict(type='dict', options=dict(
@@ -532,7 +539,7 @@ def main():
532539
auto_calculated=dict(type='bool'),
533540
specific_zone=dict(type='str')
534541
)),
535-
tags=dict(type='list'),
542+
tags=dict(type='list', elements='str'),
536543
topology=dict(type='str', choices=['automatic', 'external', 'internal']),
537544
topology_settings=dict(type='dict', options=dict(
538545
interface_leads_to_dmz=dict(type='bool'),
@@ -589,13 +596,13 @@ def main():
589596
turn_on_qos_logging=dict(type='bool'),
590597
update_account_log_every=dict(type='int')
591598
)),
592-
one_time_password=dict(type='str'),
599+
one_time_password=dict(type='str', no_log=True),
593600
os_name=dict(type='str'),
594601
save_logs_locally=dict(type='bool'),
595-
send_alerts_to_server=dict(type='list'),
596-
send_logs_to_backup_server=dict(type='list'),
597-
send_logs_to_server=dict(type='list'),
598-
tags=dict(type='list'),
602+
send_alerts_to_server=dict(type='list', elements='str'),
603+
send_logs_to_backup_server=dict(type='list', elements='str'),
604+
send_logs_to_server=dict(type='list', elements='str'),
605+
tags=dict(type='list', elements='str'),
599606
threat_emulation=dict(type='bool'),
600607
threat_extraction=dict(type='bool'),
601608
url_filtering=dict(type='bool'),
@@ -613,7 +620,7 @@ def main():
613620
'yellow']),
614621
comments=dict(type='str'),
615622
details_level=dict(type='str', choices=['uid', 'standard', 'full']),
616-
groups=dict(type='list'),
623+
groups=dict(type='list', elements='str'),
617624
ignore_warnings=dict(type='bool'),
618625
ignore_errors=dict(type='bool')
619626
)

plugins/modules/cp_mgmt_simple_gateway_facts.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
- All operations are performed over Web Services API.
3535
- This module handles both operations, get a specific object and get several objects,
3636
For getting a specific object use the parameter 'name'.
37-
version_added: "2.9"
37+
version_added: "1.0.0"
3838
author: "Or Soffer (@chkp-orso)"
3939
options:
4040
name:
@@ -63,6 +63,7 @@
6363
- Sorts results by the given field. By default the results are sorted in the ascending order by name.
6464
This parameter is relevant only for getting few objects.
6565
type: list
66+
elements: dict
6667
suboptions:
6768
ASC:
6869
description:
@@ -110,15 +111,15 @@ def main():
110111
details_level=dict(type='str', choices=['uid', 'standard', 'full']),
111112
limit=dict(type='int'),
112113
offset=dict(type='int'),
113-
order=dict(type='list', options=dict(
114+
order=dict(type='list', elements='dict', options=dict(
114115
ASC=dict(type='str', choices=['name']),
115116
DESC=dict(type='str', choices=['name'])
116117
)),
117118
show_membership=dict(type='bool')
118119
)
119120
argument_spec.update(checkpoint_argument_spec_for_facts)
120121

121-
module = AnsibleModule(argument_spec=argument_spec)
122+
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
122123

123124
api_call_object = "simple-gateway"
124125
api_call_object_plural_version = "simple-gateways"

plugins/modules/cp_mgmt_tag.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
description:
3333
- Manages tag objects on Check Point devices including creating, updating and removing objects.
3434
- All operations are performed over Web Services API.
35-
version_added: "2.9"
35+
version_added: "1.0.0"
3636
author: "Or Soffer (@chkp-orso)"
3737
options:
3838
name:
@@ -44,6 +44,7 @@
4444
description:
4545
- Collection of tag identifiers.
4646
type: list
47+
elements: str
4748
color:
4849
description:
4950
- Color of the object. Should be one of existing colors.
@@ -101,7 +102,7 @@
101102
def main():
102103
argument_spec = dict(
103104
name=dict(type='str', required=True),
104-
tags=dict(type='list'),
105+
tags=dict(type='list', elements='str'),
105106
color=dict(type='str', choices=['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green',
106107
'khaki', 'orchid', 'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown',
107108
'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', 'coral', 'sea green',

plugins/modules/cp_mgmt_tag_facts.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
- All operations are performed over Web Services API.
3535
- This module handles both operations, get a specific object and get several objects,
3636
For getting a specific object use the parameter 'name'.
37-
version_added: "2.9"
37+
version_added: "1.0.0"
3838
author: "Or Soffer (@chkp-orso)"
3939
options:
4040
name:
@@ -63,6 +63,7 @@
6363
- Sorts results by the given field. By default the results are sorted in the ascending order by name.
6464
This parameter is relevant only for getting few objects.
6565
type: list
66+
elements: dict
6667
suboptions:
6768
ASC:
6869
description:
@@ -103,14 +104,14 @@ def main():
103104
details_level=dict(type='str', choices=['uid', 'standard', 'full']),
104105
limit=dict(type='int'),
105106
offset=dict(type='int'),
106-
order=dict(type='list', options=dict(
107+
order=dict(type='list', elements='dict', options=dict(
107108
ASC=dict(type='str', choices=['name']),
108109
DESC=dict(type='str', choices=['name'])
109110
))
110111
)
111112
argument_spec.update(checkpoint_argument_spec_for_facts)
112113

113-
module = AnsibleModule(argument_spec=argument_spec)
114+
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
114115

115116
api_call_object = "tag"
116117
api_call_object_plural_version = "tags"

0 commit comments

Comments
 (0)