mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-21 10:57:01 +00:00
add constructor to handle equal sign (=) (#104)
Equal sign (=) was not parsed properly by pyyaml. Added constructor to parse equal sign as string. Related issue: https://github.com/yannh/kubeconform/issues/103
This commit is contained in:
parent
932b35d71f
commit
b5f34caa70
1 changed files with 12 additions and 1 deletions
|
|
@ -72,7 +72,7 @@ def allow_null_optional_fields(data, parent=None, grand_parent=None, key=None):
|
||||||
elif isinstance(v, str):
|
elif isinstance(v, str):
|
||||||
is_non_null_type = k == "type" and v != "null"
|
is_non_null_type = k == "type" and v != "null"
|
||||||
has_required_fields = grand_parent and "required" in grand_parent
|
has_required_fields = grand_parent and "required" in grand_parent
|
||||||
if is_non_null_type and not has_required_field:
|
if is_non_null_type and not has_required_fields:
|
||||||
new_v = [v, "null"]
|
new_v = [v, "null"]
|
||||||
new[k] = new_v
|
new[k] = new_v
|
||||||
return new
|
return new
|
||||||
|
|
@ -106,6 +106,16 @@ def write_schema_file(schema, filename):
|
||||||
print("JSON schema written to {filename}".format(filename=filename))
|
print("JSON schema written to {filename}".format(filename=filename))
|
||||||
|
|
||||||
|
|
||||||
|
def construct_value(load, node):
|
||||||
|
# Handle nodes that start with '='
|
||||||
|
# See https://github.com/yaml/pyyaml/issues/89
|
||||||
|
if not isinstance(node, yaml.ScalarNode):
|
||||||
|
raise yaml.constructor.ConstructorError(
|
||||||
|
"while constructing a value",
|
||||||
|
node.start_mark,
|
||||||
|
"expected a scalar, but found %s" % node.id, node.start_mark
|
||||||
|
)
|
||||||
|
yield str(node.value)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
@ -120,6 +130,7 @@ if __name__ == "__main__":
|
||||||
f = open(crdFile)
|
f = open(crdFile)
|
||||||
with f:
|
with f:
|
||||||
defs = []
|
defs = []
|
||||||
|
yaml.SafeLoader.add_constructor(u'tag:yaml.org,2002:value', construct_value)
|
||||||
for y in yaml.load_all(f, Loader=yaml.SafeLoader):
|
for y in yaml.load_all(f, Loader=yaml.SafeLoader):
|
||||||
if y is None:
|
if y is None:
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue