Skip to content

Commit

Permalink
Ruff: Add and fix N999
Browse files Browse the repository at this point in the history
  • Loading branch information
kiblik committed Jan 30, 2025
1 parent 420bf66 commit fa9c379
Show file tree
Hide file tree
Showing 31 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ integration_tests:
settings_changes:
- changed-files:
- any-glob-to-any-file:
- dojo/settings/settings.dist.py
- dojo/settings/settings_dist.py

apiv2:
- changed-files:
Expand Down
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Moderators: Labels currently accepted for PRs:
- maintenance (a.k.a chores)
- dependencies
- New Migration (when the PR introduces a DB migration)
- settings_changes (when the PR introduces changes or new settings in settings.dist.py)
- settings_changes (when the PR introduces changes or new settings in settings_dist.py)

# Contributors: Git Tips
## Rebase on dev branch
Expand Down
2 changes: 1 addition & 1 deletion .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ categories:
- title: '💣 Breaking changes'
labels:
- 'Breaking Changes'
- title: '🚩 Changes to `settings.dist.py` / `local_settings.py`'
- title: '🚩 Changes to `settings_dist.py` / `local_settings.py`'
labels:
- 'settings_changes'
- title: '🚩 Database migration'
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.django-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ RUN \
chown ${appuser} components/node_modules
USER ${uid}
ENV \
# Only variables that are not defined in settings.dist.py
# Only variables that are not defined in settings_dist.py
DD_ADMIN_USER=admin \
[email protected] \
DD_ADMIN_PASSWORD='' \
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.django-debian
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ RUN \
chown ${appuser} components/node_modules
USER ${uid}
ENV \
# Only variables that are not defined in settings.dist.py
# Only variables that are not defined in settings_dist.py
DD_ADMIN_USER=admin \
[email protected] \
DD_ADMIN_PASSWORD='' \
Expand Down
2 changes: 1 addition & 1 deletion docker/entrypoint-unit-tests-devDocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set -v
. /reach_database.sh

cd /app
# Unset the database URL so that we can force the DD_TEST_DATABASE_NAME (see django "DATABASES" configuration in settings.dist.py)
# Unset the database URL so that we can force the DD_TEST_DATABASE_NAME (see django "DATABASES" configuration in settings_dist.py)
unset DD_DATABASE_URL

# Unset the celery broker URL so that we can force the other DD_CELERY_BROKER settings
Expand Down
4 changes: 2 additions & 2 deletions docker/entrypoint-unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
. /reach_database.sh

cd /app || exit
# Unset the database URL so that we can force the DD_TEST_DATABASE_NAME (see django "DATABASES" configuration in settings.dist.py)
# Unset the database URL so that we can force the DD_TEST_DATABASE_NAME (see django "DATABASES" configuration in settings_dist.py)
unset DD_DATABASE_URL

# Unset the celery broker URL so that we can force the other DD_CELERY_BROKER settings
Expand All @@ -20,7 +20,7 @@ unset DD_CELERY_BROKER_URL
# TARGET_SETTINGS_FILE=dojo/settings/settings.py
# if [ ! -f ${TARGET_SETTINGS_FILE} ]; then
# echo "Creating settings.py"
# cp dojo/settings/settings.dist.py dojo/settings/settings.py
# cp dojo/settings/settings_dist.py dojo/settings/settings.py
# fi

