Browse Source

Merge "Make the yaml parser aware of '!encrypted/' tags"

Zuul 1 year ago
parent
commit
2516aeff56
1 changed files with 13 additions and 2 deletions
  1. 13
    2
      zuul_sphinx/zuul.py

+ 13
- 2
zuul_sphinx/zuul.py View File

@@ -26,6 +26,17 @@ from docutils import nodes
26 26
 import yaml
27 27
 
28 28
 
29
+class ZuulSafeLoader(yaml.SafeLoader):
30
+
31
+    def __init__(self, *args, **kwargs):
32
+        super(ZuulSafeLoader, self).__init__(*args, **kwargs)
33
+        self.add_multi_constructor('!encrypted/', self.construct_encrypted)
34
+
35
+    @classmethod
36
+    def construct_encrypted(cls, loader, tag_suffix, node):
37
+        return loader.construct_sequence(node)
38
+
39
+
29 40
 class ProjectTemplate(object):
30 41
     def __init__(self, conf):
31 42
         self.name = conf['name']
@@ -72,7 +83,7 @@ class ZuulDirective(Directive):
72 83
 
73 84
     def parse_zuul_yaml(self, path):
74 85
         with open(path) as f:
75
-            data = yaml.safe_load(f)
86
+            data = yaml.load(f, Loader=ZuulSafeLoader)
76 87
         layout = Layout()
77 88
         for obj in data:
78 89
             if 'job' in obj:
@@ -86,7 +97,7 @@ class ZuulDirective(Directive):
86 97
         layout = Layout()
87 98
         for conf in os.listdir(path):
88 99
             with open(os.path.join(path, conf)) as f:
89
-                data = yaml.safe_load(f)
100
+                data = yaml.load(f, Loader=ZuulSafeLoader)
90 101
             for obj in data:
91 102
                 if 'job' in obj:
92 103
                     layout.jobs.append(obj['job'])

Loading…
Cancel
Save