mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 22:30:22 -07:00
FortiManager Plugin Module Conversion: fmgr_secprof_web (#52788)
* Auto Commit for: fmgr_secprof_web * Auto Commit for: fmgr_secprof_web * Auto Commit for: fmgr_secprof_web
This commit is contained in:
parent
7ee7c3cf2c
commit
d1c0df9e92
3 changed files with 198 additions and 503 deletions
|
@ -27,6 +27,8 @@ DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: fmgr_secprof_web
|
module: fmgr_secprof_web
|
||||||
version_added: "2.8"
|
version_added: "2.8"
|
||||||
|
notes:
|
||||||
|
- Full Documentation at U(https://ftnt-ansible-docs.readthedocs.io/en/latest/).
|
||||||
author:
|
author:
|
||||||
- Luke Weighall (@lweighall)
|
- Luke Weighall (@lweighall)
|
||||||
- Andrew Welsh (@Ghilli3)
|
- Andrew Welsh (@Ghilli3)
|
||||||
|
@ -42,21 +44,6 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: root
|
default: root
|
||||||
|
|
||||||
host:
|
|
||||||
description:
|
|
||||||
- The FortiManager's Address.
|
|
||||||
required: true
|
|
||||||
|
|
||||||
username:
|
|
||||||
description:
|
|
||||||
- The username associated with the account.
|
|
||||||
required: true
|
|
||||||
|
|
||||||
password:
|
|
||||||
description:
|
|
||||||
- The password associated with the username account.
|
|
||||||
required: true
|
|
||||||
|
|
||||||
mode:
|
mode:
|
||||||
description:
|
description:
|
||||||
- Sets one of three modes for managing the object.
|
- Sets one of three modes for managing the object.
|
||||||
|
@ -753,17 +740,11 @@ options:
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- name: DELETE Profile
|
- name: DELETE Profile
|
||||||
fmgr_secprof_web:
|
fmgr_secprof_web:
|
||||||
host: "{{inventory_hostname}}"
|
|
||||||
username: "{{ username }}"
|
|
||||||
password: "{{ password }}"
|
|
||||||
name: "Ansible_Web_Filter_Profile"
|
name: "Ansible_Web_Filter_Profile"
|
||||||
mode: "delete"
|
mode: "delete"
|
||||||
|
|
||||||
- name: CREATE Profile
|
- name: CREATE Profile
|
||||||
fmgr_secprof_web:
|
fmgr_secprof_web:
|
||||||
host: "{{inventory_hostname}}"
|
|
||||||
username: "{{ username }}"
|
|
||||||
password: "{{ password }}"
|
|
||||||
name: "Ansible_Web_Filter_Profile"
|
name: "Ansible_Web_Filter_Profile"
|
||||||
comment: "Created by Ansible Module TEST"
|
comment: "Created by Ansible Module TEST"
|
||||||
mode: "set"
|
mode: "set"
|
||||||
|
@ -802,27 +783,30 @@ api_result:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
||||||
from ansible.module_utils.network.fortimanager.fortimanager import AnsibleFortiManager
|
from ansible.module_utils.connection import Connection
|
||||||
|
from ansible.module_utils.network.fortimanager.fortimanager import FortiManagerHandler
|
||||||
|
from ansible.module_utils.network.fortimanager.common import FMGBaseException
|
||||||
|
from ansible.module_utils.network.fortimanager.common import FMGRCommon
|
||||||
|
from ansible.module_utils.network.fortimanager.common import FMGRMethods
|
||||||
|
from ansible.module_utils.network.fortimanager.common import DEFAULT_RESULT_OBJ
|
||||||
|
from ansible.module_utils.network.fortimanager.common import FAIL_SOCKET_MSG
|
||||||
|
from ansible.module_utils.network.fortimanager.common import prepare_dict
|
||||||
|
from ansible.module_utils.network.fortimanager.common import scrub_dict
|
||||||
|
|
||||||
|
|
||||||
###############
|
def fmgr_webfilter_profile_modify(fmgr, paramgram):
|
||||||
# START METHODS
|
|
||||||
###############
|
|
||||||
|
|
||||||
|
|
||||||
def fmgr_webfilter_profile_addsetdelete(fmg, paramgram):
|
|
||||||
|
|
||||||
mode = paramgram["mode"]
|
mode = paramgram["mode"]
|
||||||
adom = paramgram["adom"]
|
adom = paramgram["adom"]
|
||||||
|
|
||||||
response = (-100000, {"msg": "Illegal or malformed paramgram discovered. System Exception"})
|
response = DEFAULT_RESULT_OBJ
|
||||||
url = ""
|
url = ""
|
||||||
datagram = {}
|
datagram = {}
|
||||||
|
|
||||||
# EVAL THE MODE PARAMETER FOR SET OR ADD
|
# EVAL THE MODE PARAMETER FOR SET OR ADD
|
||||||
if mode in ['set', 'add', 'update']:
|
if mode in ['set', 'add', 'update']:
|
||||||
url = '/pm/config/adom/{adom}/obj/webfilter/profile'.format(adom=adom)
|
url = '/pm/config/adom/{adom}/obj/webfilter/profile'.format(adom=adom)
|
||||||
datagram = fmgr_del_none(fmgr_prepare_dict(paramgram))
|
datagram = scrub_dict(prepare_dict(paramgram))
|
||||||
|
|
||||||
# EVAL THE MODE PARAMETER FOR DELETE
|
# EVAL THE MODE PARAMETER FOR DELETE
|
||||||
elif mode == "delete":
|
elif mode == "delete":
|
||||||
|
@ -830,124 +814,11 @@ def fmgr_webfilter_profile_addsetdelete(fmg, paramgram):
|
||||||
url = '/pm/config/adom/{adom}/obj/webfilter/profile/{name}'.format(adom=adom, name=paramgram["name"])
|
url = '/pm/config/adom/{adom}/obj/webfilter/profile/{name}'.format(adom=adom, name=paramgram["name"])
|
||||||
datagram = {}
|
datagram = {}
|
||||||
|
|
||||||
# IF MODE = SET -- USE THE 'SET' API CALL MODE
|
response = fmgr.process_request(url, datagram, paramgram["mode"])
|
||||||
if mode == "set":
|
|
||||||
response = fmg.set(url, datagram)
|
|
||||||
# IF MODE = UPDATE -- USER THE 'UPDATE' API CALL MODE
|
|
||||||
elif mode == "update":
|
|
||||||
response = fmg.update(url, datagram)
|
|
||||||
# IF MODE = ADD -- USE THE 'ADD' API CALL MODE
|
|
||||||
elif mode == "add":
|
|
||||||
response = fmg.add(url, datagram)
|
|
||||||
# IF MODE = DELETE -- USE THE DELETE URL AND API CALL MODE
|
|
||||||
elif mode == "delete":
|
|
||||||
response = fmg.delete(url, datagram)
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
# ADDITIONAL COMMON FUNCTIONS
|
|
||||||
def fmgr_logout(fmg, module, msg="NULL", results=(), good_codes=(0,), logout_on_fail=True, logout_on_success=False):
|
|
||||||
"""
|
|
||||||
THIS METHOD CONTROLS THE LOGOUT AND ERROR REPORTING AFTER AN METHOD OR FUNCTION RUNS
|
|
||||||
"""
|
|
||||||
# VALIDATION ERROR (NO RESULTS, JUST AN EXIT)
|
|
||||||
if msg != "NULL" and len(results) == 0:
|
|
||||||
try:
|
|
||||||
fmg.logout()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
module.fail_json(msg=msg)
|
|
||||||
|
|
||||||
# SUBMISSION ERROR
|
|
||||||
if len(results) > 0:
|
|
||||||
if msg == "NULL":
|
|
||||||
try:
|
|
||||||
msg = results[1]['status']['message']
|
|
||||||
except Exception:
|
|
||||||
msg = "No status message returned from pyFMG. Possible that this was a GET with a tuple result."
|
|
||||||
|
|
||||||
if results[0] not in good_codes:
|
|
||||||
if logout_on_fail:
|
|
||||||
fmg.logout()
|
|
||||||
module.fail_json(msg=msg, **results[1])
|
|
||||||
else:
|
|
||||||
if logout_on_success:
|
|
||||||
fmg.logout()
|
|
||||||
module.exit_json(msg="API Called worked, but logout handler has been asked to logout on success",
|
|
||||||
**results[1])
|
|
||||||
return msg
|
|
||||||
|
|
||||||
|
|
||||||
# FUNCTION/METHOD FOR CONVERTING CIDR TO A NETMASK
|
|
||||||
# DID NOT USE IP ADDRESS MODULE TO KEEP INCLUDES TO A MINIMUM
|
|
||||||
def fmgr_cidr_to_netmask(cidr):
|
|
||||||
cidr = int(cidr)
|
|
||||||
mask = (0xffffffff >> (32 - cidr)) << (32 - cidr)
|
|
||||||
return(str((0xff000000 & mask) >> 24) + '.' +
|
|
||||||
str((0x00ff0000 & mask) >> 16) + '.' +
|
|
||||||
str((0x0000ff00 & mask) >> 8) + '.' +
|
|
||||||
str((0x000000ff & mask)))
|
|
||||||
|
|
||||||
|
|
||||||
# utility function: removing keys wih value of None, nothing in playbook for that key
|
|
||||||
def fmgr_del_none(obj):
|
|
||||||
if isinstance(obj, dict):
|
|
||||||
return type(obj)((fmgr_del_none(k), fmgr_del_none(v))
|
|
||||||
for k, v in obj.items() if k is not None and (v is not None and not fmgr_is_empty_dict(v)))
|
|
||||||
else:
|
|
||||||
return obj
|
|
||||||
|
|
||||||
|
|
||||||
# utility function: remove keys that are need for the logic but the FMG API won't accept them
|
|
||||||
def fmgr_prepare_dict(obj):
|
|
||||||
list_of_elems = ["mode", "adom", "host", "username", "password"]
|
|
||||||
if isinstance(obj, dict):
|
|
||||||
obj = dict((key, fmgr_prepare_dict(value)) for (key, value) in obj.items() if key not in list_of_elems)
|
|
||||||
return obj
|
|
||||||
|
|
||||||
|
|
||||||
def fmgr_is_empty_dict(obj):
|
|
||||||
return_val = False
|
|
||||||
if isinstance(obj, dict):
|
|
||||||
if len(obj) > 0:
|
|
||||||
for k, v in obj.items():
|
|
||||||
if isinstance(v, dict):
|
|
||||||
if len(v) == 0:
|
|
||||||
return_val = True
|
|
||||||
elif len(v) > 0:
|
|
||||||
for k1, v1 in v.items():
|
|
||||||
if v1 is None:
|
|
||||||
return_val = True
|
|
||||||
elif v1 is not None:
|
|
||||||
return_val = False
|
|
||||||
return return_val
|
|
||||||
elif v is None:
|
|
||||||
return_val = True
|
|
||||||
elif v is not None:
|
|
||||||
return_val = False
|
|
||||||
return return_val
|
|
||||||
elif len(obj) == 0:
|
|
||||||
return_val = True
|
|
||||||
|
|
||||||
return return_val
|
|
||||||
|
|
||||||
|
|
||||||
def fmgr_split_comma_strings_into_lists(obj):
|
|
||||||
if isinstance(obj, dict):
|
|
||||||
if len(obj) > 0:
|
|
||||||
for k, v in obj.items():
|
|
||||||
if isinstance(v, str):
|
|
||||||
new_list = list()
|
|
||||||
if "," in v:
|
|
||||||
new_items = v.split(",")
|
|
||||||
for item in new_items:
|
|
||||||
new_list.append(item.strip())
|
|
||||||
obj[k] = new_list
|
|
||||||
|
|
||||||
return obj
|
|
||||||
|
|
||||||
|
|
||||||
#############
|
#############
|
||||||
# END METHODS
|
# END METHODS
|
||||||
#############
|
#############
|
||||||
|
@ -956,9 +827,6 @@ def fmgr_split_comma_strings_into_lists(obj):
|
||||||
def main():
|
def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
adom=dict(type="str", default="root"),
|
adom=dict(type="str", default="root"),
|
||||||
host=dict(required=True, type="str"),
|
|
||||||
password=dict(fallback=(env_fallback, ["ANSIBLE_NET_PASSWORD"]), no_log=True, required=True),
|
|
||||||
username=dict(fallback=(env_fallback, ["ANSIBLE_NET_USERNAME"]), no_log=True, required=True),
|
|
||||||
mode=dict(choices=["add", "set", "delete", "update"], type="str", default="add"),
|
mode=dict(choices=["add", "set", "delete", "update"], type="str", default="add"),
|
||||||
|
|
||||||
youtube_channel_status=dict(required=False, type="str", choices=["disable", "blacklist", "whitelist"]),
|
youtube_channel_status=dict(required=False, type="str", choices=["disable", "blacklist", "whitelist"]),
|
||||||
|
@ -1090,8 +958,7 @@ def main():
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec, supports_check_mode=False)
|
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False, )
|
||||||
|
|
||||||
# MODULE PARAMGRAM
|
# MODULE PARAMGRAM
|
||||||
paramgram = {
|
paramgram = {
|
||||||
"mode": module.params["mode"],
|
"mode": module.params["mode"],
|
||||||
|
@ -1188,45 +1055,31 @@ def main():
|
||||||
"comment": module.params["youtube_channel_filter_comment"],
|
"comment": module.params["youtube_channel_filter_comment"],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
module.paramgram = paramgram
|
||||||
|
fmgr = None
|
||||||
|
if module._socket_path:
|
||||||
|
connection = Connection(module._socket_path)
|
||||||
|
fmgr = FortiManagerHandler(connection, module)
|
||||||
|
fmgr.tools = FMGRCommon()
|
||||||
|
else:
|
||||||
|
module.fail_json(**FAIL_SOCKET_MSG)
|
||||||
|
|
||||||
list_overrides = ['ftgd-wf', 'override', 'url-extraction', 'web', 'youtube-channel-filter']
|
list_overrides = ['ftgd-wf', 'override', 'url-extraction', 'web', 'youtube-channel-filter']
|
||||||
for list_variable in list_overrides:
|
paramgram = fmgr.tools.paramgram_child_list_override(list_overrides=list_overrides,
|
||||||
override_data = list()
|
paramgram=paramgram, module=module)
|
||||||
try:
|
|
||||||
override_data = module.params[list_variable]
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
if override_data:
|
|
||||||
del paramgram[list_variable]
|
|
||||||
paramgram[list_variable] = override_data
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# CHECK IF THE HOST/USERNAME/PW EXISTS, AND IF IT DOES, LOGIN.
|
results = DEFAULT_RESULT_OBJ
|
||||||
host = module.params["host"]
|
|
||||||
password = module.params["password"]
|
|
||||||
username = module.params["username"]
|
|
||||||
if host is None or username is None or password is None:
|
|
||||||
module.fail_json(msg="Host and username and password are required")
|
|
||||||
|
|
||||||
# CHECK IF LOGIN FAILED
|
try:
|
||||||
fmg = AnsibleFortiManager(module, module.params["host"], module.params["username"], module.params["password"])
|
|
||||||
|
|
||||||
response = fmg.login()
|
results = fmgr_webfilter_profile_modify(fmgr, paramgram)
|
||||||
if response[1]['status']['code'] != 0:
|
fmgr.govern_response(module=module, results=results,
|
||||||
module.fail_json(msg="Connection to FortiManager Failed")
|
ansible_facts=fmgr.construct_ansible_facts(results, module.params, paramgram))
|
||||||
|
|
||||||
results = fmgr_webfilter_profile_addsetdelete(fmg, paramgram)
|
except Exception as err:
|
||||||
if results[0] != 0:
|
raise FMGBaseException(err)
|
||||||
fmgr_logout(fmg, module, results=results, good_codes=[0])
|
|
||||||
|
|
||||||
fmg.logout()
|
return module.exit_json(**results[1])
|
||||||
|
|
||||||
if results is not None:
|
|
||||||
return module.exit_json(**results[1])
|
|
||||||
else:
|
|
||||||
return module.exit_json(msg="No results were returned from the API call.")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -1,214 +1,146 @@
|
||||||
{
|
{
|
||||||
"fmgr_webfilter_profile_addsetdelete": [
|
"fmgr_webfilter_profile_modify": [
|
||||||
{
|
{
|
||||||
"paramgram_used": {
|
"raw_response": {
|
||||||
"comment": null,
|
"status": {
|
||||||
"web-extended-all-action-log": null,
|
"message": "OK",
|
||||||
"url-extraction": {
|
"code": 0
|
||||||
"status": null,
|
},
|
||||||
"redirect-url": null,
|
"url": "/pm/config/adom/root/obj/webfilter/profile"
|
||||||
"server-fqdn": null,
|
},
|
||||||
"redirect-header": null,
|
"datagram_sent": {
|
||||||
"redirect-no-content": null
|
"comment": "Created by Ansible Module TEST",
|
||||||
},
|
"web-extended-all-action-log": "enable",
|
||||||
"ftgd-wf": {
|
"web-filter-cookie-removal-log": "enable",
|
||||||
"filters": {
|
"extended-log": "enable",
|
||||||
"category": null,
|
"log-all-url": "enable",
|
||||||
"log": null,
|
"wisp": "enable",
|
||||||
"override-replacemsg": null,
|
"web-filter-vbs-log": "enable",
|
||||||
"warning-duration-type": null,
|
"ovrd-perm": [
|
||||||
"warn-duration": null,
|
"bannedword-override"
|
||||||
"auth-usr-grp": null,
|
],
|
||||||
"action": null,
|
"web-filter-command-block-log": "enable",
|
||||||
"warning-prompt": null
|
"web-invalid-domain-log": "enable",
|
||||||
},
|
"web-filter-referer-log": "enable",
|
||||||
"ovrd": null,
|
"inspection-mode": "proxy",
|
||||||
"rate-image-urls": null,
|
"post-action": "block",
|
||||||
"quota": {
|
"web-content-log": "enable",
|
||||||
"category": null,
|
"web-filter-applet-log": "enable",
|
||||||
"value": null,
|
"web-ftgd-err-log": "enable",
|
||||||
"override-replacemsg": null,
|
"name": "Ansible_Web_Proxy_Profile",
|
||||||
"duration": null,
|
"web-filter-jscript-log": "enable",
|
||||||
"type": null,
|
"web-filter-activex-log": "enable",
|
||||||
"unit": null
|
"web-filter-js-log": "enable",
|
||||||
},
|
"web-ftgd-quota-usage": "enable",
|
||||||
"options": null,
|
"web-filter-unknown-log": "enable",
|
||||||
"rate-javascript-urls": null,
|
"web-filter-cookie-log": "enable",
|
||||||
"max-quota-timeout": null,
|
"youtube-channel-status": "blacklist",
|
||||||
"rate-css-urls": null,
|
"web-url-log": "enable",
|
||||||
"exempt-quota": null,
|
"options": [
|
||||||
"rate-crl-urls": null
|
"js"
|
||||||
},
|
],
|
||||||
"log-all-url": null,
|
"wisp-algorithm": "auto-learning"
|
||||||
"extended-log": null,
|
},
|
||||||
"web-filter-cookie-removal-log": null,
|
"paramgram_used": {
|
||||||
"https-replacemsg": null,
|
"comment": "Created by Ansible Module TEST",
|
||||||
"web": {
|
"web-filter-command-block-log": "enable",
|
||||||
"log-search": null,
|
"web-invalid-domain-log": "enable",
|
||||||
"bword-threshold": null,
|
"web-extended-all-action-log": "enable",
|
||||||
"bword-table": null,
|
"adom": "root",
|
||||||
"whitelist": null,
|
"ftgd-wf": {
|
||||||
"youtube-restrict": null,
|
"rate-javascript-urls": null,
|
||||||
"safe-search": null,
|
"quota": {
|
||||||
"blacklist": null,
|
"category": null,
|
||||||
"keyword-match": null,
|
"value": null,
|
||||||
"urlfilter-table": null,
|
"override-replacemsg": null,
|
||||||
"content-header-list": null
|
"duration": null,
|
||||||
},
|
"type": null,
|
||||||
"wisp": null,
|
"unit": null
|
||||||
"web-filter-vbs-log": null,
|
},
|
||||||
"youtube-channel-filter": {
|
"rate-image-urls": null,
|
||||||
"comment": null,
|
"filters": {
|
||||||
"channel-id": null
|
"category": null,
|
||||||
},
|
"auth-usr-grp": null,
|
||||||
"override": {
|
"log": null,
|
||||||
"profile": null,
|
"warning-prompt": null,
|
||||||
"ovrd-scope": null,
|
"override-replacemsg": null,
|
||||||
"ovrd-dur-mode": null,
|
"action": null,
|
||||||
"profile-attribute": null,
|
"warn-duration": null,
|
||||||
"ovrd-dur": null,
|
"warning-duration-type": null
|
||||||
"profile-type": null,
|
},
|
||||||
"ovrd-user-group": null,
|
"rate-css-urls": null,
|
||||||
"ovrd-cookie": null
|
"ovrd": null,
|
||||||
},
|
"exempt-quota": null,
|
||||||
"ovrd-perm": null,
|
"max-quota-timeout": null,
|
||||||
"mode": "delete",
|
"rate-crl-urls": null,
|
||||||
"web-content-log": null,
|
"options": null
|
||||||
"web-invalid-domain-log": null,
|
},
|
||||||
"adom": "root",
|
"web-content-log": "enable",
|
||||||
"web-filter-referer-log": null,
|
"web-filter-referer-log": "enable",
|
||||||
"inspection-mode": null,
|
"log-all-url": "enable",
|
||||||
"post-action": null,
|
"extended-log": "enable",
|
||||||
"name": "Ansible_Web_Filter_Profile",
|
"inspection-mode": "proxy",
|
||||||
"web-filter-command-block-log": null,
|
"web-filter-cookie-removal-log": "enable",
|
||||||
"web-filter-applet-log": null,
|
"post-action": "block",
|
||||||
"web-ftgd-err-log": null,
|
"web-filter-activex-log": "enable",
|
||||||
"replacemsg-group": null,
|
"web-filter-cookie-log": "enable",
|
||||||
"web-filter-jscript-log": null,
|
"web": {
|
||||||
"web-filter-activex-log": null,
|
"blacklist": null,
|
||||||
"web-filter-js-log": null,
|
"log-search": null,
|
||||||
"web-ftgd-quota-usage": null,
|
"keyword-match": null,
|
||||||
"web-filter-unknown-log": null,
|
"urlfilter-table": null,
|
||||||
"web-filter-cookie-log": null,
|
"bword-table": null,
|
||||||
"youtube-channel-status": null,
|
"safe-search": null,
|
||||||
"web-url-log": null,
|
"whitelist": null,
|
||||||
"options": null,
|
"content-header-list": null,
|
||||||
"wisp-servers": null,
|
"youtube-restrict": null,
|
||||||
"wisp-algorithm": null
|
"bword-threshold": null
|
||||||
},
|
},
|
||||||
"raw_response": {
|
"web-filter-applet-log": "enable",
|
||||||
"status": {
|
"web-ftgd-err-log": "enable",
|
||||||
"message": "OK",
|
"replacemsg-group": null,
|
||||||
"code": 0
|
"web-filter-jscript-log": "enable",
|
||||||
},
|
"web-ftgd-quota-usage": "enable",
|
||||||
"url": "/pm/config/adom/root/obj/webfilter/profile/Ansible_Web_Filter_Profile"
|
"url-extraction": {
|
||||||
},
|
"status": null,
|
||||||
"post_method": "delete"
|
"server-fqdn": null,
|
||||||
},
|
"redirect-url": null,
|
||||||
{
|
"redirect-header": null,
|
||||||
"raw_response": {
|
"redirect-no-content": null
|
||||||
"status": {
|
},
|
||||||
"message": "OK",
|
"web-filter-js-log": "enable",
|
||||||
"code": 0
|
"youtube-channel-filter": {
|
||||||
},
|
"comment": null,
|
||||||
"url": "/pm/config/adom/root/obj/webfilter/profile"
|
"channel-id": null
|
||||||
},
|
},
|
||||||
"paramgram_used": {
|
"name": "Ansible_Web_Proxy_Profile",
|
||||||
"comment": "Created by Ansible Module TEST",
|
"wisp": "enable",
|
||||||
"web-filter-command-block-log": "enable",
|
"web-filter-vbs-log": "enable",
|
||||||
"web-invalid-domain-log": "enable",
|
"web-filter-unknown-log": "enable",
|
||||||
"web-extended-all-action-log": "enable",
|
"mode": "set",
|
||||||
"adom": "root",
|
"youtube-channel-status": "blacklist",
|
||||||
"ftgd-wf": {
|
"override": {
|
||||||
"rate-javascript-urls": null,
|
"profile": null,
|
||||||
"quota": {
|
"ovrd-user-group": null,
|
||||||
"category": null,
|
"ovrd-scope": null,
|
||||||
"value": null,
|
"ovrd-cookie": null,
|
||||||
"override-replacemsg": null,
|
"ovrd-dur-mode": null,
|
||||||
"duration": null,
|
"profile-attribute": null,
|
||||||
"type": null,
|
"ovrd-dur": null,
|
||||||
"unit": null
|
"profile-type": null
|
||||||
},
|
},
|
||||||
"rate-image-urls": null,
|
"web-url-log": "enable",
|
||||||
"filters": {
|
"ovrd-perm": [
|
||||||
"category": null,
|
"bannedword-override"
|
||||||
"auth-usr-grp": null,
|
],
|
||||||
"log": null,
|
"https-replacemsg": null,
|
||||||
"warning-prompt": null,
|
"options": [
|
||||||
"override-replacemsg": null,
|
"js"
|
||||||
"action": null,
|
],
|
||||||
"warn-duration": null,
|
"wisp-servers": null,
|
||||||
"warning-duration-type": null
|
"wisp-algorithm": "auto-learning"
|
||||||
},
|
},
|
||||||
"rate-css-urls": null,
|
"post_method": "set"
|
||||||
"ovrd": null,
|
}
|
||||||
"exempt-quota": null,
|
]
|
||||||
"max-quota-timeout": null,
|
|
||||||
"rate-crl-urls": null,
|
|
||||||
"options": null
|
|
||||||
},
|
|
||||||
"web-content-log": "enable",
|
|
||||||
"web-filter-referer-log": "enable",
|
|
||||||
"log-all-url": "enable",
|
|
||||||
"extended-log": "enable",
|
|
||||||
"inspection-mode": "proxy",
|
|
||||||
"web-filter-cookie-removal-log": "enable",
|
|
||||||
"post-action": "block",
|
|
||||||
"web-filter-activex-log": "enable",
|
|
||||||
"web-filter-cookie-log": "enable",
|
|
||||||
"web": {
|
|
||||||
"blacklist": null,
|
|
||||||
"log-search": null,
|
|
||||||
"keyword-match": null,
|
|
||||||
"urlfilter-table": null,
|
|
||||||
"bword-table": null,
|
|
||||||
"safe-search": null,
|
|
||||||
"whitelist": null,
|
|
||||||
"content-header-list": null,
|
|
||||||
"youtube-restrict": null,
|
|
||||||
"bword-threshold": null
|
|
||||||
},
|
|
||||||
"web-filter-applet-log": "enable",
|
|
||||||
"web-ftgd-err-log": "enable",
|
|
||||||
"replacemsg-group": null,
|
|
||||||
"web-filter-jscript-log": "enable",
|
|
||||||
"web-ftgd-quota-usage": "enable",
|
|
||||||
"url-extraction": {
|
|
||||||
"status": null,
|
|
||||||
"server-fqdn": null,
|
|
||||||
"redirect-url": null,
|
|
||||||
"redirect-header": null,
|
|
||||||
"redirect-no-content": null
|
|
||||||
},
|
|
||||||
"web-filter-js-log": "enable",
|
|
||||||
"youtube-channel-filter": {
|
|
||||||
"comment": null,
|
|
||||||
"channel-id": null
|
|
||||||
},
|
|
||||||
"name": "Ansible_Web_Filter_Profile",
|
|
||||||
"wisp": "enable",
|
|
||||||
"web-filter-vbs-log": "enable",
|
|
||||||
"web-filter-unknown-log": "enable",
|
|
||||||
"mode": "set",
|
|
||||||
"youtube-channel-status": "blacklist",
|
|
||||||
"override": {
|
|
||||||
"profile": null,
|
|
||||||
"ovrd-user-group": null,
|
|
||||||
"ovrd-scope": null,
|
|
||||||
"ovrd-cookie": null,
|
|
||||||
"ovrd-dur-mode": null,
|
|
||||||
"profile-attribute": null,
|
|
||||||
"ovrd-dur": null,
|
|
||||||
"profile-type": null
|
|
||||||
},
|
|
||||||
"web-url-log": "enable",
|
|
||||||
"ovrd-perm": "bannedword-override",
|
|
||||||
"https-replacemsg": null,
|
|
||||||
"options": "js",
|
|
||||||
"wisp-servers": null,
|
|
||||||
"wisp-algorithm": "auto-learning"
|
|
||||||
},
|
|
||||||
"post_method": "set"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ __metaclass__ = type
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from pyFMG.fortimgr import FortiManager
|
from ansible.module_utils.network.fortimanager.fortimanager import FortiManagerHandler
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -27,15 +27,10 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||||
|
|
||||||
fmg_instance = FortiManager("1.1.1.1", "admin", "")
|
|
||||||
|
|
||||||
|
|
||||||
def load_fixtures():
|
def load_fixtures():
|
||||||
fixture_path = os.path.join(
|
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') + "/{filename}.json".format(
|
||||||
os.path.dirname(__file__),
|
filename=os.path.splitext(os.path.basename(__file__))[0])
|
||||||
'fixtures') + "/{filename}.json".format(
|
|
||||||
filename=os.path.splitext(
|
|
||||||
os.path.basename(__file__))[0])
|
|
||||||
try:
|
try:
|
||||||
with open(fixture_path, "r") as fixture_file:
|
with open(fixture_path, "r") as fixture_file:
|
||||||
fixture_data = json.load(fixture_file)
|
fixture_data = json.load(fixture_file)
|
||||||
|
@ -44,114 +39,29 @@ def load_fixtures():
|
||||||
return [fixture_data]
|
return [fixture_data]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def module_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.module_utils.basic.AnsibleModule')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def connection_mock(mocker):
|
||||||
|
connection_class_mock = mocker.patch('ansible.modules.network.fortimanager.fmgr_secprof_web.Connection')
|
||||||
|
return connection_class_mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function", params=load_fixtures())
|
@pytest.fixture(scope="function", params=load_fixtures())
|
||||||
def fixture_data(request):
|
def fixture_data(request):
|
||||||
func_name = request.function.__name__.replace("test_", "")
|
func_name = request.function.__name__.replace("test_", "")
|
||||||
return request.param.get(func_name, None)
|
return request.param.get(func_name, None)
|
||||||
|
|
||||||
|
|
||||||
def test_fmgr_webfilter_profile_addsetdelete(fixture_data, mocker):
|
fmg_instance = FortiManagerHandler(connection_mock, module_mock)
|
||||||
mocker.patch("pyFMG.fortimgr.FortiManager._post_request", side_effect=fixture_data)
|
|
||||||
# Fixture sets used:###########################
|
|
||||||
|
|
||||||
##################################################
|
|
||||||
# comment: None
|
|
||||||
# web-extended-all-action-log: None
|
|
||||||
# url-extraction: {'status': None, 'redirect-url': None, 'server-fqdn': None, 'redirect-header': None,
|
|
||||||
# 'redirect-no-content': None}
|
|
||||||
# ftgd-wf: {'filters': {'category': None, 'log': None, 'override-replacemsg': None, 'warning-duration-type': None,
|
|
||||||
# 'warn-duration': None, 'auth-usr-grp': None, 'action': None, 'warning-prompt': None}, 'ovrd': None,
|
|
||||||
# 'rate-image-urls': None, 'quota': {'category': None, 'value': None, 'override-replacemsg': None,
|
|
||||||
# 'duration': None, 'type': None, 'unit': None}, 'options': None, 'rate-javascript-urls': None,
|
|
||||||
# 'max-quota-timeout': None, 'rate-css-urls': None, 'exempt-quota': None, 'rate-crl-urls': None}
|
|
||||||
# log-all-url: None
|
|
||||||
# extended-log: None
|
|
||||||
# web-filter-cookie-removal-log: None
|
|
||||||
# https-replacemsg: None
|
|
||||||
# web: {'log-search': None, 'bword-threshold': None, 'bword-table': None, 'whitelist': None,
|
|
||||||
# 'youtube-restrict': None, 'safe-search': None, 'blacklist': None, 'keyword-match': None,
|
|
||||||
# 'urlfilter-table': None, 'content-header-list': None}
|
|
||||||
# wisp: None
|
|
||||||
# web-filter-vbs-log: None
|
|
||||||
# youtube-channel-filter: {'comment': None, 'channel-id': None}
|
|
||||||
# override: {'profile': None, 'ovrd-scope': None, 'ovrd-dur-mode': None, 'profile-attribute': None,
|
|
||||||
# 'ovrd-dur': None, 'profile-type': None, 'ovrd-user-group': None, 'ovrd-cookie': None}
|
|
||||||
# ovrd-perm: None
|
|
||||||
# mode: delete
|
|
||||||
# web-content-log: None
|
|
||||||
# web-invalid-domain-log: None
|
|
||||||
# adom: root
|
|
||||||
# web-filter-referer-log: None
|
|
||||||
# inspection-mode: None
|
|
||||||
# post-action: None
|
|
||||||
# name: Ansible_Web_Filter_Profile
|
|
||||||
# web-filter-command-block-log: None
|
|
||||||
# web-filter-applet-log: None
|
|
||||||
# web-ftgd-err-log: None
|
|
||||||
# replacemsg-group: None
|
|
||||||
# web-filter-jscript-log: None
|
|
||||||
# web-filter-activex-log: None
|
|
||||||
# web-filter-js-log: None
|
|
||||||
# web-ftgd-quota-usage: None
|
|
||||||
# web-filter-unknown-log: None
|
|
||||||
# web-filter-cookie-log: None
|
|
||||||
# youtube-channel-status: None
|
|
||||||
# web-url-log: None
|
|
||||||
# options: None
|
|
||||||
# wisp-servers: None
|
|
||||||
# wisp-algorithm: None
|
|
||||||
##################################################
|
|
||||||
##################################################
|
|
||||||
# comment: Created by Ansible Module TEST
|
|
||||||
# web-filter-command-block-log: enable
|
|
||||||
# web-invalid-domain-log: enable
|
|
||||||
# web-extended-all-action-log: enable
|
|
||||||
# adom: root
|
|
||||||
# ftgd-wf: {'rate-javascript-urls': None, 'quota': {'category': None, 'value': None, 'override-replacemsg': None,
|
|
||||||
# 'duration': None, 'type': None, 'unit': None}, 'rate-image-urls': None, 'filters': {'category': None,
|
|
||||||
# 'auth-usr-grp': None, 'log': None, 'warning-prompt': None, 'override-replacemsg': None, 'action': None,
|
|
||||||
# 'warn-duration': None, 'warning-duration-type': None}, 'rate-css-urls': None, 'ovrd': None,
|
|
||||||
# 'exempt-quota': None, 'max-quota-timeout': None, 'rate-crl-urls': None, 'options': None}
|
|
||||||
# web-content-log: enable
|
|
||||||
# web-filter-referer-log: enable
|
|
||||||
# log-all-url: enable
|
|
||||||
# extended-log: enable
|
|
||||||
# inspection-mode: proxy
|
|
||||||
# web-filter-cookie-removal-log: enable
|
|
||||||
# post-action: block
|
|
||||||
# web-filter-activex-log: enable
|
|
||||||
# web-filter-cookie-log: enable
|
|
||||||
# web: {'blacklist': None, 'log-search': None, 'keyword-match': None, 'urlfilter-table': None, 'bword-table': None,
|
|
||||||
# 'safe-search': None, 'whitelist': None, 'content-header-list': None, 'youtube-restrict': None,
|
|
||||||
# 'bword-threshold': None}
|
|
||||||
# web-filter-applet-log: enable
|
|
||||||
# web-ftgd-err-log: enable
|
|
||||||
# replacemsg-group: None
|
|
||||||
# web-filter-jscript-log: enable
|
|
||||||
# web-ftgd-quota-usage: enable
|
|
||||||
# url-extraction: {'status': None, 'server-fqdn': None, 'redirect-url': None, 'redirect-header': None,
|
|
||||||
# 'redirect-no-content': None}
|
|
||||||
# web-filter-js-log: enable
|
|
||||||
# youtube-channel-filter: {'comment': None, 'channel-id': None}
|
|
||||||
# name: Ansible_Web_Filter_Profile
|
|
||||||
# wisp: enable
|
|
||||||
# web-filter-vbs-log: enable
|
|
||||||
# web-filter-unknown-log: enable
|
|
||||||
# mode: set
|
|
||||||
# youtube-channel-status: blacklist
|
|
||||||
# override: {'profile': None, 'ovrd-user-group': None, 'ovrd-scope': None, 'ovrd-cookie': None,
|
|
||||||
# 'ovrd-dur-mode': None, 'profile-attribute': None, 'ovrd-dur': None, 'profile-type': None}
|
|
||||||
# web-url-log: enable
|
|
||||||
# ovrd-perm: bannedword-override
|
|
||||||
# https-replacemsg: None
|
|
||||||
# options: js
|
|
||||||
# wisp-servers: None
|
|
||||||
# wisp-algorithm: auto-learning
|
|
||||||
##################################################
|
|
||||||
|
|
||||||
# Test using fixture 1 #
|
def test_fmgr_webfilter_profile_modify(fixture_data, mocker):
|
||||||
output = fmgr_secprof_web.fmgr_webfilter_profile_addsetdelete(fmg_instance, fixture_data[0]['paramgram_used'])
|
mocker.patch("ansible.module_utils.network.fortimanager.fortimanager.FortiManagerHandler.process_request",
|
||||||
assert output['raw_response']['status']['code'] == 0
|
side_effect=fixture_data)
|
||||||
# Test using fixture 2 #
|
output = fmgr_secprof_web.fmgr_webfilter_profile_modify(fmg_instance, fixture_data[0]['paramgram_used'])
|
||||||
output = fmgr_secprof_web.fmgr_webfilter_profile_addsetdelete(fmg_instance, fixture_data[1]['paramgram_used'])
|
|
||||||
assert output['raw_response']['status']['code'] == 0
|
assert output['raw_response']['status']['code'] == 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue