Skip to content

feat(downloader): add TUFPointerDownloader for v2 pointer-file format#23144

Open
dkirov-dd wants to merge 2 commits intomasterfrom
dk/downloader-v2-pointer-format
Open

feat(downloader): add TUFPointerDownloader for v2 pointer-file format#23144
dkirov-dd wants to merge 2 commits intomasterfrom
dk/downloader-v2-pointer-format

Conversation

@dkirov-dd
Copy link
Copy Markdown
Contributor

Summary

Adds support for the new agent-integrations-tuf release pipeline, which stores TUF targets as JSON pointer files rather than the old HTML simple index + in-toto layout.

  • download_v2.py — new TUFPointerDownloader class: TUF-verifies a pointer file at targets/<project>/<version>.json (or latest.json), then downloads and sha256-verifies the wheel from S3. Accepts an optional trust_anchor root.json path; falls back to TOFU when omitted (safe in controlled CI environments). disable_verification skips both TUF and digest checks.
  • exceptions.py — adds DigestMismatch(project, expected, actual) for sha256/length failures.
  • cli.py — adds --format v2 flag that routes through TUFPointerDownloader. --unsafe-disable-verification is fully supported. --type and --ignore-python-version are not applicable in v2 (warn and ignore) — wheel selection happens at publish time, not download time.
  • tests/test_v2_downloader.py — 8 offline unit tests (all mocked, no network): happy path, latest.json resolution, TargetNotFoundError, digest mismatch, length mismatch, and disable_verification mode.

Usage

python -m datadog_checks.downloader \
  --format v2 \
  --repository https://agent-integration-wheels-staging.s3.amazonaws.com \
  --root-json /path/to/metadata/root.json \
  datadog-postgres --version 14.0.0

Test plan

  • 8 offline unit tests pass (pytest tests/test_v2_downloader.py -m offline)
  • Manual end-to-end test against staging S3 once agent-integrations-tuf pipeline is live

The new agent-integrations-tuf pipeline produces TUF targets as JSON
pointer files (targets/<project>/<version>.json) rather than the old
HTML simple index + in-toto approach. This commit adds:

- TUFPointerDownloader in download_v2.py: TUF-verifies the pointer
  file, then fetches and sha256-verifies the wheel from S3.
- DigestMismatch exception for sha256/length failures.
- --format v2 CLI flag: routes through TUFPointerDownloader.
  --unsafe-disable-verification carries forward; --type and
  --ignore-python-version are no-ops in v2 with a warning.
- 8 offline unit tests covering happy path, missing target, digest
  mismatch, length mismatch, and disable_verification mode.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3251675bc1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

def __init__(
self,
repository_url: str,
trust_anchor: Path | None = None,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use Python 3.8-safe annotation syntax

This introduces Path | None annotations, which are only valid syntax on Python 3.10+. The package still declares requires-python = ">=3.8" in datadog_checks_downloader/pyproject.toml, so importing this module on 3.8/3.9 raises a SyntaxError before runtime. Because cli.py imports download_v2 at module load, this can break all downloader invocations (including v1 mode) in those environments.

Useful? React with 👍 / 👎.

…baked value

The pointer file always contains the prod S3 repository URL. When
validating staging, the caller passes --repository <staging-url> to
point at the staging bucket; that URL should be used for both the TUF
metadata fetch AND the wheel download, not just the metadata.

Adds a test that asserts the wheel is fetched from the caller-supplied
URL even when the pointer contains a different (prod) repository value.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant