Skip to content

Commit 315ed9b

Browse files
authored
Merge pull request #31 from chkp-ophirk/master
adding dynamic_content and simulate_packet modules
2 parents 32453af + 81daf82 commit 315ed9b

File tree

7 files changed

+559
-2
lines changed

7 files changed

+559
-2
lines changed

CHANGELOG.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ Check_Point.gaia Release Notes
44

55
.. contents:: Topics
66

7+
8+
v7.0.0
9+
======
10+
11+
Release Summary
12+
---------------
13+
14+
this release 7.0.0 of ``check_point.gaia``, released on 2025-1-1.
15+
16+
New Modules
17+
-----------
18+
19+
- check_point.gaia.cp_gaia_dynamic_content – install policy on a dynamic layer Check Point machine over Web Services API.
20+
- check_point.gaia.cp_gaia_dynamic_content_layer_facts – get the details of the installed policy on a given dynamic layer on a Check Point machine over Web Services API.
21+
- check_point.gaia.cp_gaia_dynamic_content_layers_facts – get the details of all dynamic layers on a Check Point machine over Web Services API.
22+
- check_point.gaia.cp_gaia_simulate_packet – simulate packet rulebase execution on a Check Point machine over Web Services API.
23+
24+
725
v6.0.0
826
======
927

@@ -21,6 +39,7 @@ cp_gaia_virtual_gateway – manages virtual-gateway objects on Check Point machi
2139
cp_gaia_virtual_gateway_facts – get virtual-gateway objects facts on Check Point machine over Web Services API.
2240
cp_gaia_virtual_vsnext_state_facts – get the VSNext state on Check Point machine over Web Services API.
2341

42+
2443
v5.0.1
2544
======
2645

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ Modules
127127
* `cp_gaia_virtual_gateway` – manages virtual-gateway objects on Check Point machine over Web Services API.
128128
* `cp_gaia_virtual_gateway_facts` – get virtual-gateway objects facts on Check Point machine over Web Services API.
129129
* `cp_gaia_virtual_vsnext_state_facts` – get the VSNext state on Check Point machine over Web Services API.
130+
* `cp_gaia_dynamic_content` – install policy on a dynamic layer Check Point machine over Web Services API.
131+
* `cp_gaia_dynamic_content_layer_facts` – get the details of the installed policy on a given dynamic layer on a Check Point machine over Web Services API.
132+
* `cp_gaia_dynamic_content_layers_facts` – get the details of all dynamic layers on a Check Point machine over Web Services API.
133+
* `cp_gaia_simulate_packet` – simulate packet rulebase execution on a Check Point machine over Web Services API.
130134

131135
### Code of Conduct
132136
This collection follows the Ansible project's

plugins/module_utils/checkpoint.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
wait_for_task=dict(type='bool', default=True)
4242
)
4343

