Skip to content

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

Description

@spbsoluble

Summary

(*Client).GetTemplates() issues a single GET /Templates request 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 truncates the result set at 50 templates and never pages through the remainder.

Impact

Any caller that resolves a template by name against the returned list will fail to find templates that sort beyond the first 50. On instances with more than 50 templates this manifests as a spurious "template not found" error even though the template exists and is returned by GET /Templates/{id} and by GET /Templates when a sufficient ReturnLimit is supplied.

Downstream, this blocks the Terraform provider's keyfactor_template_role_binding resource (it resolves template_short_names by case-insensitive CommonName match against GetTemplates()).

Root cause

v3/api/template.goGetTemplates() builds the request with Query: nil:

keyfactorAPIStruct := &request{
    Method:   "GET",
    Endpoint: "Templates/",
    Headers:  headers,
    Query:    nil, // no PageReturned / ReturnLimit
    Payload:  nil,
}

Fix

Paginate automatically, mirroring the existing ListApplications() pattern in this library (PageReturned/ReturnLimit, accumulate pages, stop when a page returns fewer than the page size). Add a regression test that serves more than one page and asserts a late-sorting template is returned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions