Skip to content

fix(api): serve every page of the OpenTofu releases in /tofu/index.json - #3968

Merged
alfespa17 merged 1 commit into
mainfrom
fix/tofu-releases-pagination
Nov 27, 2026
Merged

alfespa17 merged 1 commit into
mainfrom
fix/tofu-releases-pagination

Conversation

@Macbet

@Macbet Macbet commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Problem

/tofu/index.json proxies https://api.github.com/repos/opentofu/opentofu/releases in a single request. GitHub returns 30 releases per page by default, so the API cached and served only the newest 30, and the executor (which reads this endpoint, not GitHub) could not resolve older versions such as 1.6.0 or ~>1.8.0. Follow-up to terrakube-io/terraform-spring-boot#120 (comment).

Change

  • DownloadReleasesService.downloadAllReleases follows Link: rel="next" and returns all pages as one JSON array. The rules match terraform-spring-boot#120:
    • per_page=100 only for api.github.com and GitHub Enterprise /api/v3/, and only when not already set; mirror URLs (e.g. pre-signed S3/GCS) are requested as configured;
    • at most 20 pages, loop detection, one total deadline (the existing 60s) across pages;
    • next links are only followed on the configured URL's origin, so the GitHub token never goes to another host.
  • TofuJsonController serves and caches the combined array, without a Link header. Executors on the current library (1.9.1, without Add field job reference in history #120) read it unchanged, so no executor change is needed.
  • If a later page fails (rate limit, timeout, bad JSON, page cap), the pages read are merged with the stale cached list (fetched releases win, matched by tag_name/name without v) and cached for 1 minute instead of the configured TTL. A first-page failure keeps the existing stale/503 fallback.

Note: the full list is ~113 releases, ~8 MB of JSON (previously ~2 MB for 30), stored in the cache and stale keys.

Tests

  • DownloadReleasesServiceTest: multi-page with absolute and relative links, single-page mirror, 403 on page 2 keeps page 1, first-page failure and non-array body throw, cross-origin next link not followed (token not sent), loop, page cap, total deadline across slow pages, per_page rules, rel token parsing across Link headers.
  • IndexTests: complete list cached with the configured TTL; partial list merged with stale and cached for 1 minute.
  • DownloadReleasesServiceTest + IndexTests: 23/23 pass. Live GitHub: 113 releases over 2 pages, complete, includes v1.6.0 and v1.8.0.

GitHub pages the releases list (30 per page by default), so the proxy cached
and served only the newest 30 OpenTofu releases and the executor could not
resolve older versions such as 1.6.0 or 1.8.x.

The API now follows Link rel="next" (per_page=100 only for GitHub URLs, at
most 20 pages, one total deadline, same-origin links only so the token stays
on the configured host) and serves all releases as one JSON array. Older
executor library versions read it unchanged.

If a later page fails, the pages read are merged with the stale cached list
and cached for one minute; a first-page failure keeps the stale/503 fallback.

@alfespa17 alfespa17 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@alfespa17
alfespa17 merged commit c54a0f2 into main Nov 27, 2026
1 of 3 checks passed
@alfespa17
alfespa17 deleted the fix/tofu-releases-pagination branch November 27, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants