Skip to content

Commit 66b0e06

Browse files
authored
R82 resource modules - part1 (#130)
* v5.1.3 * ansible-lint bug fixes * ansible-lint bug fixes * ansible-lint bug fixes * R82 Resource Modules - part 1 * R82 Resource Modules - part 2 * Delete plugins/modules/cp_mgmt_gaia_api.py * Delete .idea/CheckPointAnsibleMgmtCollection.iml
1 parent c031db7 commit 66b0e06

File tree

83 files changed

+12801
-63
lines changed

Some content is hidden

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

83 files changed

+12801
-63
lines changed

galaxy.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ namespace: check_point
99
name: mgmt
1010

1111
# The version of the collection. Must be compatible with semantic versioning
12-
version: 5.2.3
12+
version: 6.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
1616

1717
# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url)
1818
# @nicks:irc/im.site#channel'
1919
authors:
20-
- Or Soffer <orso@checkpoint.com>
21-
- Shiran Golzar <shirango@checkpoint.com>
22-
- Eden Brillant <edenbr@checkpoint.com>
20+
- Or Soffer <orso@checkpoint.com>
21+
- Shiran Golzar <shirango@checkpoint.com>
22+
- Eden Brillant <edenbr@checkpoint.com>
2323

2424

2525
### OPTIONAL but strongly recommended
@@ -30,7 +30,7 @@ description: Check Point collection for the Management Server
3030
# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only
3131
# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file'
3232
license:
33-
- GPL-2.0-or-later
33+
- GPL-2.0-or-later
3434

3535
# The path to the license file for the collection. This path is relative to the root of the collection. This key is
3636
# mutually exclusive with 'license'

plugins/module_utils/checkpoint.py

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
utils,
4040
)
4141

42-
4342
BASE_HEADERS = {
4443
"Content-Type": "application/json",
4544
"User-Agent": "Ansible",
@@ -77,7 +76,8 @@
7776
"package",
7877
"ignore-errors",
7978
"ignore-warnings",
80-
"gateway-uid"
79+
"gateway-uid",
80+
"url"
8181
]
8282

8383
remove_from_set_payload = {
@@ -88,6 +88,11 @@
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

9398
remove_from_add_payload = {"lsm-cluster": ["name"]}
@@ -265,7 +270,7 @@ def is_checkpoint_param(parameter):
265270

266271

267272
def 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

11541159
def 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
12041212
def 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):
12291239
def 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
13981407
def 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

plugins/modules/cp_mgmt_access_section.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,29 @@
4545
description:
4646
- Position in the rulebase.
4747
type: str
48+
relative_position:
49+
description:
50+
- Position in the rulebase.
51+
- Use of this field is relevant only for "add" operation.
52+
type: dict
53+
version_added: "6.0.0"
54+
suboptions:
55+
below:
56+
description:
57+
- Add section below specific rule/section identified by name.
58+
type: str
59+
above:
60+
description:
61+
- Add section above specific rule/section identified by name.
62+
type: str
63+
top:
64+
description:
65+
- Add section to the top of a specific section identified by name.
66+
type: str
67+
bottom:
68+
description:
69+
- Add section to the bottom of a specific section identified by name.
70+
type: str
4871
name:
4972
description:
5073
- Object name.
@@ -106,6 +129,15 @@ def main():
106129
argument_spec = dict(
107130
layer=dict(type="str"),
108131
position=dict(type="str"),
132+
relative_position=dict(
133+
type="dict",
134+
options=dict(
135+
below=dict(type="str"),
136+
above=dict(type="str"),
137+
top=dict(type="str"),
138+
bottom=dict(type="str"),
139+
),
140+
),
109141
name=dict(type="str", required=True),
110142
details_level=dict(type="str", choices=["uid", "standard", "full"]),
111143
ignore_warnings=dict(type="bool"),
@@ -118,6 +150,14 @@ def main():
118150
)
119151
api_call_object = "access-section"
120152

153+
if module.params["relative_position"] is not None:
154+
if module.params["position"] is not None:
155+
raise AssertionError(
156+
"The use of both 'relative_position' and 'position' arguments isn't allowed"
157+
)
158+
module.params["position"] = module.params["relative_position"]
159+
module.params.pop("relative_position")
160+
121161
result = api_call(module, api_call_object)
122162
module.exit_json(**result)
123163

0 commit comments

Comments
 (0)