From cacd332338096f21b47aab7553f938daea963f74 Mon Sep 17 00:00:00 2001 From: Boy Baukema Date: Fri, 13 Oct 2023 15:29:48 +0200 Subject: [PATCH] Add example for getting App id and sandbox id using legacy XML API --- samples/xml_sandbox.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 samples/xml_sandbox.py diff --git a/samples/xml_sandbox.py b/samples/xml_sandbox.py new file mode 100644 index 0000000..5f4ae9b --- /dev/null +++ b/samples/xml_sandbox.py @@ -0,0 +1,38 @@ +# a simple sample to get the sandbox id +from veracode_api_py import XMLAPI +import xml.etree.ElementTree as ET + +xmlApi = XMLAPI() +appListXml = xmlApi.get_app_list() +appList = ET.fromstring(appListXml) + +# CHANGE BELOW TO SEARCH FOR OTHER APP NAMES / SANDBOXES +searchAppName = "VeraDemo" +searchSandboxName = "POJOs" + +foundAppId = 0 +for app in appList: + appName = app.get("app_name") + appId = app.get("app_id") + if searchAppName == appName: + foundAppId = appId + break + +if foundAppId == 0: + raise Exception("Did not find app id!") + +sandboxListXml = xmlApi.get_sandbox_list(foundAppId) +sandboxList = ET.fromstring(sandboxListXml) + +foundSandboxId = 0 +for sandbox in sandboxList: + sandboxName = sandbox.get("sandbox_name") + sandboxId = sandbox.get("sandbox_id") + if searchSandboxName == sandboxName: + foundSandboxId = sandboxId + break + +if foundSandboxId == 0: + raise Exception("Did not find sandbox id!") + +print("App '" + searchAppName + "' ID: " + foundAppId + "\nSandbox '" + searchSandboxName + "' ID: " + foundSandboxId) \ No newline at end of file