forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprebuilds.go
More file actions
91 lines (81 loc) · 2.12 KB
/
prebuilds.go
File metadata and controls
91 lines (81 loc) · 2.12 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package cli
import (
"fmt"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/cli"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/serpent"
)
func (r *RootCmd) prebuilds() *serpent.Command {
cmd := &serpent.Command{
Use: "prebuilds",
Short: "Manage Coder prebuilds",
Long: "Administrators can use these commands to manage prebuilt workspace settings.\n" + cli.FormatExamples(
cli.Example{
Description: "Pause Coder prebuilt workspace reconciliation.",
Command: "coder prebuilds pause",
},
cli.Example{
Description: "Resume Coder prebuilt workspace reconciliation if it has been paused.",
Command: "coder prebuilds resume",
},
),
Aliases: []string{"prebuild"},
Handler: func(inv *serpent.Invocation) error {
return inv.Command.HelpHandler(inv)
},
Children: []*serpent.Command{
r.pausePrebuilds(),
r.resumePrebuilds(),
},
}
return cmd
}
func (r *RootCmd) pausePrebuilds() *serpent.Command {
cmd := &serpent.Command{
Use: "pause",
Short: "Pause prebuilds",
Middleware: serpent.Chain(
serpent.RequireNArgs(0),
),
Handler: func(inv *serpent.Invocation) error {
client, err := r.InitClient(inv)
if err != nil {
return err
}
err = client.PutPrebuildsSettings(inv.Context(), codersdk.PrebuildsSettings{
ReconciliationPaused: true,
})
if err != nil {
return xerrors.Errorf("unable to pause prebuilds: %w", err)
}
_, _ = fmt.Fprintln(inv.Stderr, "Prebuilds are now paused.")
return nil
},
}
return cmd
}
func (r *RootCmd) resumePrebuilds() *serpent.Command {
cmd := &serpent.Command{
Use: "resume",
Short: "Resume prebuilds",
Middleware: serpent.Chain(
serpent.RequireNArgs(0),
),
Handler: func(inv *serpent.Invocation) error {
client, err := r.InitClient(inv)
if err != nil {
return err
}
err = client.PutPrebuildsSettings(inv.Context(), codersdk.PrebuildsSettings{
ReconciliationPaused: false,
})
if err != nil {
return xerrors.Errorf("unable to resume prebuilds: %w", err)
}
_, _ = fmt.Fprintln(inv.Stderr, "Prebuilds are now resumed.")
return nil
},
}
return cmd
}