Skip to content

Commit 3b0df25

Browse files
authored
Merge pull request #71 from chkp-edenbr/master
R81.20 Modules
2 parents bebadad + 8496d35 commit 3b0df25

File tree

193 files changed

+10773
-1746
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+10773
-1746
lines changed

CHANGELOG.rst

Lines changed: 230 additions & 0 deletions
Large diffs are not rendered by default.

galaxy.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace: check_point
99
name: mgmt
1010

1111
# The version of the collection. Must be compatible with semantic versioning
12-
version: 1.0.6
12+
version: 3.0.0
1313

1414
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
1515
readme: README.md
@@ -18,6 +18,8 @@ readme: README.md
1818
# @nicks:irc/im.site#channel'
1919
authors:
2020
- Or Soffer <orso@checkpoint.com>
21+
- Shiran Golzar <shirango@checkpoint.com>
22+
- Eden Brillant <edenbr@checkpoint.com>
2123

2224

2325
### OPTIONAL but strongly recommended

meta/execution-environment.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
version: 1
3+
4+
build_arg_defaults:
5+
EE_BASE_IMAGE: 'quay.io/ansible/ansible-runner:latest'
6+
7+
dependencies:
8+
galaxy: requirements.yml

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/checkpoint_access_layer_facts.py

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)