44+
checkpoint_argument_spec_for_async_false = dict(
45+
wait_for_task=dict(type='bool', default=False)
46+
)
47+
4448
checkpoint_argument_spec_for_all = dict(
4549
version=dict(type='str'),
4650
virtual_system_id=dict(type="int", required=False)
@@ -72,8 +76,11 @@ def idempotency_check(old_val, new_val):
7276

7377
# if user insert a specific version, we add it to the url
7478
def get_version(module):
75-
res = ('v' + module.params['version'] + '/') if module.params.get('version') else ''
76-
del module.params['version']
79+
if module.params.get('version'):
80+
res = ('v' + module.params['version'] + '/')
81+
del module.params['version']
82+
else:
83+
res = ''
7784
return res
7885

7986

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Ansible module to manage CheckPoint Firewall (c) 2019
5+
#
6+
# Ansible is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Ansible is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
20+
from __future__ import (absolute_import, division, print_function)
21+
22+
__metaclass__ = type
23+
24+
DOCUMENTATION = """
25+
author: Ophir Khill (@chkp-ophirk)
26+
description:
27+
- Installing policy
28+
module: cp_gaia_dynamic_content
29+
options:
30+
version:
31+
description: GAIA api version for ex 1.8
32+
required: False
33+
type: str
34+
policy_path:
35+
description: path for the policy json
36+
required: True
37+
type: str
38+
dry_run:
39+
description: dry_run set to true will apply the change, wheres set to false it will only validate the changes
40+
required: True
41+
type: bool
42+
tags:
43+
description: list of tags for the operation
44+
required: True
45+
type: list
46+
elements: str
47+
comments:
48+
description: comments for the operation
49+
required: True
50+
type: str
51+
wait_for_task:
52+
description: Wait for task or return immediately.
53+
required: False
54+
default: False
55+
type: bool
56+
short_description: installing policy
57+
version_added: '7.0.0'
58+
notes:
59+
- its advisable to perform with wait_for_task set to false and refer to show_task command
60+
"""
61+
62+
EXAMPLES = """
63+
- name: Initial setup
64+
check_point.gaia.cp_gaia_dynamic_content:
65+
policy_path: "/home/admin/policy.json"
66+
dry_run: false
67+
tags: ["JIRA-12345", "apply layer1"]
68+
comments: "testing the api"
69+
wait_for_task: true
70+
"""
71+
72+
RETURN = """
73+
change_summary:
74+
description: change-summary after installing the new policy.
75+
returned: always.
76+
type: dict
77+
"""
78+
79+
from ansible.module_utils.basic import AnsibleModule
80+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_all
81+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import chkp_api_operation
82+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_async_false
83+
import json
84+
85+
NO_CHANGES = \
86+
{
87+
"layers": [],
88+
"objects": {
89+
"create": [],
90+
"delete": [],
91+
"modify": []
92+
}
93+
}
94+
95+
KEYS_TO_REMOVE = ['comments', 'tags', 'dry-run']
96+
97+
98+
# load json
99+
def load_json_file(file_path):
100+
try:
101+
with open(file_path, 'r') as file:
102+
data = json.load(file)
103+
# remove unnecessary arguments
104+
for key in KEYS_TO_REMOVE:
105+
data.pop(key, None)
106+
107+
return data, None
108+
except Exception as e:
109+
return None, str(e)
110+
111+
112+
# check if the policy has changed
113+
def has_changed(result):
114+
changed = True
115+
change_summary = {}
116+
117+
try:
118+
change_summary = result['set_dynamic_content']['tasks'][0]['task-details'][0]['change-summary']
119+
except KeyError:
120+
# no change summary
121+
return changed
122+
123+
if change_summary == NO_CHANGES:
124+
changed = False
125+
126+
return changed
127+
128+
129+
def main():
130+
# arguments for the module:
131+
fields = {
132+
'policy_path': dict(type='str', required=True),
133+
'dry_run': dict(type='bool', required=True),
134+
'comments': dict(type='str', required=True),
135+
'tags': dict(type='list', elements='str', required=True)
136+
}
137+
fields.update(checkpoint_argument_spec_for_async_false)
138+
fields.update(checkpoint_argument_spec_for_all)
139+
module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
140+
141+
file_path = module.params['policy_path']
142+
143+
# load policy
144+
result, error = load_json_file(file_path)
145+
if error:
146+
module.exit_json(changed=False, json_data=result)
147+
148+
# add policy to request
149+
del module.params['policy_path']
150+
module.params.update(result)
151+
# call api operation
152+
api_call_object = "set-dynamic-content"
153+
res = chkp_api_operation(module, api_call_object)
154+
# fill in 'changed' field
155+
res['changed'] = has_changed(res)
156+
157+
module.exit_json(**res)
158+
159+
160+
if __name__ == "__main__":
161+
main()
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Ansible module to manage CheckPoint Firewall (c) 2019
5+
#
6+
# Ansible is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Ansible is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
20+
from __future__ import (absolute_import, division, print_function)
21+
22+
__metaclass__ = type
23+
24+
DOCUMENTATION = """
25+
author: Ophir Khill (@chkp-ophirk)
26+
description:
27+
- getting information of a chosen dynamic layer.
28+
module: cp_gaia_dynamic_content_layer_facts
29+
options:
30+
version:
31+
description: Gaia API version for example 1.6.
32+
required: False
33+
type: str
34+
name:
35+
description: dynamic layer to show
36+
required: true
37+
type: str
38+
wait_for_task:
39+
description: Wait for task or return immediately.
40+
required: False
41+
default: True
42+
type: bool
43+
short_description: getting information of the chosen dynamic layer.
44+
version_added: '7.0.0'
45+
46+
"""
47+
48+
EXAMPLES = """
49+
- name: show dynamic layer
50+
check_point.gaia.cp_gaia_dynamic_content_layer_facts:
51+
name: dynamic_layer
52+
"""
53+
54+
RETURN = """
55+
layer_summary:
56+
description: the details of the installed policy on the requested layer
57+
returned: always.
58+
type: dict
59+
"""
60+
61+
from ansible.module_utils.basic import AnsibleModule
62+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import chkp_api_call, checkpoint_argument_spec_for_all
63+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import chkp_api_operation
64+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_async
65+
66+
67+
def main():
68+
# arguments for the module:
69+
fields = dict(
70+
name=dict(type='str', required=True)
71+
)
72+
fields.update(checkpoint_argument_spec_for_async)
73+
fields.update(checkpoint_argument_spec_for_all)
74+
module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
75+
api_call_object = 'show-dynamic-layer'
76+
77+
res = chkp_api_operation(module, api_call_object)
78+
79+
# this action does not change system configuration
80+
res['changed'] = False
81+
82+
module.exit_json(**res)
83+
84+
85+
if __name__ == "__main__":
86+
main()
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Ansible module to manage CheckPoint Firewall (c) 2019
5+
#
6+
# Ansible is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Ansible is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
20+
from __future__ import (absolute_import, division, print_function)
21+
22+
__metaclass__ = type
23+
24+
DOCUMENTATION = """
25+
author: Ophir Khill (@chkp-ophirk)
26+
description:
27+
- get the names and metadata of all dynamic layers
28+
module: cp_gaia_dynamic_content_layers_facts
29+
options:
30+
version:
31+
description: Gaia API version for example 1.6.
32+
required: False
33+
type: str
34+
wait_for_task:
35+
description: Wait for task or return immediately.
36+
required: False
37+
default: True
38+
type: bool
39+
short_description: get the names and meta-data of all dynamic layers.
40+
version_added: '7.0.0'
41+
42+
"""
43+
44+
EXAMPLES = """
45+
- name: show dynamic layers
46+
check_point.gaia.cp_gaia_dynamic_content_layers_facts:
47+
"""
48+
49+
RETURN = """
50+
hostname:
51+
description: the names and metadata of all dynamic layers.
52+
returned: always.
53+
type: dict
54+
"""
55+
56+
from ansible.module_utils.basic import AnsibleModule
57+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import chkp_api_call, checkpoint_argument_spec_for_all
58+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import chkp_api_operation
59+
from ansible_collections.check_point.gaia.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_async
60+
61+
62+
def main():
63+
# arguments for the module:
64+
fields = dict()
65+
fields.update(checkpoint_argument_spec_for_async)
66+
fields.update(checkpoint_argument_spec_for_all)
67+
module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
68+
api_call_object = 'show-dynamic-layers'
69+
70+
res = chkp_api_operation(module, api_call_object)
71+
72+
# this action does not change system configuration
73+
res['changed'] = False
74+
75+
module.exit_json(**res)
76+
77+
78+
if __name__ == "__main__":
79+
main()

0 commit comments

Comments
 (0)