Skip to content

fix(template): paginate GetTemplates to return all templates#55

Open
spbsoluble wants to merge 2 commits into
v3from
fix/get-templates-pagination
Open

fix(template): paginate GetTemplates to return all templates#55
spbsoluble wants to merge 2 commits into
v3from
fix/get-templates-pagination

Conversation

@spbsoluble

Copy link
Copy Markdown
Collaborator

Problem

(*Client).GetTemplates() issued a single GET /Templates with no query parameters. Command's /Templates endpoint returns a default page of 50 results (CommonName ascending) when no paging parameters are supplied, so the client silently truncated the result set at 50 and never paged through the rest.

Callers that resolve a template by name against the returned list (e.g. the Terraform provider's keyfactor_template_role_binding resource) fail with a spurious "template not found" on instances holding more than 50 templates — even though the template exists and is returned by GET /Templates/{id} and by GET /Templates with a sufficient ReturnLimit.

Fix

Paginate automatically using PageReturned/ReturnLimit, mirroring the existing ListApplications() pattern in this library: accumulate pages and stop when a page returns fewer than the page size (100). No signature change — all callers benefit transparently.

Tests

  • TestGetTemplates_Pagination — mock server serves >1 page; asserts the full set is returned and a late-sorting template (beyond page 1) is present. Fails against the pre-fix code (returns 50), passes after.
  • TestGetTemplates_SinglePage — confirms a sub-page-size result terminates the loop in one request.

Closes #54

GetTemplates() issued a single GET /Templates with no query parameters.
The Command /Templates endpoint returns a default page of 50 results
(CommonName ascending) when no paging parameters are supplied, so the
client silently truncated at 50 templates and never paged through the
remainder. Callers resolving a template by name (e.g. the Terraform
provider's template_role_binding resource) failed with a spurious
"template not found" on instances with more than 50 templates.

Paginate automatically with PageReturned/ReturnLimit, mirroring the
existing ListApplications() pattern: accumulate pages and stop when a
page returns fewer than the page size.

Adds TestGetTemplates_Pagination (serves >1 page, asserts a late-sorting
template is returned) and TestGetTemplates_SinglePage.

Fixes #54
spbsoluble added a commit to keyfactor-pub/terraform-provider-keyfactor that referenced this pull request Jun 19, 2026
Pulls in the paginated GetTemplates() fix
(Keyfactor/keyfactor-go-client#55), so keyfactor_template_role_binding
resolves templates that sort beyond the first 50 on the instance.

RC pending the final v3.5.6 release.

Refs #172

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Security/compliance audit follow-ups to the pagination change:

- Bound the loop with getTemplatesMaxPages (10000) and an explicit
  empty-page break; return an error instead of looping forever if the
  server ignores paging or always returns a full page (DoS guard).
- Close resp.Body every iteration (incl. the decode-error path) to
  avoid a per-page connection/fd leak.
- Add an [INFO] outcome log (count + pages) and [ERROR] logs on the
  request/decode failure paths for audit traceability; no response
  bodies, tokens, or template contents are logged.

Adds TestGetTemplates_MaxPagesGuard (server ignores paging -> bounded
error, not a hang).
spbsoluble added a commit to keyfactor-pub/terraform-provider-keyfactor that referenced this pull request Jun 20, 2026
…ates

The keyfactor-go-client GetTemplates() fix (Keyfactor/keyfactor-go-client#55)
makes the client paginate GET /Templates with ?PageReturned&ReturnLimit.
The VCR matcher compares the request query string exactly, so every
cassette that recorded a no-query GET /Templates had to be re-recorded:

- template_role_binding_resource{,_import}: re-recorded (+ params)
- certificate_template_data_source / resource / resource_update: re-recorded

Adds an opt-in replayable-interactions VCR variant
(newVCRProviderFactoriesReplayable) used only by the read-only
certificate-template data-source unit test. The SDK refresh cycle reads
the same template by id more times in replay than the record run
captures; consuming-mode replay (the default) then fails with
"requested interaction not found". Replayable mode stays opt-in so
stateful/polling cassettes keep consuming ordered interactions.

NOTE: requires a keyfactor-go-client release containing
Keyfactor/keyfactor-go-client#55 and a corresponding go.mod bump before
this is mergeable / CI-green.

Refs #172
spbsoluble added a commit to keyfactor-pub/terraform-provider-keyfactor that referenced this pull request Jun 20, 2026
Pulls in the paginated GetTemplates() fix
(Keyfactor/keyfactor-go-client#55), so keyfactor_template_role_binding
resolves templates that sort beyond the first 50 on the instance.

RC pending the final v3.5.6 release.

Refs #172
@spbsoluble spbsoluble force-pushed the fix/get-templates-pagination branch from a7fb56c to 5400f36 Compare June 20, 2026 00: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.

GetTemplates() only returns the first 50 templates (missing pagination)

1 participant