Skip to content

Commit

Permalink
Ruff: add preview (DefectDojo#9759)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik authored and manuel-sommer committed Mar 27, 2024
1 parent 5bd3c0d commit 99cdfb4
Show file tree
Hide file tree
Showing 36 changed files with 180 additions and 181 deletions.
2 changes: 1 addition & 1 deletion dojo/announcement/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def configure_announcement(request):

def dismiss_announcement(request):
if request.method == "POST":
deleted_count, objects_deleted = UserAnnouncement.objects.filter(
deleted_count, _objects_deleted = UserAnnouncement.objects.filter(
user=request.user, announcement=1
).delete()
if deleted_count > 0:
Expand Down
8 changes: 4 additions & 4 deletions dojo/api_v2/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ def has_permission(self, request, view):
product_name,
product_type_name,
auto_create_context,
deduplication_on_engagement,
do_not_reactivate,
_deduplication_on_engagement,
_do_not_reactivate,
) = get_import_meta_data_from_dict(request.data)
product_type = get_target_product_type_if_exists(product_type_name)
product = get_target_product_if_exists(product_name, product_type_name)
Expand Down Expand Up @@ -645,8 +645,8 @@ def has_permission(self, request, view):
product_name,
product_type_name,
auto_create_context,
deduplication_on_engagement,
do_not_reactivate,
_deduplication_on_engagement,
_do_not_reactivate,
) = get_import_meta_data_from_dict(request.data)

