mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-19 18:07:02 +00:00
Merge a2191d6ef2 into 71fd5f8386
This commit is contained in:
commit
2c8d59cc74
1 changed files with 13 additions and 6 deletions
|
|
@ -101,8 +101,15 @@ def write_schema_file(schema, filename):
|
||||||
schema = replace_int_or_string(schema)
|
schema = replace_int_or_string(schema)
|
||||||
schemaJSON = json.dumps(schema, indent=2)
|
schemaJSON = json.dumps(schema, indent=2)
|
||||||
|
|
||||||
# Dealing with user input here..
|
# ensure the directory exists
|
||||||
filename = os.path.basename(filename)
|
dirname = os.path.dirname(filename)
|
||||||
|
try:
|
||||||
|
os.mkdir(dirname)
|
||||||
|
except FileExistsError:
|
||||||
|
# Assume the directory already exists
|
||||||
|
# If it's actually a file, that's user error
|
||||||
|
pass
|
||||||
|
|
||||||
f = open(filename, "w")
|
f = open(filename, "w")
|
||||||
print(schemaJSON, file=f)
|
print(schemaJSON, file=f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
@ -147,14 +154,14 @@ if __name__ == "__main__":
|
||||||
defs.append(y)
|
defs.append(y)
|
||||||
|
|
||||||
for y in defs:
|
for y in defs:
|
||||||
filename_format = os.getenv("FILENAME_FORMAT", "{kind}_{version}")
|
filename_format = os.getenv("FILENAME_FORMAT", "{group}/{kind}_{version}")
|
||||||
filename = ""
|
filename = ""
|
||||||
if "spec" in y and "versions" in y["spec"] and y["spec"]["versions"]:
|
if "spec" in y and "versions" in y["spec"] and y["spec"]["versions"]:
|
||||||
for version in y["spec"]["versions"]:
|
for version in y["spec"]["versions"]:
|
||||||
if "schema" in version and "openAPIV3Schema" in version["schema"]:
|
if "schema" in version and "openAPIV3Schema" in version["schema"]:
|
||||||
filename = filename_format.format(
|
filename = filename_format.format(
|
||||||
kind=y["spec"]["names"]["kind"],
|
kind=y["spec"]["names"]["kind"],
|
||||||
group=y["spec"]["group"].split(".")[0],
|
group=y["spec"]["group"],
|
||||||
version=version["name"],
|
version=version["name"],
|
||||||
).lower() + ".json"
|
).lower() + ".json"
|
||||||
|
|
||||||
|
|
@ -163,7 +170,7 @@ if __name__ == "__main__":
|
||||||
elif "validation" in y["spec"] and "openAPIV3Schema" in y["spec"]["validation"]:
|
elif "validation" in y["spec"] and "openAPIV3Schema" in y["spec"]["validation"]:
|
||||||
filename = filename_format.format(
|
filename = filename_format.format(
|
||||||
kind=y["spec"]["names"]["kind"],
|
kind=y["spec"]["names"]["kind"],
|
||||||
group=y["spec"]["group"].split(".")[0],
|
group=y["spec"]["group"],
|
||||||
version=version["name"],
|
version=version["name"],
|
||||||
).lower() + ".json"
|
).lower() + ".json"
|
||||||
|
|
||||||
|
|
@ -172,7 +179,7 @@ if __name__ == "__main__":
|
||||||
elif "spec" in y and "validation" in y["spec"] and "openAPIV3Schema" in y["spec"]["validation"]:
|
elif "spec" in y and "validation" in y["spec"] and "openAPIV3Schema" in y["spec"]["validation"]:
|
||||||
filename = filename_format.format(
|
filename = filename_format.format(
|
||||||
kind=y["spec"]["names"]["kind"],
|
kind=y["spec"]["names"]["kind"],
|
||||||
group=y["spec"]["group"].split(".")[0],
|
group=y["spec"]["group"],
|
||||||
version=y["spec"]["version"],
|
version=y["spec"]["version"],
|
||||||
).lower() + ".json"
|
).lower() + ".json"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue