From 1175d40ce718f2bbc53393b36a1de0c5a9731ac2 Mon Sep 17 00:00:00 2001
From: Jakub Judiny <judiny@cesnet.cz>
Date: Tue, 11 Feb 2025 17:19:39 +0100
Subject: [PATCH] Refactor: formatting with trailing commas
---
Makefile | 2 +-
lib/__init__.py | 4 +++-
lib/event/history.py | 13 ++++++++++---
lib/event/rescan.py | 4 +++-
lib/event/sner.py | 11 +++++++++--
lib/playground.py | 4 +++-
lib/report/__init__.py | 6 ++++--
lib/test/test_reports.py | 6 ++++--
8 files changed, 37 insertions(+), 13 deletions(-)
diff --git a/Makefile b/Makefile
index 2b97031..96c58df 100644
--- a/Makefile
+++ b/Makefile
@@ -58,7 +58,7 @@ ruff-check-format:
. venv/bin/activate
ruff format lib --check
-ruff-autoformat:
+ruff-format:
. venv/bin/activate
ruff format lib
diff --git a/lib/__init__.py b/lib/__init__.py
index ca81f7b..22e838e 100644
--- a/lib/__init__.py
+++ b/lib/__init__.py
@@ -28,7 +28,9 @@ def get_script_argument_parser() -> ArgumentParser:
help="do not print anything but errors to the standard output",
)
parser.add_argument(
- "--debug", action="store_true", help="also log the debug outputs"
+ "--debug",
+ action="store_true",
+ help="also log the debug outputs",
)
return parser
diff --git a/lib/event/history.py b/lib/event/history.py
index ad461a8..79efd0b 100644
--- a/lib/event/history.py
+++ b/lib/event/history.py
@@ -90,12 +90,19 @@ class EventHistory:
if __name__ == "__main__":
parser = ArgumentParser()
- parser.add_argument("--print", help="print the history for the given report")
parser.add_argument(
- "--print-all", action="store_true", help="print the history for all reports"
+ "--print",
+ help="print the history for the given report",
)
parser.add_argument(
- "-d", "--delete", help="delete the history for the given report item"
+ "--print-all",
+ action="store_true",
+ help="print the history for all reports",
+ )
+ parser.add_argument(
+ "-d",
+ "--delete",
+ help="delete the history for the given report item",
)
args = parser.parse_args()
diff --git a/lib/event/rescan.py b/lib/event/rescan.py
index 2f66748..fd8a849 100644
--- a/lib/event/rescan.py
+++ b/lib/event/rescan.py
@@ -16,7 +16,9 @@ def rescan(debug: bool = False, silent: bool = False) -> None:
for filename, path in get_report_files(config.reports_dir()):
logger.info("Started rescanning for report %s.", filename)
generator = Events(
- VulnerabilityReport(path, logger=logger), logger=logger, is_rescan=True
+ VulnerabilityReport(path, logger=logger),
+ logger=logger,
+ is_rescan=True,
)
generator.send_to_warden(rescan=True)
logger.info("Rescanning completed.")
diff --git a/lib/event/sner.py b/lib/event/sner.py
index 32222a0..70193d0 100644
--- a/lib/event/sner.py
+++ b/lib/event/sner.py
@@ -28,7 +28,10 @@ class SnerSearcher:
Note: Sner's API key must be set in the config file.
"""
- headers = {"Accept": "application/json", "X-API-KEY": config.SNER_apikey()}
+ headers = {
+ "Accept": "application/json",
+ "X-API-KEY": config.SNER_apikey(),
+ }
response = post(url, headers=headers, json=post_obj, timeout=600)
if not response.ok:
# 404 is returned also when nothing is found, which is a valid
@@ -110,7 +113,11 @@ class SnerSearcher:
Calls Sner's versioninfo API for given product, OS and version specification.
The results are then filtered to get only relevant results.
"""
- post_obj = {"product": product, "versionspec": version_spec, "filter": ""}
+ post_obj = {
+ "product": product,
+ "versionspec": version_spec,
+ "filter": "",
+ }
results = []
for result in self._post(self.VERSION_INFO_URL, post_obj, []):
diff --git a/lib/playground.py b/lib/playground.py
index 8110f64..66d84c5 100644
--- a/lib/playground.py
+++ b/lib/playground.py
@@ -23,7 +23,9 @@ def try_sner_searcher():
searcher = SnerSearcher()
print(
searcher.version_search(
- product="openssh", version_spec=">=4.3,<4.3.3", os_spec="*"
+ product="openssh",
+ version_spec=">=4.3,<4.3.3",
+ os_spec="*",
)
)
diff --git a/lib/report/__init__.py b/lib/report/__init__.py
index 3d74ff0..0c6bfe4 100644
--- a/lib/report/__init__.py
+++ b/lib/report/__init__.py
@@ -183,7 +183,9 @@ class ReportItem:
return self.search_in_sner
def get_name(self) -> str:
- return capitalize_and_fix_spaces(self._get("name", required=True))
+ return capitalize_and_fix_spaces(
+ self._get("name", required=True),
+ )
def get_created(self) -> Optional[str]:
created = self.item.get("created")
@@ -227,7 +229,7 @@ class ReportItem:
def get_description(self) -> str:
return capitalize_and_fix_spaces(
- self._get_from_attrs("description", required=True)
+ self._get_from_attrs("description", required=True),
)
def get_recommendations(self) -> Optional[str]:
diff --git a/lib/test/test_reports.py b/lib/test/test_reports.py
index 5fa62c0..2e16131 100644
--- a/lib/test/test_reports.py
+++ b/lib/test/test_reports.py
@@ -115,10 +115,12 @@ class Test(unittest.TestCase):
def test_date_functions(self):
self.assertEqual(
- format_date({"day": 2, "month": 10, "year": 2023}), "2. 10. 2023"
+ format_date({"day": 2, "month": 10, "year": 2023}),
+ "2. 10. 2023",
)
self.assertEqual(
- format_date({"month": 12, "year": 1984, "day": 25}), "25. 12. 1984"
+ format_date({"month": 12, "year": 1984, "day": 25}),
+ "25. 12. 1984",
)
for input_dict in [{"month": 12, "day": 25}, {"month": 12}, None]:
with self.assertRaises(ValueError):
--
GitLab