I have an api view which fetches data from its model. I want this api view to have an additional value from third party api. Here is views.py which grabs all of its model properties.
@api_view(
["GET"],
)
def business_asset_risk_details(request):
res = models.BusinessImpact.objects.all().values(
"hierarchy",
"business_assets",
"asset_name",
"vendors",
"product",
"version",
"cpe",
"asset_type",
"asset_categorization",
"_regulations",
"asset_risk",
)
return Response({"business_impact_details": res})
Here is third party api view fetching a specific values of it's own.
@api_view(
["GET"],
)
def cve_summery(request, key):
r = requests.get(
"https://services.nvd.nist.gov/rest/json/cves/1.0?cpeMatchString={}".format(
key)
)
if r.status_code == 200:
result = []
res = r.json().get("result").get("CVE_Items")
for rs in res:
data = {
"VulnID": rs.get("cve").get("CVE_data_meta").get("ID"),
"Summery": rs.get("cve").get("description").get("description_data"),
"exploitabilityScore": rs.get("impact")
.get("baseMetricV2")
.get("exploitabilityScore"),
"severity": rs.get("impact").get("baseMetricV2").get("severity"),
"impactScore": rs.get("impact").get("baseMetricV2").get("impactScore"),
}
result.append(data)
return Response(result)
return Response("error happend", r.status_code)
The logic here is, I want business_asset_risk_details view to return "severity": rs.get("impact").get("baseMetricV2").get("severity"), from cve_summery view.
NB: THE KEY parameter in cve_summery view IS cpe of business_asset_risk_details
Thanks.