Documentation
¶
Overview ¶
Package client is the Go SDK for the Kiln HTTP API. It depends only on the standard library, so a caller outside this module can import it.
Index ¶
- func Conflict(err error) bool
- func NotFound(err error) bool
- type Client
- func (c *Client) CreateSandbox(ctx context.Context, req SandboxRequest) (Sandbox, error)
- func (c *Client) CreateTemplate(ctx context.Context, req TemplateRequest) error
- func (c *Client) DeleteSandbox(ctx context.Context, id string) error
- func (c *Client) DeleteSnapshot(ctx context.Context, id string) error
- func (c *Client) DeleteTemplate(ctx context.Context, name string) error
- func (c *Client) Events(ctx context.Context, after int64, sandboxID string, fn func(Event) error) error
- func (c *Client) Exec(ctx context.Context, id string, req ExecRequest) (ExecResult, error)
- func (c *Client) Fork(ctx context.Context, id string, count int, allowSecretFork bool) ([]SandboxRef, error)
- func (c *Client) Health(ctx context.Context) (Health, error)
- func (c *Client) Publish(ctx context.Context, id string, req PublishRequest) (PublishCreated, error)
- func (c *Client) ReadFile(ctx context.Context, id, path string) (io.ReadCloser, error)
- func (c *Client) RestoreSnapshot(ctx context.Context, snapshotID string, count int, allowSecretFork bool) ([]SandboxRef, error)
- func (c *Client) Retire(ctx context.Context, id string, port int) error
- func (c *Client) Sandbox(ctx context.Context, id string) (Sandbox, error)
- func (c *Client) Sandboxes(ctx context.Context) ([]Sandbox, error)
- func (c *Client) Snapshot(ctx context.Context, id string, stop bool) (SnapshotCreated, error)
- func (c *Client) SnapshotInfo(ctx context.Context, id string) (Snapshot, error)
- func (c *Client) Snapshots(ctx context.Context) ([]Snapshot, error)
- func (c *Client) Template(ctx context.Context, name string) (Template, error)
- func (c *Client) Templates(ctx context.Context) ([]Template, error)
- func (c *Client) WriteFile(ctx context.Context, id, path string, body io.Reader) error
- type Error
- type Event
- type ExecRequest
- type ExecResult
- type Health
- type PublishCreated
- type PublishRequest
- type Published
- type Sandbox
- type SandboxRef
- type SandboxRequest
- type Snapshot
- type SnapshotCreated
- type Template
- type TemplateRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// BaseURL is the control listener, for example http://127.0.0.1:8080.
BaseURL string
// Token is the bearer token from config.json.
Token string
// HTTP is the underlying client. Nil uses http.DefaultClient.
HTTP *http.Client
}
Client calls one Kiln daemon.
func (*Client) CreateSandbox ¶
CreateSandbox restores a template snapshot into a running sandbox.
func (*Client) CreateTemplate ¶
func (c *Client) CreateTemplate(ctx context.Context, req TemplateRequest) error
CreateTemplate starts a build and returns before it runs.
func (*Client) DeleteSandbox ¶
DeleteSandbox destroys one sandbox and every host resource named after it.
func (*Client) DeleteSnapshot ¶
DeleteSnapshot removes one listing once no live child reads it.
func (*Client) DeleteTemplate ¶
DeleteTemplate removes one template.
func (*Client) Events ¶
func (c *Client) Events(ctx context.Context, after int64, sandboxID string, fn func(Event) error) error
Events calls fn for every state transition until ctx ends. A zero after starts at the latest event; pass the last seen id to resume without a gap.
func (*Client) Exec ¶
func (c *Client) Exec(ctx context.Context, id string, req ExecRequest) (ExecResult, error)
Exec runs one command and buffers its output. A sleeping sandbox wakes first.
func (*Client) Fork ¶
func (c *Client) Fork(ctx context.Context, id string, count int, allowSecretFork bool) ([]SandboxRef, error)
Fork snapshots a running sandbox and restores count copies. A secret-bearing sandbox needs allowSecretFork.
func (*Client) Publish ¶
func (c *Client) Publish(ctx context.Context, id string, req PublishRequest) (PublishCreated, error)
Publish serves one guest port on a hostname. Republishing the same port returns the same URL.
func (*Client) ReadFile ¶
ReadFile opens one guest file. The caller closes the reader. A sleeping sandbox wakes first.
func (*Client) RestoreSnapshot ¶
func (c *Client) RestoreSnapshot(ctx context.Context, snapshotID string, count int, allowSecretFork bool) ([]SandboxRef, error)
RestoreSnapshot copies a listed snapshot into count new sandboxes.
func (*Client) Snapshot ¶
Snapshot writes a listed snapshot of one sandbox. With stop set the sandbox sleeps afterwards.
func (*Client) SnapshotInfo ¶
SnapshotInfo returns one listed snapshot.
type Event ¶
type Event struct {
ID int64 `json:"id"`
SandboxID string `json:"sandbox_id,omitempty"`
FromState string `json:"from_state,omitempty"`
ToState string `json:"to_state,omitempty"`
Reason string `json:"reason,omitempty"`
At time.Time `json:"at"`
}
Event is one state transition.
type ExecRequest ¶
type ExecRequest struct {
Cmd []string `json:"cmd"`
Cwd string `json:"cwd,omitempty"`
Env map[string]string `json:"env,omitempty"`
TimeoutSeconds int `json:"timeout_seconds,omitempty"`
}
ExecRequest is one command to run inside a sandbox.
type ExecResult ¶
type ExecResult struct {
ExitCode int `json:"exit_code"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
TimedOut bool `json:"timed_out,omitempty"`
Truncated bool `json:"truncated,omitempty"`
}
ExecResult is the buffered result of one command.
type Health ¶
type Health struct {
OK bool `json:"ok"`
KVM bool `json:"kvm"`
Firecracker string `json:"firecracker"`
Sandboxes int `json:"sandboxes"`
}
Health is the daemon's view of the host.
type PublishCreated ¶
PublishCreated is the answer to a publish call.
type PublishRequest ¶
PublishRequest is one POST /v1/sandboxes/{id}/publish body. Visibility is required and is "public" or "team".
type Published ¶
type Published struct {
Port int `json:"port"`
URL string `json:"url"`
Visibility string `json:"visibility"`
}
Published is one preview of a sandbox port.
type Sandbox ¶
type Sandbox struct {
ID string `json:"id"`
State string `json:"state"`
Template string `json:"template"`
Lifecycle string `json:"lifecycle"`
IdleSeconds int `json:"idle_seconds"`
TTLSeconds *int `json:"ttl_seconds"`
Metadata json.RawMessage `json:"metadata"`
CreatedAt time.Time `json:"created_at"`
LastActiveAt time.Time `json:"last_active_at"`
DestroyedAt *time.Time `json:"destroyed_at,omitempty"`
Published []Published `json:"published"`
EnvKeys []string `json:"env_keys"`
}
Sandbox is one sandbox row.
type SandboxRef ¶
SandboxRef names one copy.
type SandboxRequest ¶
type SandboxRequest struct {
Template string `json:"template"`
Lifecycle string `json:"lifecycle"`
IdleSeconds int `json:"idle_seconds"`
TTLSeconds *int `json:"ttl_seconds,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Secrets []string `json:"secrets,omitempty"`
Env map[string]string `json:"env,omitempty"`
}
SandboxRequest is one POST /v1/sandboxes body. Lifecycle and IdleSeconds are required. TTLSeconds nil means no deadline.
type Snapshot ¶
type Snapshot struct {
ID string `json:"id"`
Template string `json:"template"`
ParentID string `json:"parent_id,omitempty"`
SizeBytes int64 `json:"size_bytes"`
SecretBearing bool `json:"secret_bearing"`
CreatedAt time.Time `json:"created_at"`
}
Snapshot is one listed snapshot row.
type SnapshotCreated ¶
type SnapshotCreated struct {
SnapshotID string `json:"snapshot_id"`
SizeBytes int64 `json:"size_bytes"`
}
SnapshotCreated is the answer to a snapshot call.
type Template ¶
type Template struct {
Name string `json:"name"`
Image string `json:"image"`
ImageDigest string `json:"image_digest,omitempty"`
VCPUs int `json:"vcpus"`
MemoryMB int `json:"memory_mb"`
DiskMB int `json:"disk_mb"`
EgressAllow []string `json:"egress_allow"`
State string `json:"state"`
Error string `json:"error,omitempty"`
SnapshotBytes int64 `json:"snapshot_bytes"`
Sandboxes int `json:"sandboxes"`
CreatedAt time.Time `json:"created_at"`
}
Template is one template row.
type TemplateRequest ¶
type TemplateRequest struct {
Name string `json:"name"`
Image string `json:"image"`
VCPUs int `json:"vcpus"`
MemoryMB int `json:"memory_mb"`
DiskMB int `json:"disk_mb"`
Setup []string `json:"setup"`
EgressAllow []string `json:"egress_allow"`
}
TemplateRequest is one POST /v1/templates body. EgressAllow is required and may be empty.