Skip to content

Commit

Permalink
fix(panos_export): Fix binary exports (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesholland-uk authored Feb 15, 2023
1 parent 29d4cbc commit 2666536
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions plugins/modules/panos_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,26 @@ def export_binary(module, xapi, category, filename):
module.fail_json(msg=msg)


def save_binary(module, xapi, category, filename):

# This function is almost the same as export_binary, but omits the line...
# xapi.export(category=category)
# This function is therefore used where the xapi.export operation is already done

f = None

try:
with open(filename, "wb") as f:
content = xapi.export_result["content"]

if content is not None:
f.write(content)

f.close()
except IOError as msg:
module.fail_json(msg=msg)


def export_async(module, xapi, category, filename, interval=60, timeout=600):

# Submit job, get resulting job id
Expand Down Expand Up @@ -281,19 +301,7 @@ def export_async(module, xapi, category, filename, interval=60, timeout=600):
# Get completed job
xapi.export(category=category, extra_qs={"action": "get", "job-id": job_id})

# Use only relevant code from export_binary, instead of calling export_binary (don't use the line: xapi.export(category=category))
f = None

try:
with open(filename, "wb") as f:
content = xapi.export_result["content"]

if content is not None:
f.write(content)

f.close()
except IOError as msg:
module.fail_json(msg=msg)
save_binary(module, xapi, category, filename)


HTML_EXPORTS = [
Expand Down Expand Up @@ -417,7 +425,7 @@ def main():
params["passphrase"] = cert_passphrase

xapi.export(category="certificate", extra_qs=params)
export_binary(module, xapi, filename)
save_binary(module, xapi, category, filename)

elif category == "application-pcap":

Expand All @@ -439,7 +447,7 @@ def main():
if filename is None:
module.fail_json(msg="filename is required for export")

export_binary(module, xapi, filename)
save_binary(module, xapi, category, filename)

elif category == "filter-pcap":

Expand All @@ -460,7 +468,7 @@ def main():
if filename is None:
module.fail_json(msg="filename is required for export")

export_binary(module, xapi, filename)
save_binary(module, xapi, category, filename)

elif category == "dlp-pcap":
from_name = module.params["dlp_pcap_name"]
Expand All @@ -485,7 +493,7 @@ def main():
if filename is None:
module.fail_json(msg="filename is required for export")

export_binary(module, xapi, filename)
save_binary(module, xapi, category, filename)

elif category == "threat-pcap":
if filename is None:
Expand All @@ -508,7 +516,7 @@ def main():
search_time=search_time,
serialno=serial,
)
export_binary(module, xapi, filename)
save_binary(module, xapi, category, filename)

module.exit_json(changed=False)

Expand Down

0 comments on commit 2666536

Please sign in to comment.