-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from chkp-shirango/master
Adding a new module "access-rules"
- Loading branch information
Showing
5 changed files
with
464 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from __future__ import (absolute_import, division, print_function) | ||
|
||
__metaclass__ = type | ||
|
||
|
||
from ansible.errors import AnsibleActionFail | ||
from ansible.plugins.action import ActionBase | ||
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import \ | ||
prepare_rule_params_for_execute_module, check_if_to_publish_for_action | ||
|
||
|
||
class ActionModule(ActionBase): | ||
|
||
def run(self, tmp=None, task_vars=None): | ||
|
||
module = super(ActionModule, self).run(tmp, task_vars) | ||
|
||
result = self._execute_module(module_name='check_point.mgmt.cp_mgmt_access_rules', module_args=self._task.args, | ||
task_vars=task_vars, tmp=tmp) | ||
|
||
if 'msg' in result.keys(): | ||
raise AnsibleActionFail(result['msg']) | ||
|
||
module_args = self._task.args | ||
|
||
fields = {'position', 'layer', 'auto_publish_session'} | ||
rules_list = module_args['rules'] | ||
for rule in rules_list: | ||
for field in fields: | ||
if field in rule.keys(): | ||
raise AnsibleActionFail('Unsupported parameter ' + field + ' for rule') | ||
# check_fields_for_rule_action_module(module_args) | ||
rules_list = self._task.args['rules'] | ||
position = 1 | ||
|
||
for rule in rules_list: | ||
rule, position = prepare_rule_params_for_execute_module(rule=rule, module_args=module_args, | ||
position=position) | ||
result['rule: ' + rule['name']] = self._execute_module(module_name='check_point.mgmt.cp_mgmt_access_rule', | ||
module_args=rule, | ||
task_vars=task_vars, tmp=tmp, wrap_async=False) | ||
if 'changed' in result['rule: ' + rule['name']].keys() and \ | ||
result['rule: ' + rule['name']]['changed'] is True: | ||
result['changed'] = True | ||
if 'failed' in result['rule: ' + rule['name']].keys() and result['rule: ' + rule['name']]['failed'] is True: | ||
temp = result['rule: ' + rule['name']].copy() | ||
result = {} | ||
result['rule: ' + rule['name']] = temp | ||
result['failed'] = True | ||
result['discard:'] = self._execute_module(module_name='check_point.mgmt.cp_mgmt_discard', | ||
module_args={}, task_vars=task_vars, tmp=tmp) | ||
break | ||
if check_if_to_publish_for_action(result, module_args): | ||
result['publish:'] = self._execute_module(module_name='check_point.mgmt.cp_mgmt_publish', module_args={}, | ||
task_vars=task_vars, tmp=tmp) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright: (c) 2019, Or Soffer <[email protected]> | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
from __future__ import (absolute_import, division, print_function) | ||
__metaclass__ = type | ||
|
||
|
||
class ModuleDocFragment(object): | ||
|
||
# Standard files documentation fragment | ||
DOCUMENTATION = r''' | ||
options: | ||
auto_publish_session: | ||
description: | ||
- Publish the current session if changes have been performed | ||
after task completes. | ||
type: bool | ||
wait_for_task_timeout: | ||
description: | ||
- How many minutes to wait until throwing a timeout error. | ||
type: int | ||
default: 30 | ||
version: | ||
description: | ||
- Version of checkpoint. If not given one, the latest version taken. | ||
type: str | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.