mirror of
https://github.com/thegeeklab/ansible-doctor.git
synced 2024-06-02 00:19:43 +02:00
Merge pull request #5 from xoxys/fix-yaml-tags
add custom yaml constructor to load ansible unsafe tag
This commit is contained in:
commit
29b1d5303b
|
@ -2,5 +2,6 @@
|
||||||
* add `role_name` config option to overwrite name of the role
|
* add `role_name` config option to overwrite name of the role
|
||||||
* fix not aborting overwrite dialog
|
* fix not aborting overwrite dialog
|
||||||
* fix failed loading of empty yaml files
|
* fix failed loading of empty yaml files
|
||||||
|
* fix failed loading of yaml files containing `!unsafe` tag
|
||||||
* FEATURE
|
* FEATURE
|
||||||
* add basic hugo theme
|
* add basic hugo theme
|
||||||
|
|
|
@ -15,6 +15,7 @@ from ansibledoctor.Config import SingleConfig
|
||||||
from ansibledoctor.Contstants import YAML_EXTENSIONS
|
from ansibledoctor.Contstants import YAML_EXTENSIONS
|
||||||
from ansibledoctor.FileRegistry import Registry
|
from ansibledoctor.FileRegistry import Registry
|
||||||
from ansibledoctor.Utils import SingleLog
|
from ansibledoctor.Utils import SingleLog
|
||||||
|
from ansibledoctor.Utils import UnsafeTag
|
||||||
|
|
||||||
|
|
||||||
class Parser:
|
class Parser:
|
||||||
|
@ -35,6 +36,7 @@ class Parser:
|
||||||
if any(fnmatch.fnmatch(rfile, "*/defaults/*." + ext) for ext in YAML_EXTENSIONS):
|
if any(fnmatch.fnmatch(rfile, "*/defaults/*." + ext) for ext in YAML_EXTENSIONS):
|
||||||
with open(rfile, "r", encoding="utf8") as yaml_file:
|
with open(rfile, "r", encoding="utf8") as yaml_file:
|
||||||
try:
|
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 {}))
|
data = defaultdict(dict, (ruamel.yaml.safe_load(yaml_file) or {}))
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
self._data["var"][key] = {"value": {key: value}}
|
self._data["var"][key] = {"value": {key: value}}
|
||||||
|
|
|
@ -191,6 +191,17 @@ class SingleLog(Log, metaclass=Singleton):
|
||||||
pass
|
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:
|
class FileUtils:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_path(path):
|
def create_path(path):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user