-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathprebuilds.go
More file actions
44 lines (39 loc) · 1.23 KB
/
prebuilds.go
File metadata and controls
44 lines (39 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package codersdk
import (
"context"
"encoding/json"
"net/http"
)
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, json.NewDecoder(res.Body).Decode(&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
}