Skip to content

Commit

Permalink
Add support for XML file upload pre-change
Browse files Browse the repository at this point in the history
  • Loading branch information
adealdag committed May 29, 2024
1 parent 7281a11 commit 36b2125
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 145 deletions.
22 changes: 12 additions & 10 deletions plugins/modules/nd_pcv.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
aliases: [ site ]
file:
description:
- Optional parameter if creating new pre-change analysis from file.
- Optional parameter if creating new pre-change analysis from file. XML and JSON files are supported. If no file extension is provided, the file is assumed to be JSON.
type: str
manual:
description:
Expand Down Expand Up @@ -213,15 +213,17 @@ def main():
if file:
if not os.path.exists(file):
nd.fail_json(msg="File not found : {0}".format(file))
# check whether file content is a valid json
if ndi.is_json(open(file, "rb").read()) is False:
extract_data = ndi.load(open(file))
else:
extract_data = json.loads(open(file, "rb").read())
if isinstance(extract_data, list):
ndi.cmap = {}
tree = ndi.construct_tree(extract_data)
ndi.create_structured_data(tree, file)
# Check if file extension is XML. If XML, skip JSON validation/transformation
if not file.endswith(".xml"):
# check whether file content is a valid json
if ndi.is_json(open(file, "rb").read()) is False:
extract_data = ndi.load(open(file))
else:
extract_data = json.loads(open(file, "rb").read())
if isinstance(extract_data, list):
ndi.cmap = {}
tree = ndi.construct_tree(extract_data)
ndi.create_structured_data(tree, file)
create_pcv_path = "{0}/{1}/fabric/{2}/prechangeAnalysis/fileChanges".format(path, insights_group, site_name)
file_resp = nd.request(create_pcv_path, method="POST", file=os.path.abspath(file), data=data, prefix=ndi.prefix)
if file_resp.get("success") is True:
Expand Down
Loading

0 comments on commit 36b2125

Please sign in to comment.