djcheckup 0.2.3__tar.gz → 0.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: djcheckup
3
- Version: 0.2.3
3
+ Version: 0.2.5
4
4
  Summary: DJ Checkup is a security scanner for Django sites.
5
5
  Author: Stuart Maxwell
6
6
  Author-email: Stuart Maxwell <stuart@amanzi.nz>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "djcheckup"
3
- version = "0.2.3"
3
+ version = "0.2.5"
4
4
  description = "DJ Checkup is a security scanner for Django sites."
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Stuart Maxwell", email = "stuart@amanzi.nz" }]
@@ -26,14 +26,17 @@ target-version = "py313"
26
26
  [tool.ruff.lint]
27
27
  select = ["ALL"]
28
28
 
29
+ [tool.pyrefly]
30
+ project-includes = ["src/djcheckup/**"]
31
+
29
32
  [tool.ruff.lint.extend-per-file-ignores]
30
- "tests/**" = ["S101", "ANN201", "ANN001", "ARG001"]
33
+ "tests/**" = ["S101", "ANN201", "ANN001", "ARG001", "PT011", "PGH003", "SLF001"]
31
34
 
32
35
  [tool.ruff.lint.pydocstyle]
33
36
  convention = "google" # Accepts: "google", "numpy", or "pep257".
34
37
 
35
38
  [dependency-groups]
36
- dev = ["nox>=2025.5.1", "pytest>=8.4.2", "pytest-cov>=7.0.0"]
39
+ dev = ["nox>=2025.5.1", "pyrefly>=0.34.0", "pytest>=8.4.2", "pytest-cov>=7.0.0"]
37
40
 
38
41
  [tool.pytest.ini_options]
39
42
  pythonpath = "."
@@ -44,7 +47,7 @@ show_contexts = true
44
47
 
45
48
  [tool.coverage.run]
46
49
  branch = true
47
- include = ["src/djcheckup/*"]
50
+ include = ["src/djcheckup/**"]
48
51
 
49
52
  [tool.coverage.report]
50
53
  # exclude_lines = ["if TYPE_CHECKING:", "# pragma: no cover"]
@@ -1,6 +1,7 @@
1
1
  """Check types."""
2
2
 
3
3
  from abc import ABC, abstractmethod
4
+ from collections.abc import Sequence
4
5
  from dataclasses import dataclass
5
6
  from enum import Enum
6
7
  from http.cookiejar import CookieJar
@@ -389,8 +390,15 @@ class SiteChecker:
389
390
  message=success_message,
390
391
  )
391
392
 
392
- def run_checks(self, checks: list[_BaseCheck]) -> SiteCheckResult:
393
- """Run all checks."""
393
+ def run_checks(self, checks: Sequence[_BaseCheck]) -> SiteCheckResult:
394
+ """Run all checks.
395
+
396
+ Args:
397
+ checks: Accepts any sequence (list, tuple, etc.) of check instances inheriting from _BaseCheck.
398
+
399
+ Returns:
400
+ A SiteCheckResult object containing the results of all checks.
401
+ """
394
402
  # First, run the first check
395
403
  first_check = self.run_first_check()
396
404
  site_check_results = SiteCheckResult(url=str(self.url), check_results=[first_check])
@@ -22,14 +22,10 @@ def run_checks(
22
22
  ] = False,
23
23
  ) -> None:
24
24
  """Run the DJ Checkup tool against a specific URL."""
25
- checker = SiteChecker(url)
25
+ checker = SiteChecker(url=url)
26
26
  results = checker.run_checks(all_checks)
27
27
 
28
28
  if output_json:
29
29
  rich.print_json(output_results_as_json(results))
30
30
  else:
31
31
  rich_output(results)
32
-
33
-
34
- if __name__ == "__main__":
35
- app()
@@ -25,10 +25,13 @@ def rich_output(check_results: SiteCheckResult) -> None:
25
25
  emoji = ""
26
26
  if result.result == CheckResult.SUCCESS:
27
27
  emoji = "🟢 "
