fix(template): paginate GetTemplates to return all templates#55
Open
spbsoluble wants to merge 2 commits into
Open
fix(template): paginate GetTemplates to return all templates#55spbsoluble wants to merge 2 commits into
spbsoluble wants to merge 2 commits into
Conversation
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
This was referenced Jun 19, 2026
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
a7fb56c to
5400f36
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
(*Client).GetTemplates()issued a singleGET /Templateswith no query parameters. Command's/Templatesendpoint 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_bindingresource) fail with a spurious "template not found" on instances holding more than 50 templates — even though the template exists and is returned byGET /Templates/{id}and byGET /Templateswith a sufficientReturnLimit.Fix
Paginate automatically using
PageReturned/ReturnLimit, mirroring the existingListApplications()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