summaryrefslogtreecommitdiff
path: root/buildstream/_yaml.py
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.co.uk>2017-09-06 16:52:26 +0100
committerTristan Maat <tristan.maat@codethink.co.uk>2017-09-13 17:10:10 +0100
commit06b4d3aeae88a30d922cd044feaf9f255946fe55 (patch)
tree0c0ab31cd4339fbe5d6bea24831c45056afa616d /buildstream/_yaml.py
parent5b995dd1543b9476abfe6f1d42dc43cd5d0ea7dc (diff)
downloadbuildstream-06b4d3aeae88a30d922cd044feaf9f255946fe55.tar.gz
Add _yaml.validate_node
Diffstat (limited to 'buildstream/_yaml.py')
-rw-r--r--buildstream/_yaml.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index 5ba540fc9..aead2ed84 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -575,6 +575,19 @@ def node_sanitize(node):
return node
+def validate_node(node, valid_keys):
+
+ # Probably the fastest way to do this: https://stackoverflow.com/a/23062482
+ valid_keys = set(valid_keys)
+ valid_keys.add(PROVENANCE_KEY)
+ invalid = next((key for key in node if key not in valid_keys), None)
+
+ if invalid:
+ provenance = node_get_provenance(node, key=invalid)
+ raise LoadError(LoadErrorReason.INVALID_DATA,
+ "[{}]: Unexpected key: {}".format(provenance, invalid))
+
+
def node_chain_copy(source):
copy = collections.ChainMap({}, source)
for key, value in source.items():