1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Validate parse_cli filter inputs (#31293)

* Validate parse_cli filter inputs

Fixes #30517

*  Add check to validate input is of type string
*  Add check to confirm template file exist

* Update error message for parse_cli_textfsm invalid template path

* Add input validation for parse_cli_textfsm filter
This commit is contained in:
Ganesh Nalawade 2017-10-13 21:26:24 +05:30 committed by GitHub
parent 8d4c059275
commit 89428a40b3

View file

@ -27,7 +27,7 @@ import json
from collections import Mapping from collections import Mapping
from ansible.module_utils.network_common import Template from ansible.module_utils.network_common import Template
from ansible.module_utils.six import iteritems from ansible.module_utils.six import iteritems, string_types
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
try: try:
@ -76,6 +76,12 @@ def re_search(regex, value):
def parse_cli(output, tmpl): def parse_cli(output, tmpl):
if not isinstance(output, string_types):
raise AnsibleError("parse_cli input should be a string, but was given a input of %s" % (type(output)))
if not os.path.exists(tmpl):
raise AnsibleError('unable to locate parse_cli template: %s' % tmpl)
try: try:
template = Template() template = Template()
except ImportError as exc: except ImportError as exc:
@ -216,8 +222,11 @@ def parse_cli_textfsm(value, template):
if not HAS_TEXTFSM: if not HAS_TEXTFSM:
raise AnsibleError('parse_cli_textfsm filter requires TextFSM library to be installed') raise AnsibleError('parse_cli_textfsm filter requires TextFSM library to be installed')
if not isinstance(value, string_types):
raise AnsibleError("parse_cli_textfsm input should be a string, but was given a input of %s" % (type(value)))
if not os.path.exists(template): if not os.path.exists(template):
raise AnsibleError('unable to locate parse_cli template: %s' % template) raise AnsibleError('unable to locate parse_cli_textfsm template: %s' % template)
try: try:
template = open(template) template = open(template)