| 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 |
ANSIBLE_METADATA = { |
| 25 |
"metadata_version": "1.1", |
| 26 |
"status": ["preview"], |
| 27 |
"supported_by": "community", |
| 28 |
} |
| 29 |
|
| 30 |
DOCUMENTATION = """ |
| 31 |
--- |
| 32 |
module: cp_mgmt_network_feed |
| 33 |
short_description: Manages network-feed objects on Checkpoint over Web Services API |
| 34 |
description: |
| 35 |
- Manages network-feed objects on Checkpoint devices including creating, updating and removing objects. |
| 36 |
- All operations are performed over Web Services API. |
| 37 |
- Available from R81.20 management version. |
| 38 |
version_added: "3.0.0" |
| 39 |
author: "Eden Brillant (@chkp-edenbr)" |
| 40 |
options: |
| 41 |
name: |
| 42 |
description: |
| 43 |
- Object name. |
| 44 |
type: str |
| 45 |
required: True |
| 46 |
feed_url: |
| 47 |
description: |
| 48 |
- URL of the feed. URL should be written as http or https. |
| 49 |
type: str |
| 50 |
certificate_id: |
| 51 |
description: |
| 52 |
- Certificate SHA-1 fingerprint to access the feed. |
| 53 |
type: str |
| 54 |
feed_format: |
| 55 |
description: |
| 56 |
- Feed file format. |
| 57 |
type: str |
| 58 |
choices: ['Flat List', 'JSON'] |
| 59 |
feed_type: |
| 60 |
description: |
| 61 |
- Feed type to be enforced. |
| 62 |
type: str |
| 63 |
choices: ['Domain', 'IP Address', 'IP Address/Domain'] |
| 64 |
password: |
| 65 |
description: |
| 66 |
- password for authenticating with the URL. |
| 67 |
type: str |
| 68 |
tags: |
| 69 |
description: |
| 70 |
- Collection of tag identifiers. |
| 71 |
type: list |
| 72 |
elements: str |
| 73 |
username: |
| 74 |
description: |
| 75 |
- username for authenticating with the URL. |
| 76 |
type: str |
| 77 |
custom_header: |
| 78 |
description: |
| 79 |
- Headers to allow different authentication methods with the URL. |
| 80 |
type: list |
| 81 |
elements: dict |
| 82 |
suboptions: |
| 83 |
header_name: |
| 84 |
description: |
| 85 |
- The name of the HTTP header we wish to add. |
| 86 |
type: str |
| 87 |
header_value: |
| 88 |
description: |
| 89 |
- The name of the HTTP value we wish to add. |
| 90 |
type: str |
| 91 |
update_interval: |
| 92 |
description: |
| 93 |
- Interval in minutes for updating the feed on the Security Gateway. |
| 94 |
type: int |
| 95 |
data_column: |
| 96 |
description: |
| 97 |
- Number of the column that contains the feed's data. |
| 98 |
type: int |
| 99 |
fields_delimiter: |
| 100 |
description: |
| 101 |
- The delimiter that separates between the columns in the feed. |
| 102 |
type: str |
| 103 |
ignore_lines_that_start_with: |
| 104 |
description: |
| 105 |
- A prefix that will determine which lines to ignore. |
| 106 |
type: str |
| 107 |
json_query: |
| 108 |
description: |
| 109 |
- JQ query to be parsed. |
| 110 |
type: str |
| 111 |
use_gateway_proxy: |
| 112 |
description: |
| 113 |
- Use the gateway's proxy for retrieving the feed. |
| 114 |
type: bool |
| 115 |
color: |
| 116 |
description: |
| 117 |
- Color of the object. Should be one of existing colors. |
| 118 |
type: str |
| 119 |
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green', |
| 120 |
'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', |
| 121 |
'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow'] |
| 122 |
comments: |
| 123 |
description: |
| 124 |
- Comments string. |
| 125 |
type: str |
| 126 |
details_level: |
| 127 |
description: |
| 128 |
- The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed |
| 129 |
representation of the object. |
| 130 |
type: str |
| 131 |
choices: ['uid', 'standard', 'full'] |
| 132 |
domains_to_process: |
| 133 |
description: |
| 134 |
- Indicates which domains to process the commands on. It cannot be used with the details-level full, must be run from the System Domain only and |
| 135 |
with ignore-warnings true. Valid values are, CURRENT_DOMAIN, ALL_DOMAINS_ON_THIS_SERVER. |
| 136 |
type: list |
| 137 |
elements: str |
| 138 |
ignore_warnings: |
| 139 |
description: |
| 140 |
- Apply changes ignoring warnings. |
| 141 |
type: bool |
| 142 |
ignore_errors: |
| 143 |
description: |
| 144 |
- Apply changes ignoring errors. You won't be able to publish such a changes. If ignore-warnings flag was omitted - warnings will also be ignored. |
| 145 |
type: bool |
| 146 |
extends_documentation_fragment: check_point.mgmt.checkpoint_objects |
| 147 |
""" |
| 148 |
|
| 149 |
EXAMPLES = """ |
| 150 |
- name: add-network-feed |
| 151 |
cp_mgmt_network_feed: |
| 152 |
custom_header: |
| 153 |
- header_name: header1 |
| 154 |
header_value: value1 |
| 155 |
- header_name: header2 |
| 156 |
header_value: value2 |
| 157 |
data_column: 1 |
| 158 |
feed_format: Flat List |
| 159 |
feed_type: IP Address |
| 160 |
feed_url: https://www.feedsresource.com/resource |
| 161 |
fields_delimiter: "\t" |
| 162 |
ignore_lines_that_start_with: '!' |
| 163 |
name: network_feed |
| 164 |
password: feed_password |
| 165 |
state: present |
| 166 |
update_interval: 60 |
| 167 |
use_gateway_proxy: false |
| 168 |
username: feed_username |
| 169 |
|
| 170 |
- name: set-network-feed |
| 171 |
cp_mgmt_network_feed: |
| 172 |
custom_header: |
| 173 |
- header_name: new_header |
| 174 |
header_value: new_value |
| 175 |
data_column: 1 |
| 176 |
feed_format: Flat List |
| 177 |
feed_type: IP Address |
| 178 |
feed_url: https://www.feedsresource.com/new_resource |
| 179 |
fields_delimiter: ',' |
| 180 |
ignore_lines_that_start_with: '!' |
| 181 |
name: network_feed |
| 182 |
password: new_password |
| 183 |
state: present |
| 184 |
update_interval: 60 |
| 185 |
use_gateway_proxy: false |
| 186 |
username: new_username |
| 187 |
|
| 188 |
- name: delete-network-feed |
| 189 |
cp_mgmt_network_feed: |
| 190 |
name: network_feed |
| 191 |
state: absent |
| 192 |
""" |
| 193 |
|
| 194 |
RETURN = """ |
| 195 |
cp_mgmt_network_feed: |
| 196 |
description: The checkpoint object created or updated. |
| 197 |
returned: always, except when deleting the object. |
| 198 |
type: dict |
| 199 |
""" |
| 200 |
|
| 201 |
from ansible.module_utils.basic import AnsibleModule |
| 202 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import ( |
| 203 |
checkpoint_argument_spec_for_objects, |
| 204 |
api_call, |
| 205 |
) |
| 206 |
|
| 207 |
|
| 208 |
def main(): |
| 209 |
argument_spec = dict( |
| 210 |
name=dict(type="str", required=True), |
| 211 |
feed_url=dict(type="str"), |
| 212 |
certificate_id=dict(type="str"), |
| 213 |
feed_format=dict(type="str", choices=["Flat List", "JSON"]), |
| 214 |
feed_type=dict( |
| 215 |
type="str", choices=["Domain", "IP Address", "IP Address/Domain"] |
| 216 |
), |
| 217 |
password=dict(type="str", no_log=True), |
| 218 |
tags=dict(type="list", elements="str"), |
| 219 |
username=dict(type="str"), |
| 220 |
custom_header=dict( |
| 221 |
type="list", |
| 222 |
elements="dict", |
| 223 |
options=dict( |
| 224 |
header_name=dict(type="str"), header_value=dict(type="str") |
| 225 |
), |
| 226 |
), |
| 227 |
update_interval=dict(type="int"), |
| 228 |
data_column=dict(type="int"), |
| 229 |
fields_delimiter=dict(type="str"), |
| 230 |
ignore_lines_that_start_with=dict(type="str"), |
| 231 |
json_query=dict(type="str"), |
| 232 |
use_gateway_proxy=dict(type="bool"), |
| 233 |
color=dict( |
| 234 |
type="str", |
| 235 |
choices=[ |
| 236 |
"aquamarine", |
| 237 |
"black", |
| 238 |
"blue", |
| 239 |
"crete blue", |
| 240 |
"burlywood", |
| 241 |
"cyan", |
| 242 |
"dark green", |
| 243 |
"khaki", |
| 244 |
"orchid", |
| 245 |
"dark orange", |
| 246 |
"dark sea green", |
| 247 |
"pink", |
| 248 |
"turquoise", |
| 249 |
"dark blue", |
| 250 |
"firebrick", |
| 251 |
"brown", |
| 252 |
"forest green", |
| 253 |
"gold", |
| 254 |
"dark gold", |
| 255 |
"gray", |
| 256 |
"dark gray", |
| 257 |
"light green", |
| 258 |
"lemon chiffon", |
| 259 |
"coral", |
| 260 |
"sea green", |
| 261 |
"sky blue", |
| 262 |
"magenta", |
| 263 |
"purple", |
| 264 |
"slate blue", |
| 265 |
"violet red", |
| 266 |
"navy blue", |
| 267 |
"olive", |
| 268 |
"orange", |
| 269 |
"red", |
| 270 |
"sienna", |
| 271 |
"yellow", |
| 272 |
], |
| 273 |
), |
| 274 |
comments=dict(type="str"), |
| 275 |
details_level=dict(type="str", choices=["uid", "standard", "full"]), |
| 276 |
domains_to_process=dict(type="list", elements="str"), |
| 277 |
ignore_warnings=dict(type="bool"), |
| 278 |
ignore_errors=dict(type="bool"), |
| 279 |
) |
| 280 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 281 |
|
| 282 |
module = AnsibleModule( |
| 283 |
argument_spec=argument_spec, supports_check_mode=True |
| 284 |
) |
| 285 |
api_call_object = "network-feed" |
| 286 |
|
| 287 |
result = api_call(module, api_call_object) |
| 288 |
module.exit_json(**result) |
| 289 |
|
| 290 |
|
| 291 |
if __name__ == "__main__": |
| 292 |
main() |