From d133d63fbf158375f3ac2f1c53e6128a10e8e75b Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 24 Feb 2020 19:10:17 +0100 Subject: [PATCH 1/3] add custom yaml constructor to load ansible unsafe tag --- ansibledoctor/DocumentationParser.py | 2 ++ ansibledoctor/Utils.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/ansibledoctor/DocumentationParser.py b/ansibledoctor/DocumentationParser.py index 6136c4a..19abd3d 100644 --- a/ansibledoctor/DocumentationParser.py +++ b/ansibledoctor/DocumentationParser.py @@ -15,6 +15,7 @@ from ansibledoctor.Config import SingleConfig from ansibledoctor.Contstants import YAML_EXTENSIONS from ansibledoctor.FileRegistry import Registry from ansibledoctor.Utils import SingleLog +from ansibledoctor.Utils import UnsafeTag class Parser: @@ -35,6 +36,7 @@ class Parser: if any(fnmatch.fnmatch(rfile, "*/defaults/*." + ext) for ext in YAML_EXTENSIONS): with open(rfile, "r", encoding="utf8") as yaml_file: try: + ruamel.yaml.add_constructor(UnsafeTag.yaml_tag, UnsafeTag.yaml_constructor, constructor=ruamel.yaml.SafeConstructor) data = defaultdict(dict, (ruamel.yaml.safe_load(yaml_file) or {})) for key, value in data.items(): self._data["var"][key] = {"value": {key: value}} diff --git a/ansibledoctor/Utils.py b/ansibledoctor/Utils.py index ad18251..cbd008d 100644 --- a/ansibledoctor/Utils.py +++ b/ansibledoctor/Utils.py @@ -191,6 +191,17 @@ class SingleLog(Log, metaclass=Singleton): pass +class UnsafeTag: + yaml_tag = u'!unsafe' + + def __init__(self, value): + self.unsafe = value + + @staticmethod + def yaml_constructor(loader, node): + return loader.construct_scalar(node) + + class FileUtils: @staticmethod def create_path(path): From 5101c6962c7739a9f90179872267cb7718b4875f Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 24 Feb 2020 19:12:35 +0100 Subject: [PATCH 2/3] fix bad quotes --- ansibledoctor/Utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansibledoctor/Utils.py b/ansibledoctor/Utils.py index cbd008d..24a9f20 100644 --- a/ansibledoctor/Utils.py +++ b/ansibledoctor/Utils.py @@ -192,7 +192,7 @@ class SingleLog(Log, metaclass=Singleton): class UnsafeTag: - yaml_tag = u'!unsafe' + yaml_tag = u"!unsafe" def __init__(self, value): self.unsafe = value From af22e1bea4a31d6c3362d74391f406d1440f23d2 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 24 Feb 2020 19:18:29 +0100 Subject: [PATCH 3/3] [SKIP CI] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6317dfa..7cc3652 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,5 +2,6 @@ * add `role_name` config option to overwrite name of the role * fix not aborting overwrite dialog * fix failed loading of empty yaml files + * fix failed loading of yaml files containing `!unsafe` tag * FEATURE * add basic hugo theme