Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ Good example:
finding.cwe = data["mykey"]
```

```python
finding.cwe = data.get("mykey", 123)
```

```python
some_list = data.get("key_of_the_list") or []
```

The finale example guards against cases where `key_of_the_list` is present, but `null`.


### Parsing of CVSS vectors

Data can have `CVSS` vectors or scores. Defect Dojo use the `cvss` module provided by RedHat Security.
Expand Down
18 changes: 11 additions & 7 deletions dojo/tools/twistlock/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,14 @@ def parse_json(self, json_output):

def get_items(self, tree, test):
items = {}
if "results" in tree:
results = tree.get("results") or []
if results:
# Extract image metadata for impact field (Item 3)
result = tree["results"][0]
result = results[0]
image_metadata = self.build_image_metadata(result)

# Parse vulnerabilities
vulnerabilityTree = result.get("vulnerabilities", [])
vulnerabilityTree = result.get("vulnerabilities") or []
for node in vulnerabilityTree:
item = get_item(node, test, image_metadata)
unique_key = node["id"] + str(
Expand All @@ -194,7 +195,7 @@ def get_items(self, tree, test):
items[unique_key] = item

# Parse compliance findings
complianceTree = result.get("compliances", [])
complianceTree = result.get("compliances") or []
for node in complianceTree:
item = get_compliance_item(node, test, image_metadata)
# Create unique key for compliance findings - prefer ID if available
Expand Down Expand Up @@ -326,11 +327,14 @@ def get_compliance_item(compliance, test, image_metadata=""):


def convert_severity(severity):
if severity.lower() == "important":
if not severity:
return "Info"
sev_lower = severity.lower()
if sev_lower == "important":
return "High"
if severity.lower() == "moderate":
if sev_lower == "moderate":
return "Medium"
if severity.lower() in {"information", "informational", ""}:
if sev_lower in {"information", "informational", ""}:
return "Info"
return severity.title()

Expand Down