-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsandbox_types.go
More file actions
341 lines (300 loc) · 13.5 KB
/
Copy pathsandbox_types.go
File metadata and controls
341 lines (300 loc) · 13.5 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
package api
import "time"
// ── Sandbox wire types ────────────────────────────────────────────
//
// Mirrors fc-spawn's user-facing API. Field names match the JSON the
// server emits so we round-trip cleanly through Resty's SetResult.
// Pointer types are used for fields that may be null (optional name,
// optional ssh keys, etc.).
// SandboxCreateReq is the body of POST /v1/sandboxes.
// `host_id` is deliberately absent — pinning was removed from the API.
type SandboxCreateReq struct {
Name string `json:"name,omitempty"`
Shape string `json:"shape"`
Rootfs string `json:"rootfs,omitempty"`
DiskMib int64 `json:"disk_mib,omitempty"`
SSHPubkeys []string `json:"ssh_pubkeys,omitempty"`
Egress []string `json:"egress,omitempty"`
Envs map[string]string `json:"envs,omitempty"`
IngressEnabled bool `json:"ingress_enabled,omitempty"`
Networks []SandboxNetworkAttach `json:"networks,omitempty"`
Disks []SandboxDiskAttach `json:"disks,omitempty"`
AutoPauseAfterSeconds *int `json:"auto_pause_after_seconds,omitempty"`
}
// SandboxPatchReq is the body of PATCH /v1/sandboxes/:id.
// Only non-nil / non-zero fields are sent; omitempty keeps unset ones out of the wire.
type SandboxPatchReq struct {
IngressEnabled *bool `json:"ingress_enabled,omitempty"`
AutoPauseAfterSeconds *int `json:"auto_pause_after_seconds,omitempty"`
DisableAutoPause bool `json:"disable_auto_pause,omitempty"`
}
// SandboxNetworkAttach binds a sandbox to a private network at create time.
type SandboxNetworkAttach struct {
ID string `json:"id"`
}
// SandboxDiskAttach mounts an S3 disk at create time.
type SandboxDiskAttach struct {
DiskID string `json:"disk_id"`
MountPath string `json:"mount_path"`
}
// SandboxExecReq is the body of POST /v1/sandboxes/:id/exec.
type SandboxExecReq struct {
Cmd string `json:"cmd"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
Stdin string `json:"stdin,omitempty"`
Stream bool `json:"stream,omitempty"`
}
// SandboxExecResult is the inner ExecResponse the agent returns.
type SandboxExecResult struct {
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
ExitCode int `json:"exit_code"`
Error string `json:"error,omitempty"`
}
// SandboxExecResp is the buffered (non-streaming) response shape.
type SandboxExecResp struct {
Result SandboxExecResult `json:"result"`
ExecMs float64 `json:"exec_ms,omitempty"`
}
// SandboxExecStreamEvent is one NDJSON frame from the streaming endpoint.
// Exactly one of (Stdout, Stderr, ExitCode, Error) is meaningful per
// event; HB heartbeats arrive every ~5 s on silent commands.
type SandboxExecStreamEvent struct {
Stdout string `json:"stdout,omitempty"`
Stderr string `json:"stderr,omitempty"`
ExitCode *int `json:"exit_code,omitempty"`
Error string `json:"error,omitempty"`
HB bool `json:"hb,omitempty"`
}
// SandboxForkReq is the body of POST /v1/sandboxes/:src/fork. All
// fields are optional overrides; omit any to inherit from the source
// sandbox's snapshot.
type SandboxForkReq struct {
SSHPubkeys []string `json:"ssh_pubkeys,omitempty"`
Egress []string `json:"egress,omitempty"`
IngressEnabled *bool `json:"ingress_enabled,omitempty"`
Envs map[string]string `json:"envs,omitempty"`
// StartPaused = true leaves the fork in the `paused` state; otherwise
// the server auto-resumes it after fork.
StartPaused bool `json:"start_paused,omitempty"`
}
// SandboxCreateResp is the response body for POST /v1/sandboxes.
// `mode` is deliberately absent — it's an internal boot-path detail.
type SandboxCreateResp struct {
ID string `json:"id"`
Name *string `json:"name,omitempty"`
IP string `json:"ip"`
Shape string `json:"shape"`
Rootfs *string `json:"rootfs,omitempty"`
VCPU int `json:"vcpu"`
MemMib int `json:"mem_mib"`
DiskMib int64 `json:"disk_mib"`
SpawnMs float64 `json:"spawn_ms,omitempty"`
Egress []string `json:"egress,omitempty"`
BandwidthQuotaBytes int64 `json:"bandwidth_quota_bytes,omitempty"`
IngressURLTemplate string `json:"ingress_url_template,omitempty"`
AutoPauseAfterSeconds *int `json:"auto_pause_after_seconds,omitempty"`
}
// SandboxView is the projection returned by GET /v1/sandboxes and
// GET /v1/sandboxes/:id. The shape matches fc-spawn's SandboxView.
type SandboxView struct {
ID string `json:"id"`
Name *string `json:"name,omitempty"`
Status string `json:"status"`
IP *string `json:"ip,omitempty"`
VCPU int `json:"vcpu"`
MemMib int `json:"mem_mib"`
DiskMib int64 `json:"disk_mib"`
CreatedAt time.Time `json:"created_at"`
RunningAt *time.Time `json:"running_at,omitempty"`
DestroyedAt *time.Time `json:"destroyed_at,omitempty"`
SpawnMs float64 `json:"spawn_ms,omitempty"`
Shape string `json:"shape,omitempty"`
Rootfs *string `json:"rootfs,omitempty"`
Egress []string `json:"egress,omitempty"`
SSHPubkeys []string `json:"ssh_pubkeys,omitempty"`
CreatedBy string `json:"created_by,omitempty"`
Region string `json:"region"`
IngressEnabled bool `json:"ingress_enabled"`
IngressURLTemplate string `json:"ingress_url_template,omitempty"`
BandwidthIngressBytes int64 `json:"bandwidth_ingress_bytes,omitempty"`
Envs []string `json:"envs,omitempty"`
PausedAt *time.Time `json:"paused_at,omitempty"`
LastResumedAt *time.Time `json:"last_resumed_at,omitempty"`
ForkedFrom *string `json:"forked_from,omitempty"`
AutoPauseAfterSeconds *int `json:"auto_pause_after_seconds,omitempty"`
}
// ── List shape ────────────────────────────────────────────────────
//
// fc-spawn paginated lists wrap items under data.data[] with a
// pagination block. Matches the createos PaginatedResponse[T] shape.
// SandboxList is the inner shape under data for GET /v1/sandboxes.
type SandboxList struct {
Data []SandboxView `json:"data"`
Pagination Pagination `json:"pagination"`
}
// ── Catalog ───────────────────────────────────────────────────────
// Shape describes one row of GET /v1/shapes.
type Shape struct {
ID string `json:"id"`
VCPU int `json:"vcpu"`
MemMib int `json:"mem_mib"`
DefaultDiskMib int64 `json:"default_disk_mib"`
}
// ShapeList is the inner shape under data for GET /v1/shapes.
type ShapeList struct {
Data []Shape `json:"data"`
Pagination Pagination `json:"pagination"`
}
// RootfsEntry describes one row of GET /v1/rootfs.
type RootfsEntry struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Successor string `json:"successor,omitempty"`
}
// RootfsCatalog is the response shape of GET /v1/rootfs. The endpoint
// is single-item (not paginated) because it carries both the list and
// the default in one object.
type RootfsCatalog struct {
Rootfs []string `json:"rootfs"`
Default string `json:"default"`
Entries []RootfsEntry `json:"entries"`
}
// ── Disks ─────────────────────────────────────────────────────────
// DiskCreateReq is the body of POST /v1/disks.
type DiskCreateReq struct {
Name string `json:"name"`
Kind string `json:"kind"` // "s3" today
Config DiskConfig `json:"config"`
Credentials DiskCredentials `json:"credentials"`
}
// DiskConfig is the non-secret S3 endpoint description.
type DiskConfig struct {
Bucket string `json:"bucket"`
Endpoint string `json:"endpoint"`
Region string `json:"region,omitempty"`
UsePathStyle bool `json:"use_path_style,omitempty"`
}
// DiskCredentials is the bucket creds. AES-encrypted at rest by the
// control plane; never returned in any GET response.
type DiskCredentials struct {
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`
}
// DiskView is the user-facing projection returned by all read endpoints.
type DiskView struct {
ID string `json:"id"`
Name string `json:"name"`
Kind string `json:"kind"`
Config DiskConfig `json:"config"`
CreatedAt time.Time `json:"created_at"`
}
// DiskList is the paginated list shape.
type DiskList struct {
Data []DiskView `json:"data"`
Pagination Pagination `json:"pagination"`
}
// SandboxDiskView is one attachment of a disk to a running sandbox,
// shape of GET /v1/sandboxes/:id/disks rows.
type SandboxDiskView struct {
DiskID string `json:"disk_id"`
Name string `json:"name"`
Kind string `json:"kind"`
Config DiskConfig `json:"config"`
MountPath string `json:"mount_path"`
SubPath string `json:"sub_path,omitempty"`
MountStatus string `json:"mount_status"`
MountError string `json:"mount_error,omitempty"`
}
// SandboxDiskList is the paginated list shape under data.
type SandboxDiskList struct {
Data []SandboxDiskView `json:"data"`
Pagination Pagination `json:"pagination"`
}
// DiskAttachReq is the body of POST /v1/sandboxes/:id/disks.
type DiskAttachReq struct {
DiskID string `json:"disk_id"`
MountPath string `json:"mount_path"`
SubPath string `json:"sub_path,omitempty"`
}
// SandboxNetwork describes one row of GET /v1/networks. Members is
// populated only by the per-id GET, not by the list endpoint.
type SandboxNetwork struct {
ID string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
MemberCount int `json:"member_count,omitempty"`
Members []SandboxNetworkMember `json:"members,omitempty"`
}
// SandboxNetworkMember is one sandbox attached to a network.
type SandboxNetworkMember struct {
SandboxID string `json:"sandbox_id"`
Status string `json:"status"`
IP string `json:"ip,omitempty"`
Name string `json:"name,omitempty"`
}
// NetworkList is the inner shape under data for GET /v1/networks.
type NetworkList struct {
Data []SandboxNetwork `json:"data"`
Pagination Pagination `json:"pagination"`
}
// BandwidthView is the response of GET /v1/sandboxes/:id/bandwidth.
// `Capped` flips true once usage hits the quota; while capped, the
// sandbox's egress is throttled hard at the host. `RemainingBytes`
// can read negative when used > quota due to in-flight accounting.
type BandwidthView struct {
ID string `json:"id"`
QuotaBytes int64 `json:"quota_bytes"`
UsedBytes int64 `json:"used_bytes"`
IngressBytes int64 `json:"ingress_bytes"`
RemainingBytes int64 `json:"remaining_bytes"`
Capped bool `json:"capped"`
}
// BandwidthRechargeReq is the body of POST /v1/sandboxes/:id/bandwidth/recharge.
type BandwidthRechargeReq struct {
AddBytes int64 `json:"add_bytes"`
}
// EgressView is the response of GET /v1/sandboxes/:id/egress.
type EgressView struct {
Egress []string `json:"egress"`
}
// EgressSetReq is the body of PUT /v1/sandboxes/:id/egress.
type EgressSetReq struct {
Egress []string `json:"egress"`
}
// ── Templates ─────────────────────────────────────────────────────
// TemplateView projects a templates row to the user-facing API.
// Mirrors fc-spawn's types.TemplateView.
type TemplateView struct {
ID string `json:"id"`
Name string `json:"name"`
Base string `json:"base"`
Status string `json:"status"`
Ext4SizeBytes int64 `json:"ext4_size_bytes"`
CreatedAt time.Time `json:"created_at"`
BuiltAt *time.Time `json:"built_at,omitempty"`
// Only populated by GET /v1/templates/:id?include=dockerfile.
Dockerfile string `json:"dockerfile,omitempty"`
}
// TemplateList is the inner shape under data for GET /v1/templates.
type TemplateList struct {
Data []TemplateView `json:"data"`
Pagination Pagination `json:"pagination"`
}
// TemplateCreateReq is the body of POST /v1/templates.
type TemplateCreateReq struct {
Name string `json:"name"`
Dockerfile string `json:"dockerfile"`
Base string `json:"base,omitempty"`
}
// TemplateLogEvent is one NDJSON frame from
// GET /v1/templates/:id/logs?follow=true. Either `Line` carries a
// build output line, or `Final` is true with `Status` set to
// ready/failed/cancelled.
type TemplateLogEvent struct {
Line string `json:"line,omitempty"`
Final bool `json:"final,omitempty"`
Status string `json:"status,omitempty"`
}