docker-scout-graphql 0.2.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Codex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ recursive-include src *.py
5
+ recursive-include tests *.py
6
+ recursive-include scripts *.ps1
7
+ global-exclude __pycache__ *.py[cod] .DS_Store
8
+ global-exclude *.exe
9
+ prune src/docker_scout_graphql.egg-info
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: docker-scout-graphql
3
+ Version: 0.2.0
4
+ Summary: CLI for querying Docker Scout GraphQL vulnerabilities for Docker images.
5
+ Author: Codex
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://pypi.org/project/docker-scout-graphql/
8
+ Project-URL: Documentation, https://docs.docker.com/scout/
9
+ Keywords: docker,scout,security,vulnerabilities,graphql,sbom
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Security
21
+ Classifier: Topic :: System :: Systems Administration
22
+ Classifier: Topic :: Utilities
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Provides-Extra: dev
27
+ Requires-Dist: build>=1.2.2; extra == "dev"
28
+ Requires-Dist: twine>=5.1.1; extra == "dev"
29
+ Requires-Dist: pytest>=8.3.0; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # docker-scout-graphql
33
+
34
+ `docker-scout-graphql` scans Docker images by:
35
+
36
+ 1. Extracting package dependencies from `docker sbom --format syft-json`.
37
+ 2. Converting package URLs into the format expected by Docker Scout's GraphQL backend.
38
+ 3. Querying `https://api.dso.docker.com/v1/graphql`.
39
+ 4. Returning vulnerabilities separated by image layer hierarchy.
40
+
41
+ It can scan one image or all local images.
42
+
43
+ ## Install
44
+
45
+ ```powershell
46
+ pip install .
47
+ ```
48
+
49
+ For development mode:
50
+
51
+ ```powershell
52
+ pip install -e .
53
+ ```
54
+
55
+ ## Usage
56
+
57
+ Scan one image and print JSON (default):
58
+
59
+ ```powershell
60
+ docker-scout-graphql debian:12-slim
61
+ ```
62
+
63
+ Scan one image and write JSON report:
64
+
65
+ ```powershell
66
+ docker-scout-graphql debian:12-slim -o report.json
67
+ ```
68
+
69
+ Scan all local images and write JSON:
70
+
71
+ ```powershell
72
+ docker-scout-graphql --all-images -o report.json
73
+ ```
74
+
75
+ Markdown output (optional):
76
+
77
+ ```powershell
78
+ docker-scout-graphql debian:12-slim --markdown -o report.md
79
+ ```
80
+
81
+ ## Output
82
+
83
+ Default output is JSON with this top-level shape:
84
+
85
+ ```json
86
+ {
87
+ "schema_version": "1.0",
88
+ "generated_at_utc": "2026-02-27T02:17:14.428185+00:00",
89
+ "images_scanned": 1,
90
+ "images": []
91
+ }
92
+ ```
93
+
94
+ Each `images[]` entry contains:
95
+
96
+ - overall counts (`queried_packages`, `vulnerable_packages_count`, `vulnerability_count`)
97
+ - raw vulnerable package records (`packages`)
98
+ - layered hierarchy (`image_hierarchy.layers`) with vulnerable packages grouped by image layer
99
+
100
+ ## Release
101
+
102
+ For TestPyPI/PyPI publishing steps, see [PYPI_RELEASE.md](PYPI_RELEASE.md).
103
+ You can also use the helper script:
104
+
105
+ ```powershell
106
+ .\scripts\publish.ps1 -TestPyPI
107
+ .\scripts\publish.ps1
108
+ ```
@@ -0,0 +1,77 @@
1
+ # docker-scout-graphql
2
+
3
+ `docker-scout-graphql` scans Docker images by:
4
+
5
+ 1. Extracting package dependencies from `docker sbom --format syft-json`.
6
+ 2. Converting package URLs into the format expected by Docker Scout's GraphQL backend.
7
+ 3. Querying `https://api.dso.docker.com/v1/graphql`.
8
+ 4. Returning vulnerabilities separated by image layer hierarchy.
9
+
10
+ It can scan one image or all local images.
11
+
12
+ ## Install
13
+
14
+ ```powershell
15
+ pip install .
16
+ ```
17
+
18
+ For development mode:
19
+
20
+ ```powershell
21
+ pip install -e .
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ Scan one image and print JSON (default):
27
+
28
+ ```powershell
29
+ docker-scout-graphql debian:12-slim
30
+ ```
31
+
32
+ Scan one image and write JSON report:
33
+
34
+ ```powershell
35
+ docker-scout-graphql debian:12-slim -o report.json
36
+ ```
37
+
38
+ Scan all local images and write JSON:
39
+
40
+ ```powershell
41
+ docker-scout-graphql --all-images -o report.json
42
+ ```
43
+
44
+ Markdown output (optional):
45
+
46
+ ```powershell
47
+ docker-scout-graphql debian:12-slim --markdown -o report.md
48
+ ```
49
+
50
+ ## Output
51
+
52
+ Default output is JSON with this top-level shape:
53
+
54
+ ```json
55
+ {
56
+ "schema_version": "1.0",
57
+ "generated_at_utc": "2026-02-27T02:17:14.428185+00:00",
58
+ "images_scanned": 1,
59
+ "images": []
60
+ }
61
+ ```
62
+
63
+ Each `images[]` entry contains:
64
+
65
+ - overall counts (`queried_packages`, `vulnerable_packages_count`, `vulnerability_count`)
66
+ - raw vulnerable package records (`packages`)
67
+ - layered hierarchy (`image_hierarchy.layers`) with vulnerable packages grouped by image layer
68
+
69
+ ## Release
70
+
71
+ For TestPyPI/PyPI publishing steps, see [PYPI_RELEASE.md](PYPI_RELEASE.md).
72
+ You can also use the helper script:
73
+
74
+ ```powershell
75
+ .\scripts\publish.ps1 -TestPyPI
76
+ .\scripts\publish.ps1
77
+ ```
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "docker-scout-graphql"
7
+ version = "0.2.0"
8
+ description = "CLI for querying Docker Scout GraphQL vulnerabilities for Docker images."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [{ name = "Codex" }]
13
+ keywords = ["docker", "scout", "security", "vulnerabilities", "graphql", "sbom"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Environment :: Console",
17
+ "Intended Audience :: Developers",
18
+ "Intended Audience :: System Administrators",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Topic :: Security",
26
+ "Topic :: System :: Systems Administration",
27
+ "Topic :: Utilities",
28
+ ]
29
+ dependencies = []
30
+ license-files = ["LICENSE"]
31
+
32
+ [project.scripts]
33
+ docker-scout-graphql = "docker_scout_graphql.cli:main"
34
+
35
+ [project.urls]
36
+ Homepage = "https://pypi.org/project/docker-scout-graphql/"
37
+ Documentation = "https://docs.docker.com/scout/"
38
+
39
+ [project.optional-dependencies]
40
+ dev = ["build>=1.2.2", "twine>=5.1.1", "pytest>=8.3.0"]
41
+
42
+ [tool.setuptools]
43
+ package-dir = { "" = "src" }
44
+ include-package-data = false
45
+
46
+ [tool.setuptools.packages.find]
47
+ where = ["src"]
48
+
49
+ [tool.pytest.ini_options]
50
+ testpaths = ["tests"]
@@ -0,0 +1,30 @@
1
+ param(
2
+ [switch]$TestPyPI
3
+ )
4
+
5
+ if (-not $env:TWINE_USERNAME) {
6
+ $env:TWINE_USERNAME = "__token__"
7
+ }
8
+
9
+ if (-not $env:TWINE_PASSWORD) {
10
+ Write-Error "TWINE_PASSWORD is not set. Export your PyPI token first."
11
+ exit 1
12
+ }
13
+
14
+ python -m build
15
+ if ($LASTEXITCODE -ne 0) {
16
+ exit $LASTEXITCODE
17
+ }
18
+
19
+ python -m twine check dist/*
20
+ if ($LASTEXITCODE -ne 0) {
21
+ exit $LASTEXITCODE
22
+ }
23
+
24
+ if ($TestPyPI) {
25
+ python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
26
+ } else {
27
+ python -m twine upload dist/*
28
+ }
29
+
30
+ exit $LASTEXITCODE
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,19 @@
1
+ """Docker Scout GraphQL scanner package."""
2
+
3
+ from .scout import (
4
+ DockerScoutGraphQLClient,
5
+ build_json_document,
6
+ list_local_images,
7
+ scan_image,
8
+ scan_images,
9
+ )
10
+
11
+ __all__ = [
12
+ "DockerScoutGraphQLClient",
13
+ "build_json_document",
14
+ "list_local_images",
15
+ "scan_image",
16
+ "scan_images",
17
+ ]
18
+
19
+ __version__ = "0.2.0"
@@ -0,0 +1,192 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import json
5
+ import sys
6
+ from textwrap import dedent
7
+ from pathlib import Path
8
+
9
+ from .scout import (
10
+ DockerScoutGraphQLClient,
11
+ build_json_document,
12
+ list_local_images,
13
+ render_markdown_report,
14
+ scan_images,
15
+ )
16
+
17
+
18
+ def _build_parser() -> argparse.ArgumentParser:
19
+ description = (
20
+ "Scan Docker images by querying Docker Scout's GraphQL API with package URLs "
21
+ "extracted from docker sbom. Default output is JSON."
22
+ )
23
+ epilog = dedent(
24
+ """\
25
+ Quick Start:
26
+ 1) Scan a single image (JSON to stdout):
27
+ docker-scout-graphql debian:12-slim
28
+
29
+ 2) Scan a single image and write JSON file:
30
+ docker-scout-graphql debian:12-slim -o result.json
31
+
32
+ 3) Scan all local images and write markdown:
33
+ docker-scout-graphql --all-images --markdown -o report.md
34
+
35
+ 4) Scan your existing FastAPI image:
36
+ docker-scout-graphql fastapiproject-fastapi:latest -o test.json
37
+
38
+ Arguments:
39
+ image
40
+ Optional positional Docker image reference (for example: debian:12-slim).
41
+ Required unless --all-images is provided.
42
+
43
+ --all-images
44
+ Scans every image currently returned by `docker images`.
45
+ Cannot be used together with the positional `image`.
46
+
47
+ -o, --output PATH
48
+ Optional destination file path.
49
+ If omitted, output is written to stdout.
50
+
51
+ --markdown
52
+ Optional switch to output markdown instead of JSON.
53
+ JSON is the default format.
54
+
55
+ --timeout N
56
+ HTTP timeout in seconds for each GraphQL request.
57
+
58
+ --chunk-size N
59
+ Number of package URLs per GraphQL request. Larger values reduce
60
+ request count but can increase per-request latency.
61
+
62
+ --retries N
63
+ Retry count for transient GraphQL errors (429/5xx/network).
64
+
65
+ JSON Output Shape (default):
66
+ {
67
+ "schema_version": "1.0",
68
+ "generated_at_utc": "...",
69
+ "images_scanned": 1,
70
+ "images": [
71
+ {
72
+ "image": "repo:tag",
73
+ "queried_packages": 123,
74
+ "vulnerable_packages_count": 10,
75
+ "vulnerability_count": 23,
76
+ "correlation_ids": ["..."],
77
+ "packages": [
78
+ {
79
+ "purl": "pkg:...",
80
+ "package": { "name": "...", "version": "...", "type": "...", "origin": "binary|source" },
81
+ "layer_id": "sha256:...",
82
+ "vulnerabilities": [ ... ]
83
+ }
84
+ ],
85
+ "image_hierarchy": {
86
+ "type": "layered_image",
87
+ "root_layer_id": "sha256:...",
88
+ "layers": [
89
+ {
90
+ "id": "sha256:...",
91
+ "index": 0,
92
+ "parent": null,
93
+ "vulnerable_packages_count": 2,
94
+ "vulnerability_count": 5,
95
+ "packages": [ ... ]
96
+ }
97
+ ]
98
+ }
99
+ }
100
+ ]
101
+ }
102
+
103
+ Notes:
104
+ - All vulnerabilities come directly from Docker's backend GraphQL response.
105
+ - Correlation IDs are included for traceability with backend requests.
106
+ """
107
+ )
108
+ parser = argparse.ArgumentParser(
109
+ prog="docker-scout-graphql",
110
+ description=description,
111
+ epilog=epilog,
112
+ formatter_class=argparse.RawDescriptionHelpFormatter,
113
+ )
114
+ parser.add_argument(
115
+ "image",
116
+ nargs="?",
117
+ help="Docker image reference to scan (for example: debian:12-slim)",
118
+ )
119
+ parser.add_argument(
120
+ "--all-images",
121
+ action="store_true",
122
+ help="Scan every local Docker image.",
123
+ )
124
+ parser.add_argument(
125
+ "-o",
126
+ "--output",
127
+ help="Optional output file path.",
128
+ )
129
+ parser.add_argument(
130
+ "--markdown",
131
+ action="store_true",
132
+ help="Output markdown instead of JSON (JSON is the default).",
133
+ )
134
+ parser.add_argument(
135
+ "--timeout",
136
+ type=int,
137
+ default=60,
138
+ help="GraphQL request timeout in seconds (default: 60).",
139
+ )
140
+ parser.add_argument(
141
+ "--chunk-size",
142
+ type=int,
143
+ default=200,
144
+ help="Number of package URLs per GraphQL request chunk (default: 200).",
145
+ )
146
+ parser.add_argument(
147
+ "--retries",
148
+ type=int,
149
+ default=3,
150
+ help="GraphQL retries per chunk on transient failures (default: 3).",
151
+ )
152
+ return parser
153
+
154
+
155
+ def main(argv: list[str] | None = None) -> int:
156
+ parser = _build_parser()
157
+ args = parser.parse_args(argv)
158
+
159
+ if args.all_images and args.image:
160
+ parser.error("Provide either an image or --all-images, not both.")
161
+ if not args.all_images and not args.image:
162
+ parser.error("Provide an image name or use --all-images.")
163
+
164
+ images = list_local_images() if args.all_images else [args.image]
165
+ if not images:
166
+ parser.error("No local images found.")
167
+
168
+ client = DockerScoutGraphQLClient(
169
+ timeout_seconds=max(1, args.timeout),
170
+ chunk_size=max(1, args.chunk_size),
171
+ max_retries=max(0, args.retries),
172
+ )
173
+ reports = scan_images(images=images, client=client)
174
+ json_document = build_json_document(reports)
175
+
176
+ if args.markdown:
177
+ output_text = render_markdown_report(reports)
178
+ else:
179
+ output_text = json.dumps(json_document, indent=2)
180
+
181
+ if args.output:
182
+ output_path = Path(args.output)
183
+ output_path.parent.mkdir(parents=True, exist_ok=True)
184
+ output_path.write_text(output_text, encoding="utf-8")
185
+ else:
186
+ sys.stdout.write(output_text)
187
+
188
+ return 1 if any(report.get("error") for report in reports) else 0
189
+
190
+
191
+ if __name__ == "__main__":
192
+ raise SystemExit(main())