product_type = get_target_product_type_if_exists(product_type_name)
Expand Down
24 changes: 12 additions & 12 deletions dojo/api_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,7 @@ def save(self, push_to_jira=False):
product_type_name,
auto_create_context,
deduplication_on_engagement,
do_not_reactivate,
_do_not_reactivate,
) = get_import_meta_data_from_dict(data)
engagement = get_or_create_engagement(
engagement_id,
Expand All @@ -2264,9 +2264,9 @@ def save(self, push_to_jira=False):
try:
(
test,
finding_count,
closed_finding_count,
test_import,
_finding_count,
_closed_finding_count,
_test_import,
) = importer.import_scan(
scan,
scan_type,
Expand Down Expand Up @@ -2557,11 +2557,11 @@ def save(self, push_to_jira=False):
reimporter = ReImporter()
(
test,
finding_count,
new_finding_count,
closed_finding_count,
reactivated_finding_count,
untouched_finding_count,
_finding_count,
_new_finding_count,
_closed_finding_count,
_reactivated_finding_count,
_untouched_finding_count,
test_import,
) = reimporter.reimport_scan(
scan,
Expand Down Expand Up @@ -2608,8 +2608,8 @@ def save(self, push_to_jira=False):
importer = Importer()
(
test,
finding_count,
closed_finding_count,
_finding_count,
_closed_finding_count,
_,
) = importer.import_scan(
scan,
Expand Down Expand Up @@ -2800,7 +2800,7 @@ def save(self):
try:
(
language_type,
created,
_created,
) = Language_Type.objects.get_or_create(language=name)
except Language_Type.MultipleObjectsReturned:
language_type = Language_Type.objects.filter(
Expand Down
16 changes: 8 additions & 8 deletions dojo/api_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2605,10 +2605,10 @@ def perform_create(self, serializer):
engagement_id,
engagement_name,
product_name,
product_type_name,
auto_create_context,
deduplication_on_engagement,
do_not_reactivate,
_product_type_name,
_auto_create_context,
_deduplication_on_engagement,
_do_not_reactivate,
) = serializers.get_import_meta_data_from_dict(
serializer.validated_data
)
Expand Down Expand Up @@ -2784,10 +2784,10 @@ def perform_create(self, serializer):
_,
engagement_name,
product_name,
product_type_name,
auto_create_context,
deduplication_on_engagement,
do_not_reactivate,
_product_type_name,
_auto_create_context,
_deduplication_on_engagement,
_do_not_reactivate,
) = serializers.get_import_meta_data_from_dict(
serializer.validated_data
)
Expand Down
4 changes: 2 additions & 2 deletions dojo/endpoint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def validate_endpoints_to_add(endpoints_to_add):
def save_endpoints_to_add(endpoint_list, product):
processed_endpoints = []
for e in endpoint_list:
endpoint, created = endpoint_get_or_create(
endpoint, _created = endpoint_get_or_create(
protocol=e[0],
userinfo=e[1],
host=e[2],
Expand Down Expand Up @@ -347,7 +347,7 @@ def endpoint_meta_import(file, product, create_endpoints, create_tags, create_me
if item[1] is not None and len(item[1]) > 0:
if create_meta:
# check if meta exists first. Don't want to make duplicate endpoints
dojo_meta, create = DojoMeta.objects.get_or_create(
dojo_meta, _create = DojoMeta.objects.get_or_create(
endpoint=endpoint,
name=item[0])
dojo_meta.value = item[1]
Expand Down
2 changes: 1 addition & 1 deletion dojo/engagement/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ def download_risk_acceptance(request, eid, raid):
open(settings.MEDIA_ROOT + "/" + risk_acceptance.path.name, mode='rb')))
response['Content-Disposition'] = 'attachment; filename="%s"' \
% risk_acceptance.filename()
mimetype, encoding = mimetypes.guess_type(risk_acceptance.path.name)
mimetype, _encoding = mimetypes.guess_type(risk_acceptance.path.name)
response['Content-Type'] = mimetype
return response

Expand Down
2 changes: 1 addition & 1 deletion dojo/finding/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def add_endpoints(new_finding, form):
new_finding.endpoints.set(form.cleaned_data['endpoints'] | Endpoint.objects.filter(id__in=endpoint_ids))

for endpoint in new_finding.endpoints.all():
eps, created = Endpoint_Status.objects.get_or_create(
_eps, _created = Endpoint_Status.objects.get_or_create(
finding=new_finding,
endpoint=endpoint, defaults={'date': form.cleaned_data['date'] or timezone.now()})

Expand Down
8 changes: 4 additions & 4 deletions dojo/finding/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2277,7 +2277,7 @@ def apply_cwe_mitigation(apply_to_findings, template, update=True):
"CWE remediation text applied to finding for CWE: %s using template: %s."
% (template.cwe, template.title)
)
new_note.author, created = User.objects.get_or_create(
new_note.author, _created = User.objects.get_or_create(
username="System"
)
new_note.save()
Expand Down Expand Up @@ -2477,7 +2477,7 @@ class Original(ImageSpec):
image = size_map[size](source=file).generate()
response = StreamingHttpResponse(FileIterWrapper(image))
response["Content-Disposition"] = "inline"
mimetype, encoding = mimetypes.guess_type(file_name)
mimetype, _encoding = mimetypes.guess_type(file_name)
response["Content-Type"] = mimetype
return response

Expand Down Expand Up @@ -3019,7 +3019,7 @@ def finding_bulk_update_all(request, pid=None):
(
can_be_pushed_to_jira,
error_message,
error_code,
_error_code,
) = jira_helper.can_be_pushed_to_jira(group)
if not can_be_pushed_to_jira:
error_counts[error_message] += 1
Expand Down Expand Up @@ -3071,7 +3071,7 @@ def finding_bulk_update_all(request, pid=None):
(
can_be_pushed_to_jira,
error_message,
error_code,
_error_code,
) = jira_helper.can_be_pushed_to_jira(finding)
if finding.has_jira_group_issue and not finding.has_jira_issue:
error_message = (
Expand Down
2 changes: 1 addition & 1 deletion dojo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ def __init__(self, *args, **kwargs):
def save(self):
processed_endpoints = []
for e in self.endpoints_to_process:
endpoint, created = endpoint_get_or_create(
endpoint, _created = endpoint_get_or_create(
protocol=e[0],
userinfo=e[1],
host=e[2],
Expand Down
2 changes: 1 addition & 1 deletion dojo/importers/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def process_parsed_findings(self, test, parsed_findings, scan_type, user, active
for unsaved_file in item.unsaved_files:
data = base64.b64decode(unsaved_file.get('data'))
title = unsaved_file.get('title', '<No title>')
file_upload, file_upload_created = FileUpload.objects.get_or_create(
file_upload, _file_upload_created = FileUpload.objects.get_or_create(
title=title,
)
file_upload.file.save(title, ContentFile(data))
Expand Down
2 changes: 1 addition & 1 deletion dojo/importers/reimporter/reimporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def process_parsed_findings(
title = unsaved_file.get("title", "<No title>")
(
file_upload,
file_upload_created,
_file_upload_created,
) = FileUpload.objects.get_or_create(
title=title,
)
Expand Down
4 changes: 2 additions & 2 deletions dojo/importers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def add_endpoints_to_unsaved_finding(finding, test, endpoints, **kwargs):
"{}".format(e))
ep = None
try:
ep, created = endpoint_get_or_create(
ep, _created = endpoint_get_or_create(
protocol=endpoint.protocol,
userinfo=endpoint.userinfo,
host=endpoint.host,
Expand All @@ -158,7 +158,7 @@ def add_endpoints_to_unsaved_finding(finding, test, endpoints, **kwargs):
raise Exception("Endpoints in your database are broken. Please access {} and migrate them to new format or "
"remove them.".format(reverse('endpoint_migrate')))

eps, created = Endpoint_Status.objects.get_or_create(
_eps, _created = Endpoint_Status.objects.get_or_create(
finding=finding,
endpoint=ep,
defaults={'date': finding.date})
Expand Down
4 changes: 2 additions & 2 deletions dojo/jira_link/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def failure_to_add_message(message: str, exception: Exception, object: Any) -> b
jira_project = get_jira_project(obj)
jira_instance = get_jira_instance(obj)

obj_can_be_pushed_to_jira, error_message, error_code = can_be_pushed_to_jira(obj)
obj_can_be_pushed_to_jira, error_message, _error_code = can_be_pushed_to_jira(obj)
if not obj_can_be_pushed_to_jira:
if isinstance(obj, Finding) and obj.duplicate and not obj.active:
logger.warning("%s will not be pushed to JIRA as it's a duplicate finding", to_str_typed(obj))
Expand Down Expand Up @@ -1596,7 +1596,7 @@ def process_resolution_from_jira(finding, resolution_id, resolution_name, assign
finding.active = False
finding.mitigated = jira_now
finding.is_mitigated = True
finding.mitigated_by, created = User.objects.get_or_create(username='JIRA')
finding.mitigated_by, _created = User.objects.get_or_create(username='JIRA')
finding.endpoints.clear()
finding.false_p = False
ra_helper.risk_unaccept(finding)
Expand Down
2 changes: 1 addition & 1 deletion dojo/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def post(self, request: HttpRequest):
# Set up the initial context
context = self.get_initial_context(request, notifications, self.get_scope())
# Determine the validity of the form
request, success = self.process_form(request, context)
request, _success = self.process_form(request, context)
# Add any breadcrumbs
request = self.set_breadcrumbs(request)
# Render the page
Expand Down
2 changes: 1 addition & 1 deletion dojo/okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def validate_and_return_id_token(self, id_token, access_token):
"""
Validates the id_token using Okta.
"""
client_id, client_secret = self.get_key_and_secret()
client_id, _client_secret = self.get_key_and_secret()
claims = None
k = None

Expand Down
6 changes: 3 additions & 3 deletions dojo/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def assign_user_to_groups(user, group_names, social_provider):
group, created_group = Dojo_Group.objects.get_or_create(name=group_name, social_provider=social_provider)
if created_group:
logger.debug("Group %s for social provider %s was created", str(group), social_provider)
group_member, is_member_created = Dojo_Group_Member.objects.get_or_create(group=group, user=user, defaults={
_group_member, is_member_created = Dojo_Group_Member.objects.get_or_create(group=group, user=user, defaults={
'role': Role.objects.get(id=Roles.Maintainer)})
if is_member_created:
logger.debug("User %s become member of group %s (social provider: %s)", user, str(group), social_provider)
Expand All @@ -142,7 +142,7 @@ def update_product_access(backend, uid, user=None, social=None, *args, **kwargs)
projects = gl.projects.list(membership=True, min_access_level=settings.GITLAB_PROJECT_MIN_ACCESS_LEVEL, all=True)
project_names = [project.path_with_namespace for project in projects]
# Create product_type if necessary
product_type, created = Product_Type.objects.get_or_create(name='Gitlab Import')
product_type, _created = Product_Type.objects.get_or_create(name='Gitlab Import')
# For each project: create a new product or update product's authorized_users
for project in projects:
if project.path_with_namespace not in user_product_names:
Expand All @@ -153,7 +153,7 @@ def update_product_access(backend, uid, user=None, social=None, *args, **kwargs)
# If not, create a product with that name and the GitLab product type
product = Product(name=project.path_with_namespace, prod_type=product_type)
product.save()
product_member, created = Product_Member.objects.get_or_create(product=product, user=user, defaults={'role': Role.objects.get(id=Roles.Owner)})
_product_member, _created = Product_Member.objects.get_or_create(product=product, user=user, defaults={'role': Role.objects.get(id=Roles.Owner)})
# Import tags and/orl URL if necessary
if settings.GITLAB_PROJECT_IMPORT_TAGS:
if hasattr(project, 'topics'):
Expand Down
4 changes: 2 additions & 2 deletions dojo/product/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def view_product(request, pid):
sla = SLA_Configuration.objects.filter(id=prod.sla_configuration_id).first()
benchAndPercent = []
for i in range(0, len(benchmarks)):
desired_level, total, total_pass, total_wait, total_fail, total_viewed = asvs_calc_level(benchmarks[i])
desired_level, total, total_pass, total_wait, total_fail, _total_viewed = asvs_calc_level(benchmarks[i])

success_percent = round((float(total_pass) / float(total)) * 100, 2)
waiting_percent = round((float(total_wait) / float(total)) * 100, 2)
Expand Down Expand Up @@ -1166,7 +1166,7 @@ def get_product(self, product_id: int):
return get_object_or_404(Product, id=product_id)

def get_test_type(self):
test_type, nil = Test_Type.objects.get_or_create(name=_("Pen Test"))
test_type, _nil = Test_Type.objects.get_or_create(name=_("Pen Test"))
return test_type

def get_engagement(self, product: Product):
Expand Down
4 changes: 2 additions & 2 deletions dojo/reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def add_extra_values(self):
pass

def get(self, request):
findings, obj = get_findings(request)
findings, _obj = get_findings(request)
self.findings = findings
findings = self.add_findings_data()
response = HttpResponse(content_type='text/csv')
Expand Down Expand Up @@ -958,7 +958,7 @@ def add_extra_values(self):
pass

def get(self, request):
findings, obj = get_findings(request)
findings, _obj = get_findings(request)
self.findings = findings
findings = self.add_findings_data()
workbook = Workbook()
Expand Down
2 changes: 1 addition & 1 deletion dojo/templatetags/display_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def asvs_calc_level(benchmark_score):

@register.filter
def asvs_level(benchmark_score):
benchmark_score.desired_level, total, total_pass, total_wait, total_fail, total_viewed = asvs_calc_level(benchmark_score)
benchmark_score.desired_level, total, _total_pass, _total_wait, _total_fail, total_viewed = asvs_calc_level(benchmark_score)

level = percentage(total_viewed, total)

Expand Down
2 changes: 1 addition & 1 deletion dojo/test/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ def re_import_scan_results(request, tid):
finding_count, new_finding_count, closed_finding_count, reactivated_finding_count, untouched_finding_count = 0, 0, 0, 0, 0
reimporter = ReImporter()
try:
test, finding_count, new_finding_count, closed_finding_count, reactivated_finding_count, untouched_finding_count, test_import = \
test, finding_count, new_finding_count, closed_finding_count, reactivated_finding_count, untouched_finding_count, _test_import = \
reimporter.reimport_scan(scan, scan_type, test, active=active, verified=verified,
tags=tags, minimum_severity=minimum_severity,
endpoints_to_add=endpoints_to_add, scan_date=scan_date,
Expand Down
4 changes: 2 additions & 2 deletions dojo/tools/api_vulners/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class VulnersImporter(object):
"""

def get_findings(self, test):
client, config = self.prepare_client(test)
client, _config = self.prepare_client(test)
findings = client.get_findings()
return findings

def get_vulns_description(self, test, vulns_id):
client, config = self.prepare_client(test)
client, _config = self.prepare_client(test)
description = client.get_vulns_description(vulns_id)
return description

Expand Down
4 changes: 2 additions & 2 deletions dojo/tools/checkmarx/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _get_findings_xml(self, filename, test):
# - value: a list of vuln_id_from_tool
vuln_ids_from_tool = dict()
for query in root.findall("Query"):
name, cwe, categories, queryId = self.getQueryElements(query)
_name, _cwe, categories, _queryId = self.getQueryElements(query)
language = ""
findingdetail = ""
group = ""
Expand Down Expand Up @@ -142,7 +142,7 @@ def _process_result_file_name_aggregated(
Create the finding and add it into the dupes list
If a vuln with the same file_path was found before, updates the description
"""
name, cwe, categories, queryId = self.getQueryElements(query)
_name, cwe, _categories, queryId = self.getQueryElements(query)
titleStart = query.get("name").replace("_", " ")
description, lastPathnode = self.get_description_file_name_aggregated(
query, result
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/kics/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_findings(self, filename, test):
expected_value = item.get("expected_value")
actual_value = item.get("actual_value")

description = f"{query.get('description','')}\n"
description = f"{query.get('description', '')}\n"
if platform:
description += f"**Platform:** {platform}\n"
if category:
Expand Down
Loading

0 comments on commit 99cdfb4

Please sign in to comment.