mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add GET /api/v2/templatebuilder/bases endpoint (#26116)
Implement `GET /api/v2/templatebuilder/bases`, which returns the list of base templates available in the template builder. Reads from the bundled catalog by cross-referencing `templatebuilder.BaseTemplateIDs()` with `examples.List()`, enriching each entry with the OS from the `exampleID -> OS` map. The endpoint is gated behind the template builder feature flag (returns 404 when disabled) and requires `policy.ActionRead` on `rbac.ResourceTemplate`. Depends on #26115 > [!NOTE] > This PR was authored by Coder Agents on behalf of @jeremyruppel.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package codersdk
|
||||
|
||||
import "encoding/json"
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// TemplateBuilderVariableType enumerates the variable types
|
||||
// supported by template builder module manifests.
|
||||
@@ -40,3 +44,33 @@ type TemplateBuilderModule struct {
|
||||
type TemplateBuilderModulesResponse struct {
|
||||
Modules []TemplateBuilderModule `json:"modules"`
|
||||
}
|
||||
|
||||
// TemplateBuilderBase is the API response type for a base template
|
||||
// returned by GET /api/v2/templatebuilder/bases.
|
||||
type TemplateBuilderBase struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Icon string `json:"icon"`
|
||||
OS string `json:"os"`
|
||||
}
|
||||
|
||||
// TemplateBuilderBasesResponse is the response body for listing template builder bases.
|
||||
type TemplateBuilderBasesResponse struct {
|
||||
Bases []TemplateBuilderBase `json:"bases"`
|
||||
}
|
||||
|
||||
// TemplateBuilderBases returns the list of base templates available
|
||||
// in the template builder.
|
||||
func (c *Client) TemplateBuilderBases(ctx context.Context) (TemplateBuilderBasesResponse, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, "/api/v2/templatebuilder/bases", nil)
|
||||
if err != nil {
|
||||
return TemplateBuilderBasesResponse{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return TemplateBuilderBasesResponse{}, ReadBodyAsError(res)
|
||||
}
|
||||
var resp TemplateBuilderBasesResponse
|
||||
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user