Skip to content

Instantly share code, notes, and snippets.

@boriphuth
Last active November 2, 2020 16:12
Show Gist options
  • Save boriphuth/5f03d9300a30628e687d1f8a1e453fbf to your computer and use it in GitHub Desktop.
Save boriphuth/5f03d9300a30628e687d1f8a1e453fbf to your computer and use it in GitHub Desktop.
import argparse
from datetime import datetime
import json
import os
import requests
import logging
def GetProducts(DefectDojoURL, apiKey):
url = DefectDojoURL + "/api/v2/products/"
dataApi = None
headers = {'Authorization': "Token " + apiKey}
data = []
n = 0
jsondata = fetch_data(url, headers, dataApi, False)
if jsondata:
for results in jsondata:
n += 1
product_url = results['url'].split("/")
id_product = product_url[len(product_url)-2]
data.append([n, id_product, results['name'], results['url'], results['findings_count'], results['prod_type'],
results['description'], results['platform'], results['lifecycle'], results['origin']])
print((colored(tabulate(data, tablefmt="fancy_grid", headers=[
"#", "ID Product", "Name", "URL", "Findings", "Product Type", "Description", "Platform", "Lifecycle", "Origin"]), 'green')))
def fetch_data(DefectDojoURL, headersapi, dataApi, upload):
if dataApi or upload:
r = requests.post(DefectDojoURL, headers=headersapi,
data=dataApi, verify=False)
else:
r = requests.get(DefectDojoURL, headers=headersapi, verify=False)
if not (r.status_code == 200 or r.status_code == 201):
logging.error('Error in operation')
return False
results = json.loads(r.text)
logging.info(results)
if results:
try:
return results['results']
except KeyError as error:
return results
else:
logging.error('Error in operation')
return None
GetProducts("http://10.0.1.20:8080", 'c3d20a82f95dcc2a758e3ef4a491197358ec0e9f')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment