mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Use salt.utils.yamlloader with SaltYamlSafeLoader as the Loader with yaml.load
This commit is contained in:
parent
a48ecc4a5c
commit
62c4d37c2f
4 changed files with 46 additions and 13 deletions
|
@ -145,10 +145,14 @@ Here is a simple YAML renderer example:
|
|||
.. code-block:: python
|
||||
|
||||
import yaml
|
||||
from salt.utils.yamlloader import SaltYamlSafeLoader
|
||||
def render(yaml_data, saltenv='', sls='', **kws):
|
||||
if not isinstance(yaml_data, basestring):
|
||||
yaml_data = yaml_data.read()
|
||||
data = yaml.load(yaml_data)
|
||||
data = yaml.load(
|
||||
yaml_data,
|
||||
Loader=SaltYamlSafeLoader
|
||||
)
|
||||
return data if data else {}
|
||||
|
||||
Full List of Renderers
|
||||
|
|
|
@ -126,10 +126,11 @@ from __future__ import absolute_import
|
|||
import logging
|
||||
import re
|
||||
import yaml
|
||||
import salt.utils.minions
|
||||
|
||||
from salt.exceptions import CommandExecutionError
|
||||
from salt.utils.dictupdate import update as dict_merge
|
||||
import salt.utils.minions
|
||||
from salt.utils.yamlloader import SaltYamlSafeLoader
|
||||
|
||||
# Import third party libs
|
||||
try:
|
||||
|
@ -251,7 +252,10 @@ def pillar_format(ret, keys, value):
|
|||
# If value is not None then it's a string
|
||||
# Use YAML to parse the data
|
||||
# YAML strips whitespaces unless they're surrounded by quotes
|
||||
pillar_value = yaml.load(value)
|
||||
pillar_value = yaml.load(
|
||||
value,
|
||||
Loader=SaltYamlSafeLoader
|
||||
)
|
||||
|
||||
keyvalue = keys.pop()
|
||||
pil = {keyvalue: pillar_value}
|
||||
|
|
|
@ -279,18 +279,19 @@ import jinja2
|
|||
import re
|
||||
from os.path import isfile, join
|
||||
|
||||
# Import 3rd-party libs
|
||||
# Import Salt libs
|
||||
import salt.ext.six as six
|
||||
from salt.ext.six.moves import input # pylint: disable=import-error,redefined-builtin
|
||||
import salt.utils
|
||||
from salt.utils.yamlloader import SaltYamlSafeLoader
|
||||
|
||||
# Import 3rd-party libs
|
||||
try:
|
||||
import requests
|
||||
HAS_REQUESTS = True
|
||||
except ImportError:
|
||||
HAS_REQUESTS = False
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils
|
||||
|
||||
# Only used when called from a terminal
|
||||
log = None
|
||||
|
@ -436,7 +437,10 @@ def ext_pillar(minion_id, pillar, resource, sequence, subkey=False, subkey_only=
|
|||
data['grains'] = __grains__.copy()
|
||||
data['pillar'] = pillar.copy()
|
||||
results_jinja = template.render(data)
|
||||
results = yaml.load(results_jinja)
|
||||
results = yaml.load(
|
||||
results_jinja,
|
||||
Loader=SaltYamlSafeLoader
|
||||
)
|
||||
except jinja2.UndefinedError as err:
|
||||
log.error('Failed to parse JINJA template: {0}\n{1}'.format(fn, err))
|
||||
except yaml.YAMLError as err:
|
||||
|
@ -529,7 +533,10 @@ def validate(output, resource):
|
|||
data = output
|
||||
data['grains'] = __grains__.copy()
|
||||
data['pillar'] = __pillar__.copy()
|
||||
schema = yaml.load(template.render(data))
|
||||
schema = yaml.load(
|
||||
template.render(data),
|
||||
Loader=SaltYamlSafeLoader
|
||||
)
|
||||
all_schemas.update(schema)
|
||||
pepa_schemas.append(fn)
|
||||
|
||||
|
@ -551,7 +558,12 @@ if __name__ == '__main__':
|
|||
|
||||
# Get configuration
|
||||
with salt.utils.fopen(args.config) as fh_:
|
||||
__opts__.update(yaml.load(fh_.read()))
|
||||
__opts__.update(
|
||||
yaml.load(
|
||||
fh_.read(),
|
||||
Loader=SaltYamlSafeLoader
|
||||
)
|
||||
)
|
||||
|
||||
loc = 0
|
||||
for name in [next(iter(list(e.keys()))) for e in __opts__['ext_pillar']]:
|
||||
|
@ -564,14 +576,24 @@ if __name__ == '__main__':
|
|||
if 'pepa_grains' in __opts__:
|
||||
__grains__ = __opts__['pepa_grains']
|
||||
if args.grains:
|
||||
__grains__.update(yaml.load(args.grains))
|
||||
__grains__.update(
|
||||
yaml.load(
|
||||
args.grains,
|
||||
Loader=SaltYamlSafeLoader
|
||||
)
|
||||
)
|
||||
|
||||
# Get pillars
|
||||
__pillar__ = {}
|
||||
if 'pepa_pillar' in __opts__:
|
||||
__pillar__ = __opts__['pepa_pillar']
|
||||
if args.pillar:
|
||||
__pillar__.update(yaml.load(args.pillar))
|
||||
__pillar__.update(
|
||||
yaml.load(
|
||||
args.pillar,
|
||||
Loader=SaltYamlSafeLoader
|
||||
)
|
||||
)
|
||||
|
||||
# Validate or not
|
||||
if args.validate:
|
||||
|
@ -607,7 +629,6 @@ if __name__ == '__main__':
|
|||
raise RuntimeError('Failed to get Grains from SaltStack REST API')
|
||||
|
||||
__grains__ = result[args.hostname]
|
||||
# print yaml.safe_dump(__grains__, indent=4, default_flow_style=False)
|
||||
|
||||
# Print results
|
||||
ex_subkey = False
|
||||
|
|
|
@ -59,6 +59,7 @@ import yaml
|
|||
# Import Salt Libs
|
||||
import salt.ext.six as six
|
||||
import salt.utils
|
||||
from salt.utils.yamlloader import SaltYamlSafeLoader
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -675,7 +676,10 @@ class _Swagger(object):
|
|||
self._swagger_file = swagger_file_path
|
||||
self._md5_filehash = _gen_md5_filehash(self._swagger_file)
|
||||
with salt.utils.fopen(self._swagger_file, 'rb') as sf:
|
||||
self._cfg = yaml.load(sf)
|
||||
self._cfg = yaml.load(
|
||||
sf,
|
||||
Loader=SaltYamlSafeLoader
|
||||
)
|
||||
self._swagger_version = ''
|
||||
else:
|
||||
raise IOError('Invalid swagger file path, {0}'.format(swagger_file_path))
|
||||
|
|
Loading…
Add table
Reference in a new issue