Skip to content

Commit

Permalink
Merge pull request #6 from TheScriptGuy/4-output-without-any-outputfi…
Browse files Browse the repository at this point in the history
…le-option-gets-weird

Version 0.12. See CHANGELOG.md
  • Loading branch information
TheScriptGuy authored Jan 30, 2023
2 parents c19dff1 + 40a9a89 commit 390e2be
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# PrismaAccess-Egress IPs Changelog
## 2023-01-30 - 0.12
* Found the pesky stdout formatting [bug](https://github.com/TheScriptGuy/PrismaAccess-EgressIPs/issues/4) and squashed it.

## 2023-01-30 - 0.11
## New feature
* added `--outputEdlFile` argument to send IP's only directly to file.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ usage: format-egress-ips.py [-h] [--fileName FILENAME] [--setAPIKey SETAPIKEY] [
[--allCleanPipeAddresses] [--allExplicitProxyAddresses] [--allLoopbackIPAddresses] [--outputJsonFile OUTPUTJSONFILE]
[--outputCsvFile OUTPUTCSVFILE] [--outputEdlFile OUTPUTEDLFILE]

Format Egress IPs 0.11
Format Egress IPs 0.12

options:
-h, --help show this help message and exit
Expand Down
12 changes: 4 additions & 8 deletions format-egress-ips.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Formats the json output to get all the egress IPs
# Author: TheScriptGuy
# Last modified: 2023-01-30
# Version: 0.11
# Version: 0.12
# Changelog:
# Added some better error handling in case a json object is not returned.

Expand All @@ -14,7 +14,7 @@
from requests.packages.urllib3.exceptions import InsecureRequestWarning


scriptVersion = "0.11"
scriptVersion = "0.12"

API_KEY_FILE = 'prisma-access-api.key'

Expand Down Expand Up @@ -178,7 +178,6 @@ def jsonConvert2Csv(__csvFile, __dataObject):

def printJsonObject(__jsonObject):
"""Output the Json object in a tabulated format to stdout"""
# Print Headers
try:
if isinstance(__jsonObject, list):
# Table looks a little different for loopback_ips
Expand All @@ -195,10 +194,7 @@ def printJsonObject(__jsonObject):
locationInfo = item.split(":")
print(tableString.format(jsonItem["result"]["fwType"], locationInfo[0], locationInfo[1]))
else:
if "status" in __jsonObject and \
__jsonObject["status"] == "success" and \
__jsonObject["result"]["addrListType"] not in "loopback_ip":

if "status" in __jsonObject and __jsonObject["status"] != "error":
# Set the table string format.
tableString = '{: <20}{: <18}{: <18}{: <18}'
print(tableString.format("Location", "serviceType", "egress IP", "Active/Reserved"))
Expand All @@ -208,7 +204,7 @@ def printJsonObject(__jsonObject):
for obj in objEgressIps["address_details"]:
print(tableString.format(objEgressIps["zone"], obj["serviceType"], obj["address"], obj["addressType"]))
else:
print(__jsonObject)
print(__jsonObject["result"])
sys.exit(1)

except TypeError:
Expand Down

0 comments on commit 390e2be

Please sign in to comment.