wait_for_database_to_be_reachable
Expand Down
2 changes: 1 addition & 1 deletion docker/extra_settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ For an example, see [template-local_settings](../../dojo/settings/template-local
Please note this copy action could fail if you have mounted the full `dojo/` folder, but that is owned by a different user/group.
That's why this copy action only happens in docker compose release mode, and not in dev/debug/unit_tests/integration_tests modes.

For advanced usage you can also place a `settings.dist.py` or `settings.py` file. These will also be copied on startup to dojo/settings.
For advanced usage you can also place a `settings_dist.py` or `settings.py` file. These will also be copied on startup to dojo/settings.

The files in this `docker/extra_settings` folder are *not* used by the nginx container, as this container needs the settings at build time.
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ NOTE: *DD_SAML2_ATTRIBUTES_MAP* in k8s can be referenced as extraConfig (e.g. `D

NOTE: *DD_SITE_URL* might also need to be set depending on the choices you make with the metadata.xml provider. (File versus URL).

4. Checkout the SAML section in dojo/`dojo/settings/settings.dist.py` and verfiy if it fits your requirement. If you need help, take a look at the [plugin
4. Checkout the SAML section in dojo/`dojo/settings/settings_dist.py` and verfiy if it fits your requirement. If you need help, take a look at the [plugin
documentation](https://djangosaml2.readthedocs.io/contents/setup.html#configuration).

5. Restart DefectDojo, and you should now see a **Login with SAML** button (default setting of DD_SAML2_LOGIN_BUTTON_TEXT) on the login page.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/open_source/archived_docs/jira.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ This can be executed from the uwsgi docker container using:
$ docker compose exec uwsgi /bin/bash -c 'python manage.py jira_status_reconciliation'
{{< /highlight >}}

DEBUG output can be obtains via `-v 3`, but only after increasing the logging to DEBUG level in your settings.dist.py or local_settings.py file
DEBUG output can be obtains via `-v 3`, but only after increasing the logging to DEBUG level in your settings_dist.py or local_settings.py file

{{< highlight bash >}}
$ docker compose exec uwsgi /bin/bash -c 'python manage.py jira_status_reconciliation -v 3'
Expand Down
10 changes: 5 additions & 5 deletions docs/content/en/open_source/archived_docs/usage/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ Note that currently deduplication does not occur across different products.
### Deduplication algorithms

The behavior of the deduplication can be configured for each parser in
settings.dist.py (or settings.py after install) by configuring the
settings_dist.py (or settings.py after install) by configuring the
`DEDUPLICATION_ALGORITHM_PER_PARSER` variable, or via the env variable (useful for Kubernetes deployments) `DD_DEDUPLICATION_ALGORITHM_PER_PARSER` with a JSON string like
```json
{"ScannerName":"algorithm"}
```
The environment variable will override the settings in `settings.dist.py`, replacing by matching the keys.
The environment variable will override the settings in `settings_dist.py`, replacing by matching the keys.


The available algorithms are:
Expand Down Expand Up @@ -304,11 +304,11 @@ DEDUPE_ALGO_LEGACY (value for `DD_DEDUPLICATION_ALGORITHM_PER_PARSER`: `legacy`)

The hash_code computation can be configured for each parser using the
parameter `HASHCODE_FIELDS_PER_SCANNER` in
`settings.dist.py`, or via the env variable (useful for Kubernetes deployments) `DD_HASHCODE_FIELDS_PER_SCANNER` with a JSON string like
`settings_dist.py`, or via the env variable (useful for Kubernetes deployments) `DD_HASHCODE_FIELDS_PER_SCANNER` with a JSON string like
```json
{"ScannerName":["field1", "field2"]}
```
The environment variable will override the settings in `settings.dist.py`, replacing by matching the keys.
The environment variable will override the settings in `settings_dist.py`, replacing by matching the keys.

The parameter `HASHCODE_ALLOWED_FIELDS` list the fields
from finding table that were tested and are known to be working when
Expand Down Expand Up @@ -384,7 +384,7 @@ Please note the deduplication process is resource intensive and can take a long
There is a specific logger that can be activated in order to have
details about the deduplication process : switch
`dojo.specific-loggers.deduplication` to debug in
`settings.dist.py`.
`settings_dist.py`.

### Deduplication - APIv2 parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $ docker compose build --build-arg uid=1000
|`dojo/tools/<parser_dir>/parser.py` | The meat. This is where you write your actual parser. The class name must be the Python module name without underscores plus `Parser`. **Example:** When the name of the Python module is `dependency_check`, the class name shall be `DependencyCheckParser`
|`unittests/scans/<parser_dir>/{many_vulns,no_vuln,one_vuln}.json` | Sample files containing meaningful data for unit tests. The minimal set.
|`unittests/tools/test_<parser_name>_parser.py` | Unit tests of the parser.
|`dojo/settings/settings.dist.py` | If you want to use a modern hashcode based deduplication algorithm
|`dojo/settings/settings_dist.py` | If you want to use a modern hashcode based deduplication algorithm
|`doc/content/en/integrations/parsers/<file/api>/<parser_file>.md` | Documentation, what kind of file format is required and how it should be obtained

## Factory contract
Expand Down
10 changes: 5 additions & 5 deletions docs/content/en/open_source/installation/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ draft: false
weight: 3
---

## dojo/settings/settings.dist.py
## dojo/settings/settings_dist.py

The main settings are stored in [`dojo/settings/settings.dist.py`](https://github.com/DefectDojo/django-DefectDojo/blob/master/dojo/settings/settings.dist.py). It is great to use this file as a reference for what can be configured, but it shouldn\'t be edited directly, because changes will be overwritten when updating DefectDojo. There are several methods to change the default settings:
The main settings are stored in [`dojo/settings/settings_dist.py`](https://github.com/DefectDojo/django-DefectDojo/blob/master/dojo/settings/settings_dist.py). It is great to use this file as a reference for what can be configured, but it shouldn\'t be edited directly, because changes will be overwritten when updating DefectDojo. There are several methods to change the default settings:

### Environment variables

Expand All @@ -19,16 +19,16 @@ When you deploy DefectDojo in a **Kubernetes** cluster, you can set environment

### Environment file (not with Docker Compose or Kubernetes)

`settings.dist.py` reads environment variables from a file whose name is specified in the environment variable `DD_ENV_PATH`. If this variable is not set, the default `.env.prod` is used. The file must be located in the `dojo/settings` directory.
`settings_dist.py` reads environment variables from a file whose name is specified in the environment variable `DD_ENV_PATH`. If this variable is not set, the default `.env.prod` is used. The file must be located in the `dojo/settings` directory.

An example can be found in [`template_env`](https://github.com/DefectDojo/django-DefectDojo/blob/master/dojo/settings/template-env).

### local_settings.py (not with Kubernetes)

`local_settings.py` can contain more complex customizations such as adding MIDDLEWARE or INSTALLED_APP entries.
This file is processed *after* settings.dist.py is processed, so you can modify settings delivered by DefectDojo out of the box.
This file is processed *after* settings_dist.py is processed, so you can modify settings delivered by DefectDojo out of the box.
The file must be located in the `dojo/settings` directory. Environment variables in this file must not have the `DD_` prefix.
If the file is missing feel free to create it. Do not edit `settings.dist.py` directly.
If the file is missing feel free to create it. Do not edit `settings_dist.py` directly.

An example can be found in [`dojo/settings/template-local_settings`](https://github.com/DefectDojo/django-DefectDojo/blob/master/dojo/settings/template-local_settings).

Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/open_source/upgrading/1.10.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exclude_search: true
and
<https://github.com/DefectDojo/django-DefectDojo/blob/master/docker/extra_settings/README.md>
- A quickfix is to rename your own / customized
`settings.py` or `settings.dist.py` to
`settings.py` or `settings\_dist.py` to
`local\_settings.py`. Details of that PR:
<https://github.com/DefectDojo/django-DefectDojo/pull/3136>
- Major JIRA integration refactoring, for which you should at least
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/open_source/upgrading/1.7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ after CELERY\_TASK\_IGNORE\_RESULT line:

Save your modified settings file. For reference the modified file should
look like the new 1.5.0
\[settings\](<https://github.com/DefectDojo/django-DefectDojo/blob/master/dojo/settings/settings.dist.py>)
\[settings\](<https://github.com/DefectDojo/django-DefectDojo/blob/master/dojo/settings/settings_dist.py>)
file, minus the environmental configurations. As an alternative this
file can be used and the enviromental configurations from you
environment can be copied into this file.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/open_source/upgrading/2.35.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Integrity checker announced
exclude_search: true
---

From 2.35.0, DefectDojo will perform an integrity check of the `settings.dist.py` file to ensure it has not been modified. If the user changed this file (in the past or even now) the DefectDojo instance will not start until those changes have been reverted.
From 2.35.0, DefectDojo will perform an integrity check of the `settings_dist.py` file to ensure it has not been modified. If the user changed this file (in the past or even now) the DefectDojo instance will not start until those changes have been reverted.
Any customization of variables needs to be done via environmental variables or in 'local_settings.py'.
For more information check [Configuration documentation page](https://documentation.defectdojo.com/getting_started/configuration/).

Expand Down
6 changes: 3 additions & 3 deletions dojo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ def deduplication_algorithm(self):
deduplicationLogger.debug(f"using DEDUPLICATION_ALGORITHM_PER_PARSER for scan_type: {self.scan_type}")
deduplicationAlgorithm = settings.DEDUPLICATION_ALGORITHM_PER_PARSER[self.scan_type]
else:
deduplicationLogger.debug("Section DEDUPLICATION_ALGORITHM_PER_PARSER not found in settings.dist.py")
deduplicationLogger.debug("Section DEDUPLICATION_ALGORITHM_PER_PARSER not found in settings_dist.py")

deduplicationLogger.debug(f"DEDUPLICATION_ALGORITHM_PER_PARSER is: {deduplicationAlgorithm}")
return deduplicationAlgorithm
Expand All @@ -2199,7 +2199,7 @@ def hash_code_fields(self):
else:
deduplicationLogger.warning(f"test_type name {self.test_type.name} and scan_type {self.scan_type} not found in HASHCODE_FIELDS_PER_SCANNER")
else:
deduplicationLogger.debug("Section HASHCODE_FIELDS_PER_SCANNER not found in settings.dist.py")
deduplicationLogger.debug("Section HASHCODE_FIELDS_PER_SCANNER not found in settings_dist.py")

deduplicationLogger.debug(f"HASHCODE_FIELDS_PER_SCANNER is: {hashCodeFields}")
return hashCodeFields
Expand All @@ -2216,7 +2216,7 @@ def hash_code_allows_null_cwe(self):
deduplicationLogger.debug(f"using HASHCODE_ALLOWS_NULL_CWE for scan_type: {self.scan_type}")
hashCodeAllowsNullCwe = settings.HASHCODE_ALLOWS_NULL_CWE[self.scan_type]
else:
deduplicationLogger.debug("Section HASHCODE_ALLOWS_NULL_CWE not found in settings.dist.py")
deduplicationLogger.debug("Section HASHCODE_ALLOWS_NULL_CWE not found in settings_dist.py")

deduplicationLogger.debug(f"HASHCODE_ALLOWS_NULL_CWE is: {hashCodeAllowsNullCwe}")
return hashCodeAllowsNullCwe
Expand Down
2 changes: 1 addition & 1 deletion dojo/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
# how to tune the configuration to your needs.

include(
"settings.dist.py",
"settings_dist.py",
optional("local_settings.py"),
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#########################################################################################################
# It is not recommended to edit file 'settings.dist.py', for production deployments. #
# It is not recommended to edit file 'settings_dist.py', for production deployments. #
# Any customization of variables need to be done via environmental variables or in 'local_settings.py'. #
# For more information check https://documentation.defectdojo.com/getting_started/configuration/ #
#########################################################################################################
Expand Down
4 changes: 2 additions & 2 deletions dojo/settings/template-local_settings
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# local_settings.py
# this file will be included by settings.py *after* loading settings.dist.py
# this file will be included by settings.py *after* loading settings_dist.py

# this example configures the django debug toolbar and sets some loglevels to DEBUG

from django.urls import re_path
from django.conf.urls import include

# UPDATE: Adding debug_toolbar to to INSTALLED_APPS here prevents the nginx container from generating the correct static files
# So add debug_toolbar to INSTALLED_APPS in settings.dist.py and rebuild to get started with the debug_toolbar.
# So add debug_toolbar to INSTALLED_APPS in settings_dist.py and rebuild to get started with the debug_toolbar.
# Thje middleware and other config can remain in this file (local_settings.py) to avoid chance of conflicts on upgrades.
INSTALLED_APPS += (
# 'debug_toolbar',
Expand Down
2 changes: 1 addition & 1 deletion dojo/settings/unittests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# In order to run the unit tests, it is required to create a settings file
# first;
# Do so by copying the file dojo/settings/settings.dist.py to
# Do so by copying the file dojo/settings/settings_dist.py to
# dojo/settings/settings.py; Otherwise, the following import will not work
from .settings import * # noqa: F403

Expand Down
2 changes: 1 addition & 1 deletion readme-docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ DefectDojo.

0. In dev branch, the code should be python 3.11 compliant.

[dojo_settings]: /dojo/settings/settings.dist.py "DefectDojo settings file"
[dojo_settings]: /dojo/settings/settings_dist.py "DefectDojo settings file"
[pep8]: https://www.python.org/dev/peps/pep-0008/ "PEP8"
[flake8 built-in commit hooks]: https://flake8.pycqa.org/en/latest/user/using-hooks.html#built-in-hook-integration

Expand Down
4 changes: 2 additions & 2 deletions readme-docs/DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ docker exec -it django-defectdojo-uwsgi-1 ./manage.py changepassword admin
```

# Logging
For docker compose release mode the log level is INFO. In the other modes the log level is DEBUG. Logging is configured in `settings.dist.py` and can be tuned using a `local_settings.py`, see [template for local_settings.py](dojo/settings/template-local_settings). For example the deduplication logger can be set to DEBUG in a local_settings.py file:
For docker compose release mode the log level is INFO. In the other modes the log level is DEBUG. Logging is configured in `settings_dist.py` and can be tuned using a `local_settings.py`, see [template for local_settings.py](dojo/settings/template-local_settings). For example the deduplication logger can be set to DEBUG in a local_settings.py file:


```
LOGGING['loggers']['dojo.specific-loggers.deduplication']['level'] = 'DEBUG'
```

Or you can modify `settings.dist.py` directly, but this adds the risk of having conflicts when `settings.dist.py` gets updated upstream.
Or you can modify `settings_dist.py` directly, but this adds the risk of having conflicts when `settings_dist.py` gets updated upstream.

```
'dojo.specific-loggers.deduplication': {
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",
"N804", "N811", "N814", "N818",
"N804", "N811", "N814", "N818", "N999",
"D2", "D3", "D402", "D403", "D405", "D406", "D407", "D408", "D409", "D410", "D411", "D412", "D413", "D416",
"UP",
"YTT",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion unittests/scans/bandit/dd2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3530,7 +3530,7 @@
"loc": 4,
"nosec": 0
},
"dojo/settings/settings.dist.py": {
"dojo/settings/settings_dist.py": {
"CONFIDENCE.HIGH": 0.0,
"CONFIDENCE.LOW": 0.0,
"CONFIDENCE.MEDIUM": 0.0,
Expand Down
2 changes: 1 addition & 1 deletion unittests/scans/bandit/many_vulns.json
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@
"loc": 0,
"nosec": 0
},
"dojo/settings\\settings.dist.py": {
"dojo/settings\\settings_dist.py": {
"CONFIDENCE.HIGH": 0.0,
"CONFIDENCE.LOW": 0.0,
"CONFIDENCE.MEDIUM": 0.0,
Expand Down
4 changes: 2 additions & 2 deletions unittests/scans/gitlab_sast/gl-sast-report-many-vuln_v14.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@
"name": "Password in URL",
"message": "Password in URL",
"description": "Password in URL detected; please remove and revoke it if this is a leak.",
"cve": "dojo/settings/settings.dist.py:ac48da3029b35c40a4126d516386d226bbe00c27f9d6b44834458c29ef9d8779:Password in URL",
"cve": "dojo/settings/settings_dist.py:ac48da3029b35c40a4126d516386d226bbe00c27f9d6b44834458c29ef9d8779:Password in URL",
"severity": "Critical",
"confidence": "Unknown",
"scanner": {
"id": "trufflehog",
"name": "TruffleHog"
},
"location": {
"file": "dojo/settings/settings.dist.py",
"file": "dojo/settings/settings_dist.py",
"start_line": 155,
"end_line": 155,
"dependency": {
Expand Down
4 changes: 2 additions & 2 deletions unittests/scans/gitlab_sast/gl-sast-report-many-vuln_v15.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
{
"name": "Password in URL",
"description": "Password in URL detected; please remove and revoke it if this is a leak.",
"cve": "dojo/settings/settings.dist.py:ac48da3029b35c40a4126d516386d226bbe00c27f9d6b44834458c29ef9d8779:Password in URL",
"cve": "dojo/settings/settings_dist.py:ac48da3029b35c40a4126d516386d226bbe00c27f9d6b44834458c29ef9d8779:Password in URL",
"severity": "Critical",
"location": {
"file": "dojo/settings/settings.dist.py",
"file": "dojo/settings/settings_dist.py",
"start_line": 155,
"end_line": 155,
"dependency": {
Expand Down
Loading

0 comments on commit fa9c379

Please sign in to comment.