mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-22 12:50:42 +00:00
fix: handle custom yaml tag '!unsafe'
This commit is contained in:
parent
b6fb8cab47
commit
777415731d
@ -15,6 +15,7 @@ from .yamlhelper import action_tasks
|
|||||||
from .yamlhelper import normalize_task
|
from .yamlhelper import normalize_task
|
||||||
from .yamlhelper import normalized_yaml
|
from .yamlhelper import normalized_yaml
|
||||||
from .yamlhelper import parse_yaml_linenumbers
|
from .yamlhelper import parse_yaml_linenumbers
|
||||||
|
from .yamlhelper import UnsafeTag
|
||||||
|
|
||||||
|
|
||||||
def get_tasks(candidate, settings):
|
def get_tasks(candidate, settings):
|
||||||
@ -160,6 +161,9 @@ def get_raw_yaml(candidate, settings):
|
|||||||
if not candidate.faulty:
|
if not candidate.faulty:
|
||||||
try:
|
try:
|
||||||
with codecs.open(candidate.path, mode="rb", encoding="utf-8") as f:
|
with codecs.open(candidate.path, mode="rb", encoding="utf-8") as f:
|
||||||
|
yaml.add_constructor(
|
||||||
|
UnsafeTag.yaml_tag, UnsafeTag.yaml_constructor, Loader=yaml.SafeLoader
|
||||||
|
)
|
||||||
content = yaml.safe_load(f)
|
content = yaml.safe_load(f)
|
||||||
except yaml.YAMLError as e:
|
except yaml.YAMLError as e:
|
||||||
errors.append(
|
errors.append(
|
||||||
@ -176,6 +180,9 @@ def run_yamllint(candidate, options="extends: default"):
|
|||||||
if not candidate.faulty:
|
if not candidate.faulty:
|
||||||
try:
|
try:
|
||||||
with codecs.open(candidate.path, mode="rb", encoding="utf-8") as f:
|
with codecs.open(candidate.path, mode="rb", encoding="utf-8") as f:
|
||||||
|
yaml.add_constructor(
|
||||||
|
UnsafeTag.yaml_tag, UnsafeTag.yaml_constructor, Loader=yaml.SafeLoader
|
||||||
|
)
|
||||||
yaml.safe_load(f)
|
yaml.safe_load(f)
|
||||||
|
|
||||||
for problem in linter.run(f, YamlLintConfig(options)):
|
for problem in linter.run(f, YamlLintConfig(options)):
|
||||||
|
@ -576,3 +576,16 @@ def normalized_yaml(file, options):
|
|||||||
except (yaml.parser.ParserError, yaml.scanner.ScannerError) as e:
|
except (yaml.parser.ParserError, yaml.scanner.ScannerError) as e:
|
||||||
raise LaterError("syntax error", e)
|
raise LaterError("syntax error", e)
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
|
||||||
|
class UnsafeTag:
|
||||||
|
"""Handle custom yaml unsafe tag."""
|
||||||
|
|
||||||
|
yaml_tag = u"!unsafe"
|
||||||
|
|
||||||
|
def __init__(self, value):
|
||||||
|
self.unsafe = value
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def yaml_constructor(loader, node):
|
||||||
|
return loader.construct_scalar(node)
|
||||||
|
Loading…
Reference in New Issue
Block a user