mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
> [!NOTE]
> This PR was authored by Coder Agents on behalf of @jeremyruppel.
Adds `scripts/templatebuildermodulegen/`, a Go tool that fetches module metadata from the Coder registry HTTP API and generates the `module.json` manifests and `.tf.tmpl` files used by the template builder catalog.
The generator calls `GET /api/modules/{id}` for per-module metadata (display name, description, icon, tags, variables) and the Terraform protocol versions endpoint for semver resolution. No git clone or HCL parsing required.
Split into four files:
- `main.go`: orchestration, module config map, CLI flags
- `types.go`: output types (`ModuleManifest`, `ModuleVariable`) and API response types
- `fetch.go`: HTTP fetching, version resolution, variable conversion, icon normalization
- `write.go`: JSON writer, `.tf.tmpl` Go template and writer
62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package main
|
|
|
|
import "encoding/json"
|
|
|
|
// ModuleManifest is the on-disk module.json schema.
|
|
type ModuleManifest struct {
|
|
ID string `json:"id"`
|
|
DisplayName string `json:"display_name"`
|
|
Description string `json:"description"`
|
|
Icon string `json:"icon"`
|
|
Category string `json:"category"`
|
|
Tags []string `json:"tags"`
|
|
CompatibleOS []string `json:"compatible_os"`
|
|
ConflictsWith []string `json:"conflicts_with"`
|
|
PinnedVersion string `json:"pinned_version"`
|
|
Variables []ModuleVariable `json:"variables"`
|
|
}
|
|
|
|
// ModuleVariable is a variable declaration within a module manifest.
|
|
type ModuleVariable struct {
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
Description string `json:"description"`
|
|
Default json.RawMessage `json:"default,omitempty"`
|
|
Required bool `json:"required"`
|
|
Sensitive bool `json:"sensitive"`
|
|
Computed bool `json:"computed"`
|
|
}
|
|
|
|
// registryModule is the JSON shape returned by GET /api/modules/{id}.
|
|
type registryModule struct {
|
|
ID string `json:"id"`
|
|
Slug string `json:"slug"`
|
|
DisplayName string `json:"displayName"`
|
|
Description string `json:"description"`
|
|
IconURL string `json:"iconUrl"`
|
|
Tags []string `json:"tags"`
|
|
Variables []registryVariable `json:"variables"`
|
|
Namespace string `json:"contributorNamespace"`
|
|
}
|
|
|
|
// registryVariable is a variable as returned by the registry API.
|
|
// The Default field is a raw JSON value because the API returns typed
|
|
// defaults (string, bool, number, null, array, object).
|
|
type registryVariable struct {
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
Description string `json:"description"`
|
|
Default interface{} `json:"default"`
|
|
Required bool `json:"required"`
|
|
Sensitive bool `json:"sensitive"`
|
|
}
|
|
|
|
// terraformVersionsResponse wraps the Terraform protocol versions endpoint.
|
|
type terraformVersionsResponse struct {
|
|
Modules []struct {
|
|
Versions []struct {
|
|
Version string `json:"version"`
|
|
} `json:"versions"`
|
|
} `json:"modules"`
|
|
}
|