Skip to content

Commit 4641298

Browse files
committed
upload all the mgmt collection
1 parent b53c5e8 commit 4641298

File tree

186 files changed

+24162
-0
lines changed

Some content is hidden

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

186 files changed

+24162
-0
lines changed

galaxy.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
### REQUIRED
2+
3+
# The namespace of the collection. This can be a company/brand/organization or product namespace under which all
4+
# content lives. May only contain alphanumeric characters and underscores. Additionally namespaces cannot start with
5+
# underscores or numbers and cannot contain consecutive underscores
6+
namespace: check_point
7+
8+
# The name of the collection. Has the same character restrictions as 'namespace'
9+
name: mgmt
10+
11+
# The version of the collection. Must be compatible with semantic versioning
12+
version: 1.0.0
13+
14+
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
15+
readme: README.md
16+
17+
# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url)
18+
# @nicks:irc/im.site#channel'
19+
authors:
20+
- Or Soffer <orso@checkpoint.com>
21+
22+
23+
### OPTIONAL but strongly recommended
24+
25+
# A short summary description of the collection
26+
description: check_point collection for the management server
27+
28+
# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only
29+
# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file'
30+
license:
31+
- GPL-2.0-or-later
32+
33+
# The path to the license file for the collection. This path is relative to the root of the collection. This key is
34+
# mutually exclusive with 'license'
35+
license_file: ''
36+
37+
# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
38+
# requirements as 'namespace' and 'name'
39+
tags: []
40+
41+
# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
42+
# collection label 'namespace.name'. The value is a version range
43+
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
44+
# range specifiers can be set and are separated by ','
45+
dependencies: {}
46+
47+
# The URL of the originating SCM repository
48+
repository: http://example.com/repository
49+
50+
# The URL to any online docs
51+
documentation: http://docs.example.com
52+
53+
# The URL to the homepage of the collection/project
54+
homepage: http://example.com
55+
56+
# The URL to the collection issue tracker
57+
issues: http://example.com/issue/tracker

