Skip to content

Commit

Permalink
Ruff: Add and fix A002
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Jan 25, 2025
1 parent feabd7b commit 167a2d2
Show file tree
Hide file tree
Showing 44 changed files with 394 additions and 394 deletions.
10 changes: 5 additions & 5 deletions dojo/api_v2/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ def check_post_permission(request, post_model, post_pk, post_permission):

def check_object_permission(
request,
object,
obj,
get_permission,
put_permission,
delete_permission,
post_permission=None,
):
if request.method == "GET":
return user_has_permission(request.user, object, get_permission)
return user_has_permission(request.user, obj, get_permission)
if request.method == "PUT" or request.method == "PATCH":
return user_has_permission(request.user, object, put_permission)
return user_has_permission(request.user, obj, put_permission)
if request.method == "DELETE":
return user_has_permission(request.user, object, delete_permission)
return user_has_permission(request.user, obj, delete_permission)
if request.method == "POST":
return user_has_permission(request.user, object, post_permission)
return user_has_permission(request.user, obj, post_permission)
return False


Expand Down
2 changes: 1 addition & 1 deletion dojo/api_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2433,7 +2433,7 @@ class UserProfileView(GenericAPIView):
@action(
detail=True, methods=["get"], filter_backends=[], pagination_class=None,
)
def get(self, request, format=None):
def get(self, request, _=None):
user = get_current_user()
user_contact_info = (
user.usercontactinfo if hasattr(user, "usercontactinfo") else None
Expand Down
14 changes: 7 additions & 7 deletions dojo/benchmark/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,16 @@ def score_asvs(product, benchmark_type):


@user_is_authorized(Product, Permissions.Benchmark_Edit, "pid")
def benchmark_view(request, pid, type, cat=None):
def benchmark_view(request, pid, benchmark_type, cat=None):
product = get_object_or_404(Product, id=pid)
benchmark_type = get_object_or_404(Benchmark_Type, id=type)
benchmark_type = get_object_or_404(Benchmark_Type, id=benchmark_type)
benchmark_category = Benchmark_Category.objects.filter(
type=type, enabled=True,
type=benchmark_type, enabled=True,
).order_by("name")

# Add requirements to the product
new_benchmarks = Benchmark_Requirement.objects.filter(
category__type=type, category__type__enabled=True, enabled=True,
category__type=benchmark_type, category__type__enabled=True, enabled=True,
).exclude(
id__in=Benchmark_Product.objects.filter(product=product).values_list(
"control_id", flat=True,
Expand Down Expand Up @@ -290,10 +290,10 @@ def benchmark_view(request, pid, type, cat=None):


@user_is_authorized(Product, Permissions.Benchmark_Delete, "pid")
def delete(request, pid, type):
def delete(request, pid, benchmark_type):
product = get_object_or_404(Product, id=pid)
benchmark_product_summary = Benchmark_Product_Summary.objects.filter(
product=product, benchmark_type=type,
product=product, benchmark_type=benchmark_type,
).first()
form = DeleteBenchmarkForm(instance=benchmark_product_summary)

Expand All @@ -307,7 +307,7 @@ def delete(request, pid, type):
)
if form.is_valid():
benchmark_product = Benchmark_Product.objects.filter(
product=product, control__category__type=type,
product=product, control__category__type=benchmark_type,
)
benchmark_product.delete()
benchmark_product_summary.delete()
Expand Down
14 changes: 7 additions & 7 deletions dojo/cred/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def new_cred_finding(request, fid):


@user_is_authorized(Cred_User, Permissions.Credential_Delete, "ttid")
def delete_cred_controller(request, destination_url, id, ttid):
def delete_cred_controller(request, destination_url, elem_id, ttid):
cred = Cred_Mapping.objects.filter(pk=ttid).first()
if request.method == "POST":
tform = CredMappingForm(request.POST, instance=cred)
Expand Down Expand Up @@ -637,23 +637,23 @@ def delete_cred_controller(request, destination_url, id, ttid):

if destination_url == "cred":
return HttpResponseRedirect(reverse(destination_url))
return HttpResponseRedirect(reverse(destination_url, args=(id, )))
return HttpResponseRedirect(reverse(destination_url, args=(elem_id, )))
tform = CredMappingForm(instance=cred)

add_breadcrumb(title="Delete Credential", top_level=False, request=request)
product_tab = None
if id:
if elem_id:
product = None
if destination_url == "all_cred_product":
product = get_object_or_404(Product, id=id)
product = get_object_or_404(Product, id=elem_id)
elif destination_url == "view_engagement":
engagement = get_object_or_404(Engagement, id=id)
engagement = get_object_or_404(Engagement, id=elem_id)
product = engagement.product
elif destination_url == "view_test":
test = get_object_or_404(Test, id=id)
test = get_object_or_404(Test, id=elem_id)
product = test.engagement.product
elif destination_url == "view_finding":
finding = get_object_or_404(Finding, id=id)
finding = get_object_or_404(Finding, id=elem_id)
product = finding.test.engagement.product
product_tab = Product_Tab(product, title="Delete Credential Mapping", tab="settings")
return render(request, "dojo/delete_cred_all.html", {
Expand Down
4 changes: 2 additions & 2 deletions dojo/engagement/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,9 +1540,9 @@ def engagement_ics(request, eid):
return response


def get_list_index(list, index):
def get_list_index(full_list, index):
try:
element = list[index]
element = full_list[index]
except Exception:
element = None
return element
Expand Down
2 changes: 1 addition & 1 deletion dojo/jira_link/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def prepare_jira_issue_fields(


def add_jira_issue(obj, *args, **kwargs):
def failure_to_add_message(message: str, exception: Exception, object: Any) -> bool:
def failure_to_add_message(message: str, exception: Exception, _: Any) -> bool:
if exception:
logger.exception(exception)
logger.error(message)
Expand Down
4 changes: 2 additions & 2 deletions dojo/management/commands/test_celery_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def handle(self, *args, **options):
# the outside decorator only outside


def test2(clazz, id):
model = clazz.objects.get(id=id)
def test2(clazz, clazz_id):
model = clazz.objects.get(id=clazz_id)
logger.debug(model)


Expand Down
12 changes: 6 additions & 6 deletions dojo/notes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
logger = logging.getLogger(__name__)


def delete_note(request, id, page, objid):
note = get_object_or_404(Notes, id=id)
def delete_note(request, note_id, page, objid):
note = get_object_or_404(Notes, id=note_id)
reverse_url = None
object_id = None

Expand Down Expand Up @@ -64,8 +64,8 @@ def delete_note(request, id, page, objid):
return HttpResponseRedirect(reverse(reverse_url, args=(object_id, )))


def edit_note(request, id, page, objid):
note = get_object_or_404(Notes, id=id)
def edit_note(request, note_id, page, objid):
note = get_object_or_404(Notes, id=note_id)
reverse_url = None
object_id = None

Expand Down Expand Up @@ -142,8 +142,8 @@ def edit_note(request, id, page, objid):
})


def note_history(request, id, page, objid):
note = get_object_or_404(Notes, id=id)
def note_history(request, elem_id, page, objid):
note = get_object_or_404(Notes, id=elem_id)
reverse_url = None
object_id = None

Expand Down
4 changes: 2 additions & 2 deletions dojo/reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,9 +650,9 @@ def prefetch_related_endpoints_for_report(endpoints):
)


def get_list_index(list, index):
def get_list_index(full_list, index):
try:
element = list[index]
element = full_list[index]
except Exception:
element = None
return element
Expand Down
6 changes: 3 additions & 3 deletions dojo/settings/settings.dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,10 +901,10 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param
# https://djangosaml2.readthedocs.io/contents/setup.html#users-attributes-and-account-linking


def saml2_attrib_map_format(dict):
def saml2_attrib_map_format(din):
dout = {}
for i in dict:
dout[i] = (dict[i],)
for i in din:
dout[i] = (din[i],)
return dout


Expand Down
18 changes: 9 additions & 9 deletions dojo/templatetags/display_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,9 @@ def internet_accessible_icon(value):


@register.filter
def get_severity_count(id, table):
if table == "test":
counts = Finding.objects.filter(test=id). \
def get_severity_count(elem_id, table_type):
if table_type == "test":
counts = Finding.objects.filter(test=elem_id). \
prefetch_related("test__engagement__product").aggregate(
total=Sum(
Case(When(severity__in=("Critical", "High", "Medium", "Low"),
Expand All @@ -608,8 +608,8 @@ def get_severity_count(id, table):
then=Value(1)),
output_field=IntegerField())),
)
elif table == "engagement":
counts = Finding.objects.filter(test__engagement=id, active=True, duplicate=False). \
elif table_type == "engagement":
counts = Finding.objects.filter(test__engagement=elem_id, active=True, duplicate=False). \
prefetch_related("test__engagement__product").aggregate(
total=Sum(
Case(When(severity__in=("Critical", "High", "Medium", "Low"),
Expand All @@ -636,8 +636,8 @@ def get_severity_count(id, table):
then=Value(1)),
output_field=IntegerField())),
)
elif table == "product":
counts = Finding.objects.filter(test__engagement__product=id). \
elif table_type == "product":
counts = Finding.objects.filter(test__engagement__product=elem_id). \
prefetch_related("test__engagement__product").aggregate(
total=Sum(
Case(When(severity__in=("Critical", "High", "Medium", "Low"),
Expand Down Expand Up @@ -695,9 +695,9 @@ def get_severity_count(id, table):
"Info: " + str(info),
))

if table == "test":
if table_type == "test":
display_counts.append("Total: " + str(total) + " Findings")
elif table == "engagement" or table == "product":
elif table_type == "engagement" or table_type == "product":
display_counts.append("Total: " + str(total) + " Active Findings")

return ", ".join([str(item) for item in display_counts])
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/awssecurityhub/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_tests(self, scan_type, scan):
aws_acc.append(finding.get("AwsAccountId", "No Account Found"))
report_date = data.get("createdAt")
test = ParserTest(
name=self.ID, type=self.ID, version="",
name=self.ID, parser_type=self.ID, version="",
)
test.description = "**AWS Accounts:** " + ", ".join(set(aws_acc)) + "\n"
test.description += "**Finding Origins:** " + ", ".join(set(prod)) + "\n"
Expand Down
6 changes: 3 additions & 3 deletions dojo/tools/deepfence_threatmapper/compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def get_findings(self, row, headers, test):
test=test,
)

def compliance_severity(self, input):
if input == "pass" or input == "info":
def compliance_severity(self, severity_input):
if severity_input == "pass" or severity_input == "info":
output = "Info"
elif input == "warn":
elif severity_input == "warn":
output = "Medium"
else:
output = "Info"
Expand Down
6 changes: 3 additions & 3 deletions dojo/tools/deepfence_threatmapper/malware.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_findings(self, row, headers, test):
test=test,
)

def severity(self, input):
if input is None:
def severity(self, severity_input):
if severity_input is None:
return "Info"
return input.capitalize()
return severity_input.capitalize()
6 changes: 3 additions & 3 deletions dojo/tools/deepfence_threatmapper/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_findings(self, row, headers, test):
finding = None
return finding

def severity(self, input):
if input is None:
def severity(self, severity_input):
if severity_input is None:
return "Info"
return input.capitalize()
return severity_input.capitalize()
6 changes: 3 additions & 3 deletions dojo/tools/deepfence_threatmapper/vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_findings(self, row, headers, test):
test=test,
)

def severity(self, input):
if input is None:
def severity(self, severity_input):
if severity_input is None:
return "Info"
return input.capitalize()
return severity_input.capitalize()
6 changes: 3 additions & 3 deletions dojo/tools/generic/csv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _get_findings_csv(self, filename):
def _convert_bool(self, val):
return val.lower()[0:1] == "t" # bool False by default

def get_severity(self, input):
if input in ["Info", "Low", "Medium", "High", "Critical"]:
return input
def get_severity(self, severity_input):
if severity_input in ["Info", "Low", "Medium", "High", "Critical"]:
return severity_input
return "Info"
2 changes: 1 addition & 1 deletion dojo/tools/generic/json_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GenericJSONParser:
def _get_test_json(self, data):
test_internal = ParserTest(
name=data.get("name", self.ID),
type=data.get("type", self.ID),
parser_type=data.get("type", self.ID),
version=data.get("version"),
)
test_internal.findings = []
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/generic/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_findings(self, filename, test):
def get_tests(self, scan_type, filename):
# if the file is a CSV just use the old function
if filename.name.lower().endswith(".csv"):
test = ParserTest(name=self.ID, type=self.ID, version=None)
test = ParserTest(name=self.ID, parser_type=self.ID, version=None)
test.findings = GenericCSVParser()._get_findings_csv(filename)
return [test]
# we manage it like a JSON file (default)
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/gitlab_sast/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_tests(self, scan_type, handle):

test = ParserTest(
name=scanner_name,
type=scanner_type,
parser_type=scanner_type,
version=scanner_version,
)
test.findings = self.get_items(tree)
Expand Down
10 changes: 5 additions & 5 deletions dojo/tools/hcl_appscan/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def get_label_for_scan_types(self, scan_type):
def get_description_for_scan_types(self, scan_type):
return "Import XML output of HCL AppScan."

def xmltreehelper(self, input):
if input.text is None:
def xmltreehelper(self, xml_input):
if xml_input.text is None:
output = None
elif "\n" in input.text:
elif "\n" in xml_input.text:
output = ""
for i in input:
for i in xml_input:
output = output + " " + i.text
else:
output = " " + input.text
output = " " + xml_input.text
return output

def get_findings(self, file, test):
Expand Down
10 changes: 5 additions & 5 deletions dojo/tools/hcl_asoc_sast/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def get_label_for_scan_types(self, scan_type):
def get_description_for_scan_types(self, scan_type):
return "Import XML output of HCL AppScan on Cloud SAST"

def xmltreehelper(self, input):
if input.text is None:
def xmltreehelper(self, xml_input):
if xml_input.text is None:
output = None
elif "\n" in input.text:
elif "\n" in xml_input.text:
output = ""
for i in input:
for i in xml_input:
output = output + " " + i.text
else:
output = " " + input.text
output = " " + xml_input.text
return output

def get_findings(self, file, test):
Expand Down
2 changes: 1 addition & 1 deletion dojo/tools/horusec/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_tests(self, scan_type, scan):
data = json.load(scan)
report_date = parse(data.get("createdAt"))
test = ParserTest(
name=self.ID, type=self.ID, version=data.get("version").lstrip("v"),
name=self.ID, parser_type=self.ID, version=data.get("version").lstrip("v"),
) # remove the v in vX.Y.Z
test.description = "\n".join(
[
Expand Down
Loading

0 comments on commit 167a2d2

Please sign in to comment.