28
- elif result.result == CheckResult.FAILURE:
28
+
29
+ if result.result == CheckResult.FAILURE:
29
30
  emoji = "🔴 "
30
- elif result.result == CheckResult.SKIPPED:
31
+
32
+ if result.result == CheckResult.SKIPPED:
31
33
  emoji = "🟡 "
34
+
32
35
  display_result = emoji + result.result.value.capitalize()
33
36
  table.add_row(result.name, display_result, Markdown(result.message))
34
37
 
@@ -43,8 +46,9 @@ def json_encoder(obj: object) -> str | int:
43
46
  if isinstance(obj, CheckResult):
44
47
  return obj.value
45
48
 
46
- msg = f"Object of type {type(obj).__name__} is not JSON serialisable"
47
- raise TypeError(msg)
49
+ # The following should never happen since this encoder is only used for SeverityWeight and CheckResult
50
+ msg = f"Object of type {type(obj).__name__} is not JSON serialisable" # pragma: no cover
51
+ raise TypeError(msg) # pragma: no cover
48
52
 
49
53
 
50
54
  def output_results_as_json(results: SiteCheckResult) -> str:
@@ -0,0 +1,48 @@
1
+ """Run the DJ Checkup security scanner."""
2
+
3
+ from typing import Literal, overload
4
+
5
+ import httpx
6
+
7
+ from djcheckup.check_defs import all_checks
8
+ from djcheckup.checks import SiteChecker, SiteCheckResult
9
+ from djcheckup.outputs import output_results_as_json
10
+
11
+
12
+ @overload
13
+ def run_checks(
14
+ url: str,
15
+ output_format: Literal["object"] = "object",
16
+ client: httpx.Client | None = None,
17
+ ) -> SiteCheckResult: ...
18
+ @overload
19
+ def run_checks(url: str, output_format: Literal["json"], client: httpx.Client | None = None) -> str: ...
20
+
21
+
22
+ def run_checks(
23
+ url: str,
24
+ output_format: Literal["object", "json"] = "object",
25
+ client: httpx.Client | None = None,
26
+ ) -> str | SiteCheckResult:
27
+ """Run the DJ Checkup tool.
28
+
29
+ Args:
30
+ url: The URL to check.
31
+ output_format: The format of the output, either "object" or "json" (default: "object").
32
+ client: An optional HTTPX client to use for requests.
33
+
34
+ Returns:
35
+ The result of the checks, either as a JSON string or a SiteCheckResult object.
36
+ """
37
+ with SiteChecker(url, client=client) as checker:
38
+ results = checker.run_checks(all_checks)
39
+
40
+ if output_format not in {"object", "json"}:
41
+ msg = f"Invalid output_format: {output_format!r}. Must be 'object' or 'json'."
42
+ raise ValueError(msg)
43
+
44
+ if output_format == "json":
45
+ return output_results_as_json(results)
46
+
47
+ # Default to object output
48
+ return results
@@ -1,29 +0,0 @@
1
- """Run the DJ Checkup security scanner."""
2
-
3
- from typing import Literal, overload
4
-
5
- from djcheckup.check_defs import all_checks
6
- from djcheckup.checks import SiteChecker, SiteCheckResult
7
- from djcheckup.outputs import output_results_as_json
8
-
9
-
10
- @overload
11
- def run_checks(url: str, output_format: Literal["object"] = "object") -> SiteCheckResult: ...
12
- @overload
13
- def run_checks(url: str, output_format: Literal["json"]) -> str: ...
14
-
15
-
16
- def run_checks(url: str, output_format: Literal["object", "json"] = "object") -> str | SiteCheckResult:
17
- """Run the DJ Checkup tool against a specific URL and returns a JSON string."""
18
- with SiteChecker(url) as checker:
19
- results = checker.run_checks(all_checks)
20
-
21
- if output_format not in {"object", "json"}:
22
- msg = f"Invalid output_format: {output_format!r}. Must be 'object' or 'json'."
23
- raise ValueError(msg)
24
-
25
- if output_format == "json":
26
- return output_results_as_json(results)
27
-
28
- # Default to object output
29
- return str(results)
File without changes
File without changes