plugins/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Collections Plugins Directory
2+
3+
This directory can be used to ship various plugins inside an Ansible collection. Each plugin is placed in a folder that
4+
is named after the type of plugin it is in. It can also include the `module_utils` and `modules` directory that
5+
would contain module utils and modules respectively.
6+
7+
Here is an example directory of the majority of plugins currently supported by Ansible;
8+
9+
```
10+
└── plugins
11+
├── action
12+
├── become
13+
├── cache
14+
├── callback
15+
├── cliconf
16+
├── connection
17+
├── filter
18+
├── httpapi
19+
├── inventory
20+
├── lookup
21+
├── module_utils
22+
├── modules
23+
├── netconf
24+
├── shell
25+
├── strategy
26+
├── terminal
27+
├── test
28+
└── vars
29+
```
30+
31+
A full list of plugin types can be found at [Working With Plugins](https://docs.ansible.com/ansible/devel/plugins/plugins.html).
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright: (c) 2019, Or Soffer <orso@checkpoint.com>
4+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5+
6+
7+
class ModuleDocFragment(object):
8+
9+
# Standard files documentation fragment
10+
DOCUMENTATION = r'''
11+
options:
12+
wait_for_task:
13+
description:
14+
- Wait for the task to end. Such as publish task.
15+
type: bool
16+
default: True
17+
version:
18+
description:
19+
- Version of checkpoint. If not given one, the latest version taken.
20+
type: str
21+
'''
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright: (c) 2019, Or Soffer <orso@checkpoint.com>
4+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5+
6+
from __future__ import (absolute_import, division, print_function)
7+
__metaclass__ = type
8+
9+
10+
class ModuleDocFragment(object):
11+
12+
# Standard files documentation fragment
13+
DOCUMENTATION = r'''
14+
options:
15+
version:
16+
description:
17+
- Version of checkpoint. If not given one, the latest version taken.
18+
type: str
19+
'''
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright: (c) 2019, Or Soffer <orso@checkpoint.com>
4+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5+
6+
7+
class ModuleDocFragment(object):
8+
9+
# Standard files documentation fragment
10+
DOCUMENTATION = r'''
11+
options:
12+
state:
13+
description:
14+
- State of the access rule (present or absent). Defaults to present.
15+
type: str
16+
default: present
17+
choices:
18+
- 'present'
19+
- 'absent'
20+
auto_publish_session:
21+
description:
22+
- Publish the current session if changes have been performed
23+
after task completes.
24+
type: bool
25+
wait_for_task:
26+
description:
27+
- Wait for the task to end. Such as publish task.
28+
type: bool
29+
default: True
30+
version:
31+
description:
32+
- Version of checkpoint. If not given one, the latest version taken.
33+
type: str
34+
'''

plugins/httpapi/checkpoint.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# (c) 2018 Red Hat Inc.
2+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3+
4+
from __future__ import (absolute_import, division, print_function)
5+
6+
__metaclass__ = type
7+
8+
DOCUMENTATION = """
9+
---
10+
author: Ansible Networking Team
11+
httpapi : checkpoint
12+
short_description: HttpApi Plugin for Checkpoint devices
13+
description:
14+
- This HttpApi plugin provides methods to connect to Checkpoint
15+
devices over a HTTP(S)-based api.
16+
version_added: "2.8"
17+
options:
18+
domain:
19+
type: str
20+
description:
21+
- Specifies the domain of the Check Point device
22+
vars:
23+
- name: ansible_checkpoint_domain
24+
"""
25+
26+
import json
27+
28+
from ansible.module_utils.basic import to_text
29+
from ansible.errors import AnsibleConnectionFailure
30+
from ansible.module_utils.six.moves.urllib.error import HTTPError
31+
from ansible.plugins.httpapi import HttpApiBase
32+
from ansible.module_utils.connection import ConnectionError
33+
34+
BASE_HEADERS = {
35+
'Content-Type': 'application/json',
36+
}
37+
38+
39+
class HttpApi(HttpApiBase):
40+
def login(self, username, password):
41+
if username and password:
42+
cp_domain = self.get_option('domain')
43+
if cp_domain:
44+
payload = {'user': username, 'password': password, 'domain': cp_domain}
45+
else:
46+
payload = {'user': username, 'password': password}
47+
url = '/web_api/login'
48+
response, response_data = self.send_request(url, payload)
49+
else:
50+
raise AnsibleConnectionFailure('Username and password are required for login')
51+
52+
try:
53+
self.connection._auth = {'X-chkp-sid': response_data['sid']}
54+
self.connection._session_uid = response_data['uid']
55+
except KeyError:
56+
raise ConnectionError(
57+
'Server returned response without token info during connection authentication: %s' % response)
58+
59+
def logout(self):
60+
url = '/web_api/logout'
61+
62+
response, dummy = self.send_request(url, None)
63+
64+
def get_session_uid(self):
65+
return self.connection._session_uid
66+
67+
def send_request(self, path, body_params):
68+
data = json.dumps(body_params) if body_params else '{}'
69+
70+
try:
71+
self._display_request()
72+
response, response_data = self.connection.send(path, data, method='POST', headers=BASE_HEADERS)
73+
value = self._get_response_value(response_data)
74+
75+
return response.getcode(), self._response_to_json(value)
76+
except AnsibleConnectionFailure as e:
77+
return 404, e.message
78+
except HTTPError as e:
79+
error = json.loads(e.read())
80+
return e.code, error
81+
82+
def _display_request(self):
83+
self.connection.queue_message('vvvv', 'Web Services: %s %s' % ('POST', self.connection._url))
84+
85+
def _get_response_value(self, response_data):
86+
return to_text(response_data.getvalue())
87+
88+
def _response_to_json(self, response_text):
89+
try:
90+
return json.loads(response_text) if response_text else {}
91+
# JSONDecodeError only available on Python 3.5+
92+
except ValueError:
93+
raise ConnectionError('Invalid JSON response: %s' % response_text)

0 commit comments

Comments
 (0)