summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Schmidt <felix.fs.schmidt@bmw.de>2018-04-10 10:30:20 +0200
committerFelix Schmidt <felix.fs.schmidt@bmw.de>2018-04-10 14:47:40 +0200
commit3ef1afe17ee74f5420247463652efd71e6f1e406 (patch)
tree58315d3dbd37ee0c718feae3e398eac0037c2af3
parent12b3f457bd9d94fb37389e921c64ac9e6f01cd8c (diff)
Make the yaml parser aware of '!encrypted/' tags
Currently, the documentation generation for zuul jobs fails whenever a secret is included in any of the yaml files that are parsed by the zuul-sphinx extension. This is because the yaml parser is not aware of the custom tag '!encrypted/pkcs1-oaep' and therefore fails to initialize an appropriate python object due to a missing constructor. This results in the following error message: "yaml.constructor.ConstructorError: could not determine a constructor for the tag '!encrypted/pkcs1-oaep'" Change-Id: Id011487615a3392affd627bbdcbdbe18e58206c5
Notes
Notes (review): Code-Review+2: Tobias Henkel <tobias.henkel@bmw.de> Code-Review+2: Monty Taylor <mordred@inaugust.com> Code-Review+2: James E. Blair <corvus@inaugust.com> Workflow+1: Tobias Henkel <tobias.henkel@bmw.de> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 12 Apr 2018 19:44:46 +0000 Reviewed-on: https://review.openstack.org/559963 Project: openstack-infra/zuul-sphinx Branch: refs/heads/master
-rw-r--r--zuul_sphinx/zuul.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/zuul_sphinx/zuul.py b/zuul_sphinx/zuul.py
index 95d69cb..a140988 100644
--- a/zuul_sphinx/zuul.py
+++ b/zuul_sphinx/zuul.py
@@ -26,6 +26,17 @@ from docutils import nodes
26import yaml 26import yaml
27 27
28 28
29class 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
29class ProjectTemplate(object): 40class ProjectTemplate(object):
30 def __init__(self, conf): 41 def __init__(self, conf):
31 self.name = conf['name'] 42 self.name = conf['name']
@@ -72,7 +83,7 @@ class ZuulDirective(Directive):
72 83
73 def parse_zuul_yaml(self, path): 84 def parse_zuul_yaml(self, path):
74 with open(path) as f: 85 with open(path) as f:
75 data = yaml.safe_load(f) 86 data = yaml.load(f, Loader=ZuulSafeLoader)
76 layout = Layout() 87 layout = Layout()
77 for obj in data: 88 for obj in data:
78 if 'job' in obj: 89 if 'job' in obj:
@@ -86,7 +97,7 @@ class ZuulDirective(Directive):
86 layout = Layout() 97 layout = Layout()
87 for conf in os.listdir(path): 98 for conf in os.listdir(path):
88 with open(os.path.join(path, conf)) as f: 99 with open(os.path.join(path, conf)) as f:
89 data = yaml.safe_load(f) 100 data = yaml.load(f, Loader=ZuulSafeLoader)
90 for obj in data: 101 for obj in data:
91 if 'job' in obj: 102 if 'job' in obj:
92 layout.jobs.append(obj['job']) 103 layout.jobs.append(obj['job'])