mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +00:00
openapi2jsonschema: Allow writting to subdirectories
Verify that the target filename (templates from `FILENAME_FORMAT`) is in the current working directory and allow writting to arbitrary subdirectories if this is the case
This commit is contained in:
parent
347cd5e4c9
commit
cb6b6c3f24
1 changed files with 10 additions and 1 deletions
|
|
@ -102,7 +102,16 @@ def write_schema_file(schema, filename):
|
|||
schemaJSON = json.dumps(schema, indent=2)
|
||||
|
||||
# Dealing with user input here..
|
||||
filename = os.path.basename(filename)
|
||||
cwd = Path.cwd()
|
||||
abspath = Path(filename).resolve()
|
||||
if cwd in abspath.parents:
|
||||
filename = abspath.relative_to(cwd)
|
||||
if not filename.parent.exists():
|
||||
filename.parent.mkdir(parents=True)
|
||||
else:
|
||||
print("Trying to write to a file outside of the current directory, aborting.")
|
||||
exit(1)
|
||||
|
||||
f = open(filename, "w")
|
||||
print(schemaJSON, file=f)
|
||||
f.close()
|
||||
|
|
|
|||
Loading…
Reference in a new issue