import requests
import base64
import json
# Configuration
baseUrl = "https://localhost:8443"
username = "---USERNAME---"
password = "---PASSWORD---"
commandId = "---COMMAND-ID---"
# Login & get JWT token
headers = {
"Authorization":
"Basic " +
base64
.b64encode(
(username + ":" + password)
.encode('utf-8')
)
.decode('utf-8')
}
response = requests.request("POST", "%s/api/v1/auth/login" % baseUrl, headers=headers, verify=False)
if response.status_code != 200:
print("Login failed")
exit()
authToken = response.text
headers = {"Authorization": "Bearer " + authToken}
# Get command result
response = requests.get("%s/api/v1/commands/%s" % (baseUrl, commandId), headers=headers, verify=False)
if response.status_code != 200:
print("Could not receive result")
print(response.text)
exit()
data = json.loads(response.text)
if data["result"] is None:
print("Result not received yet")
exit()
print("Command result status: %s" % (data["result"]["status"]))
for entry in data["result"]["entries"]:
print("Result entry '%s'" % entry["name"])
print(" type: %s" % entry["type"])
if entry["type"] == "text":
print(" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print(entry["value"])
print(" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")