Skip to content

Commit 2320d82

Browse files
authored
To fix pep8 Ansible guidelines (#92)
* fix pep8 ansible guidelines n enable Ansible gh actions * remove ansible GH actions
1 parent a05cb3f commit 2320d82

File tree

296 files changed

+14587
-7442
lines changed

Some content is hidden

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

296 files changed

+14587
-7442
lines changed
Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,91 @@
1-
from __future__ import (absolute_import, division, print_function)
1+
from __future__ import absolute_import, division, print_function
22

33
__metaclass__ = type
44

55

66
from ansible.errors import AnsibleActionFail
77
from ansible.plugins.action import ActionBase
8-
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import \
9-
prepare_rule_params_for_execute_module, check_if_to_publish_for_action
8+
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import (
9+
prepare_rule_params_for_execute_module,
10+
check_if_to_publish_for_action,
11+
)
1012

1113

1214
class ActionModule(ActionBase):
13-
1415
def run(self, tmp=None, task_vars=None):
1516

1617
module = super(ActionModule, self).run(tmp, task_vars)
1718

18-
result = self._execute_module(module_name='check_point.mgmt.cp_mgmt_access_rules', module_args=self._task.args,
19-
task_vars=task_vars, tmp=tmp)
19+
result = self._execute_module(
20+
module_name="check_point.mgmt.cp_mgmt_access_rules",
21+
module_args=self._task.args,
22+
task_vars=task_vars,
23+
tmp=tmp,
24+
)
2025

21-
if 'msg' in result.keys():
22-
raise AnsibleActionFail(result['msg'])
26+
if "msg" in result.keys():
27+
raise AnsibleActionFail(result["msg"])
2328

2429
module_args = self._task.args
2530

26-
fields = {'position', 'layer', 'auto_publish_session'}
27-
rules_list = module_args['rules']
31+
fields = {"position", "layer", "auto_publish_session"}
32+
rules_list = module_args["rules"]
2833
for rule in rules_list:
2934
for field in fields:
3035
if field in rule.keys():
31-
raise AnsibleActionFail('Unsupported parameter ' + field + ' for rule')
36+
raise AnsibleActionFail(
37+
"Unsupported parameter " + field + " for rule"
38+
)
3239
# check_fields_for_rule_action_module(module_args)
33-
rules_list = self._task.args['rules']
40+
rules_list = self._task.args["rules"]
3441
position = 1
3542
below_rule_name = None
3643

3744
for rule in rules_list:
38-
rule, position, below_rule_name = prepare_rule_params_for_execute_module(rule=rule, module_args=module_args,
39-
position=position,
40-
below_rule_name=below_rule_name)
41-
42-
result['rule: ' + rule['name']] = self._execute_module(module_name='check_point.mgmt.cp_mgmt_access_rule',
43-
module_args=rule,
44-
task_vars=task_vars, tmp=tmp, wrap_async=False)
45-
if 'changed' in result['rule: ' + rule['name']].keys() and \
46-
result['rule: ' + rule['name']]['changed'] is True:
47-
result['changed'] = True
48-
if 'failed' in result['rule: ' + rule['name']].keys() and result['rule: ' + rule['name']]['failed'] is True:
49-
temp = result['rule: ' + rule['name']].copy()
45+
(
46+
rule,
47+
position,
48+
below_rule_name,
49+
) = prepare_rule_params_for_execute_module(
50+
rule=rule,
51+
module_args=module_args,
52+
position=position,
53+
below_rule_name=below_rule_name,
54+
)
55+
56+
result["rule: " + rule["name"]] = self._execute_module(
57+
module_name="check_point.mgmt.cp_mgmt_access_rule",
58+
module_args=rule,
59+
task_vars=task_vars,
60+
tmp=tmp,
61+
wrap_async=False,
62+
)
63+
if (
64+
"changed" in result["rule: " + rule["name"]].keys()
65+
and result["rule: " + rule["name"]]["changed"] is True
66+
):
67+
result["changed"] = True
68+
if (
69+
"failed" in result["rule: " + rule["name"]].keys()
70+
and result["rule: " + rule["name"]]["failed"] is True
71+
):
72+
temp = result["rule: " + rule["name"]].copy()
5073
result = {}
51-
result['rule: ' + rule['name']] = temp
52-
result['failed'] = True
53-
result['discard:'] = self._execute_module(module_name='check_point.mgmt.cp_mgmt_discard',
54-
module_args={}, task_vars=task_vars, tmp=tmp)
74+
result["rule: " + rule["name"]] = temp
75+
result["failed"] = True
76+
result["discard:"] = self._execute_module(
77+
module_name="check_point.mgmt.cp_mgmt_discard",
78+
module_args={},
79+
task_vars=task_vars,
80+
tmp=tmp,
81+
)
5582
break
5683
if check_if_to_publish_for_action(result, module_args):
57-
result['publish:'] = self._execute_module(module_name='check_point.mgmt.cp_mgmt_publish', module_args={},
58-
task_vars=task_vars, tmp=tmp)
84+
result["publish:"] = self._execute_module(
85+
module_name="check_point.mgmt.cp_mgmt_publish",
86+
module_args={},
87+
task_vars=task_vars,
88+
tmp=tmp,
89+
)
5990

6091
return result

plugins/doc_fragments/checkpoint_commands.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
# Copyright: (c) 2019, Or Soffer <orso@checkpoint.com>
44
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
55

6-
from __future__ import (absolute_import, division, print_function)
6+
from __future__ import absolute_import, division, print_function
7+
78
__metaclass__ = type
89

910

1011
class ModuleDocFragment(object):
1112

1213
# Standard files documentation fragment
13-
DOCUMENTATION = r'''
14+
DOCUMENTATION = r"""
1415
options:
1516
wait_for_task:
1617
description:
@@ -26,4 +27,4 @@ class ModuleDocFragment(object):
2627
description:
2728
- Version of checkpoint. If not given one, the latest version taken.
2829
type: str
29-
'''
30+
"""

plugins/doc_fragments/checkpoint_facts.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
# Copyright: (c) 2019, Or Soffer <orso@checkpoint.com>
44
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
55

6-
from __future__ import (absolute_import, division, print_function)
6+
from __future__ import absolute_import, division, print_function
7+
78
__metaclass__ = type
89

910

1011
class ModuleDocFragment(object):
1112

1213
# Standard files documentation fragment
13-
DOCUMENTATION = r'''
14+
DOCUMENTATION = r"""
1415
options:
1516
version:
1617
description:
1718
- Version of checkpoint. If not given one, the latest version taken.
1819
type: str
19-
'''
20+
"""

plugins/doc_fragments/checkpoint_objects.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
# Copyright: (c) 2019, Or Soffer <orso@checkpoint.com>
44
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
55

6-
from __future__ import (absolute_import, division, print_function)
6+
from __future__ import absolute_import, division, print_function
7+
78
__metaclass__ = type
89

910

1011
class ModuleDocFragment(object):
1112

1213
# Standard files documentation fragment
13-
DOCUMENTATION = r'''
14+
DOCUMENTATION = r"""
1415
options:
1516
state:
1617
description:
@@ -39,4 +40,4 @@ class ModuleDocFragment(object):
3940
description:
4041
- Version of checkpoint. If not given one, the latest version taken.
4142
type: str
42-
'''
43+
"""

plugins/doc_fragments/checkpoint_objects_action_module.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
# Copyright: (c) 2019, Or Soffer <orso@checkpoint.com>
44
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
55

6-
from __future__ import (absolute_import, division, print_function)
6+
from __future__ import absolute_import, division, print_function
7+
78
__metaclass__ = type
89

910

1011
class ModuleDocFragment(object):
1112

1213
# Standard files documentation fragment
13-
DOCUMENTATION = r'''
14+
DOCUMENTATION = r"""
1415
options:
1516
auto_publish_session:
1617
description:
@@ -26,4 +27,4 @@ class ModuleDocFragment(object):
2627
description:
2728
- Version of checkpoint. If not given one, the latest version taken.
2829
type: str
29-
'''
30+
"""

plugins/httpapi/checkpoint.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# (c) 2018 Red Hat Inc.
22
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
33

4-
from __future__ import (absolute_import, division, print_function)
4+
from __future__ import absolute_import, division, print_function
55

66
__metaclass__ = type
77

@@ -44,53 +44,59 @@
4444
from ansible.module_utils.connection import ConnectionError
4545

4646
BASE_HEADERS = {
47-
'Content-Type': 'application/json',
48-
'User-Agent': 'Ansible',
47+
"Content-Type": "application/json",
48+
"User-Agent": "Ansible",
4949
}
5050

5151

5252
class HttpApi(HttpApiBase):
5353
def login(self, username, password):
5454
payload = {}
55-
cp_domain = self.get_option('domain')
56-
cp_api_key = self.get_option('api_key')
55+
cp_domain = self.get_option("domain")
56+
cp_api_key = self.get_option("api_key")
5757
if cp_domain:
58-
payload['domain'] = cp_domain
58+
payload["domain"] = cp_domain
5959
if username and password and not cp_api_key:
60-
payload['user'] = username
61-
payload['password'] = password
60+
payload["user"] = username
61+
payload["password"] = password
6262
elif cp_api_key and not username and not password:
63-
payload['api-key'] = cp_api_key
63+
payload["api-key"] = cp_api_key
6464
else:
65-
raise AnsibleConnectionFailure('[Username and password] or api_key are required for login')
66-
url = '/web_api/login'
65+
raise AnsibleConnectionFailure(
66+
"[Username and password] or api_key are required for login"
67+
)
68+
url = "/web_api/login"
6769
response, response_data = self.send_request(url, payload)
6870

6971
try:
70-
self.connection._auth = {'X-chkp-sid': response_data['sid']}
72+
self.connection._auth = {"X-chkp-sid": response_data["sid"]}
7173
except KeyError:
7274
raise ConnectionError(
73-
'Server returned response without token info during connection authentication: %s' % response)
75+
"Server returned response without token info during connection authentication: %s"
76+
% response
77+
)
7478
# Case of read-only
75-
if 'uid' in response_data.keys():
76-
self.connection._session_uid = response_data['uid']
79+
if "uid" in response_data.keys():
80+
self.connection._session_uid = response_data["uid"]
7781

7882
def logout(self):
79-
url = '/web_api/logout'
83+
url = "/web_api/logout"
8084

8185
response, dummy = self.send_request(url, None)
8286

8387
def get_session_uid(self):
8488
return self.connection._session_uid
8589

8690
def send_request(self, path, body_params):
87-
data = json.dumps(body_params) if body_params else '{}'
88-
cp_cloud_mgmt_id = self.get_option('cloud_mgmt_id')
91+
data = json.dumps(body_params) if body_params else "{}"
92+
cp_cloud_mgmt_id = self.get_option("cloud_mgmt_id")
8993
if cp_cloud_mgmt_id:
90-
path = '/' + cp_cloud_mgmt_id + path
94+
path = "/" + cp_cloud_mgmt_id + path
9195
try:
9296
self._display_request()
93-
response, response_data = self.connection.send(path, data, method='POST', headers=BASE_HEADERS)
97+
response, response_data = self.connection.send(
98+
path, data, method="POST", headers=BASE_HEADERS
99+
)
94100
value = self._get_response_value(response_data)
95101

96102
return response.getcode(), self._response_to_json(value)
@@ -101,7 +107,9 @@ def send_request(self, path, body_params):
101107
return e.code, error
102108

103109
def _display_request(self):
104-
self.connection.queue_message('vvvv', 'Web Services: %s %s' % ('POST', self.connection._url))
110+
self.connection.queue_message(
111+
"vvvv", "Web Services: %s %s" % ("POST", self.connection._url)
112+
)
105113

106114
def _get_response_value(self, response_data):
107115
return to_text(response_data.getvalue())
@@ -111,4 +119,4 @@ def _response_to_json(self, response_text):
111119
return json.loads(response_text) if response_text else {}
112120
# JSONDecodeError only available on Python 3.5+
113121
except ValueError:
114-
raise ConnectionError('Invalid JSON response: %s' % response_text)
122+
raise ConnectionError("Invalid JSON response: %s" % response_text)

0 commit comments

Comments
 (0)