Skip to content

Commit

Permalink
Ruff: Add and fix D413 (#11065)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Tesauro <[email protected]>
  • Loading branch information
kiblik and mtesauro authored Nov 5, 2024
1 parent e6447df commit eae8bad
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions dojo/api_v2/prefetch/prefetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def _build_serializers():
Returns:
dict[model, serializer]: map of model to their serializer
"""

def _is_model_serializer(obj):
Expand Down Expand Up @@ -61,6 +62,7 @@ def _find_serializer(self, field_type):
Returns:
rest_framework.serializers.ModelSerializer: The serializer if one has been found or None
"""
# If the type is represented in the map then return the serializer
if field_type in self._serializers:
Expand All @@ -80,6 +82,7 @@ def _prefetch(self, entry, fields_to_fetch):
Args:
entry (ModelInstance): Instance of a model as returned by a django queryset
field_to_fetch (list[string]): fields to prefetch
"""
for field_to_fetch in fields_to_fetch:
# Get the field from the instance
Expand Down
3 changes: 3 additions & 0 deletions dojo/api_v2/prefetch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def _is_many_to_many_relation(field):
Returns:
bool: true if the field is a many-to-many relationship
"""
return isinstance(field, related.ManyToManyDescriptor)

Expand All @@ -27,6 +28,7 @@ def _is_one_to_one_relation(field):
Returns:
bool: true if the field is a one-to-one relationship
"""
return isinstance(field, related.ForwardManyToOneDescriptor)

Expand All @@ -38,6 +40,7 @@ def _get_prefetchable_fields(serializer):
Args:
serializer (Serializer): [description]
"""

def _is_field_prefetchable(field):
Expand Down
1 change: 1 addition & 0 deletions dojo/tools/intsights/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def _build_finding_description(self, alert: dict) -> str:
Args:
alert: The parsed alert dictionary
Returns: A markdown formatted description
"""
return "\n".join(
[
Expand Down
1 change: 1 addition & 0 deletions dojo/tools/qualys/csv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def _extract_cvss_vectors(cvss_base, cvss_temporal):
cvss_temporal:
Returns:
A CVSS3 Vector including both Base and Temporal if available
"""
vector_pattern = r"^\d{1,2}.\d \((.*)\)"
cvss_vector = "CVSS:3.0/"
Expand Down
6 changes: 6 additions & 0 deletions dojo/tools/whitehat_sentinel/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def _convert_whitehat_severity_id_to_dojo_severity(
Args:
whitehat_severity_id: The WhiteHat Severity ID (called risk_id in the API)
Returns: A DefectDojo severity if a mapping can be found; otherwise a null value is returned
"""
severities = [
"Informational",
Expand All @@ -84,6 +85,7 @@ def _parse_cwe_from_tags(self, whitehat_sentinel_tags) -> str:
Args:
whitehat_sentinel_tags: The Tags list from the WhiteHat vuln
Returns: The first CWE ID in the list, if it exists
"""
for tag in whitehat_sentinel_tags:
if tag.startswith("CWE-"):
Expand All @@ -97,6 +99,7 @@ def _parse_description(self, whitehat_sentinel_description: dict):
Args:
whitehat_sentinel_description: The description section of the WhiteHat Sentinel vulnerability dict
Returns: A dict with description and reference link
"""
description_ref = {"description": "", "reference_link": ""}

Expand Down Expand Up @@ -151,6 +154,7 @@ def __get_href_url(self, text_to_search):
Args:
text_to_search: The text string to search for an anchor tag
Returns:
"""
links = ""

Expand All @@ -165,6 +169,7 @@ def __remove_paragraph_tags(self, html_string):
Args:
html_string: The HMTL string to remove <p> </p> tags from
Returns: The original string stipped of paragraph tags
"""
return re.sub(r"<p>|</p>", "", html_string)

Expand Down Expand Up @@ -198,6 +203,7 @@ def _convert_whitehat_sentinel_vulns_to_dojo_finding(
whitehat_sentinel_vulns: The vuln dictionary from WhiteHat Sentinel vuln API
test: The test ID that the DefectDojo finding should be associated with
Returns: A DefectDojo Finding object
"""
dupes = {}

Expand Down
2 changes: 2 additions & 0 deletions dojo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def do_false_positive_history(finding, *args, **kwargs):
Args:
finding (:model:`dojo.Finding`): Finding to be replicated
"""
to_mark_as_fp = set()

Expand Down Expand Up @@ -150,6 +151,7 @@ def match_finding_to_existing_findings(finding, product=None, engagement=None, t
product (:model:`dojo.Product`, optional): Product to filter findings by
engagement (:model:`dojo.Engagement`, optional): Engagement to filter findings by
test (:model:`dojo.Test`, optional): Test to filter findings by
"""
if product:
custom_filter_type = "product"
Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ select = [
"W",
"C90",
"I",
"D2", "D3", "D403", "D411",
"D2", "D3", "D403", "D411", "D413",
"UP",
"YTT",
"ASYNC",
Expand Down

0 comments on commit eae8bad

Please sign in to comment.