Files
coder/codersdk/prebuilds.go
T
dylanhuff-at-coder 76ae64391a refactor(codersdk): use ReadBodyAsJSON in typed endpoints (#27857)
This PR migrates 224 typed JSON response sites across 46 files to
`codersdk.ReadBodyAsJSON`, so invalid 2xx bodies return structured
errors while preserving URL credential redaction.

It intentionally excludes agent-direct HTTP, Azure IMDS, `UseNumber`,
and chat paths; stacked on coder/coder#27804, with chat and lint
follow-ups in coder/coder#27858 and coder/coder#27859. Refs
coder/coder#27044.

Reviewed and updated by Coder Agents on behalf of @dylanhuff-at-coder.
2026-08-05 13:22:23 -07:00

51 lines
1.6 KiB
Go

package codersdk
import (
"context"
"net/http"
)
// PrebuildsSystemUserID is the UUID of the Coder prebuilds system
// user. Prebuilt workspaces are owned by this user until they are
// claimed; build #1 of a claimed workspace remains attributed to
// this user as the initiator forever, which is how callers can
// recognize a prebuild claim after the fact.
const PrebuildsSystemUserID = "c42fdf75-3097-471c-8c33-fb52454d81c0"
type PrebuildsSettings struct {
ReconciliationPaused bool `json:"reconciliation_paused"`
}
// GetPrebuildsSettings retrieves the prebuilds settings, which currently just describes whether all
// prebuild reconciliation is paused.
func (c *Client) GetPrebuildsSettings(ctx context.Context) (PrebuildsSettings, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/prebuilds/settings", nil)
if err != nil {
return PrebuildsSettings{}, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return PrebuildsSettings{}, ReadBodyAsError(res)
}
var settings PrebuildsSettings
return settings, ReadBodyAsJSON(res, &settings)
}
// PutPrebuildsSettings modifies the prebuilds settings, which currently just controls whether all
// prebuild reconciliation is paused.
func (c *Client) PutPrebuildsSettings(ctx context.Context, settings PrebuildsSettings) error {
res, err := c.Request(ctx, http.MethodPut, "/api/v2/prebuilds/settings", settings)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode == http.StatusNotModified {
return nil
}
if res.StatusCode != http.StatusOK {
return ReadBodyAsError(res)
}
return nil
}