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) EgressLog(ctx context.Context, id string) (EgressLog, error)
- func (c *Client) EgressRequests(ctx context.Context, id string) (EgressRequests, 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) ForkWithMetadata(ctx context.Context, id string, count int, allowSecretFork bool, ...) ([]SandboxRef, error)
- func (c *Client) Health(ctx context.Context) (Health, error)
- func (c *Client) Logs(ctx context.Context, id string) (SandboxLogs, error)
- func (c *Client) ObserveEgress(ctx context.Context, id string) (Sandbox, 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) ReadProcess(ctx context.Context, id, pid string, stdoutOffset, stderrOffset int64) (Process, error)
- func (c *Client) RestoreSnapshot(ctx context.Context, snapshotID string, count int, allowSecretFork bool) ([]SandboxRef, error)
- func (c *Client) RestoreSnapshotWithMetadata(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) SetCredentials(ctx context.Context, id string, credentials []Credential) (Sandbox, error)
- func (c *Client) SetEgress(ctx context.Context, id string, allow []string) (Sandbox, error)
- func (c *Client) SignalProcess(ctx context.Context, id, pid, signal string) 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) StartProcess(ctx context.Context, id string, req ProcessRequest) (string, 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 Credential
- type EgressLog
- type EgressRecord
- type EgressRequest
- type EgressRequests
- type Error
- type Event
- type ExecRequest
- type ExecResult
- type Health
- type Process
- type ProcessRequest
- type PublishCreated
- type PublishRequest
- type Published
- type Sandbox
- type SandboxLogs
- type SandboxRef
- type SandboxRequest
- type ServiceLog
- type Snapshot
- type SnapshotCreated
- type Template
- type TemplateCredential
- type TemplateRequest
- type TemplateService
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) EgressRequests ¶ added in v0.12.0
EgressRequests reads the request log of one sandbox.
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) ForkWithMetadata ¶ added in v0.9.7
func (c *Client) ForkWithMetadata(ctx context.Context, id string, count int, allowSecretFork bool, metadata map[string]any) ([]SandboxRef, error)
ForkWithMetadata is Fork with metadata that replaces the origin's on the copies. Nil keeps the origin's.
func (*Client) ObserveEgress ¶ added in v0.11.0
ObserveEgress lets any public TLS name through one sandbox and records it.
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) ReadProcess ¶ added in v0.9.0
func (c *Client) ReadProcess(ctx context.Context, id, pid string, stdoutOffset, stderrOffset int64) (Process, error)
ReadProcess reads a detached process and its output after each offset.
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) RestoreSnapshotWithMetadata ¶ added in v0.9.7
func (c *Client) RestoreSnapshotWithMetadata(ctx context.Context, snapshotID string, count int, allowSecretFork bool, metadata map[string]any) ([]SandboxRef, error)
RestoreSnapshotWithMetadata is RestoreSnapshot with metadata that replaces the origin's on the copies. Nil keeps the origin's.
func (*Client) SetCredentials ¶ added in v0.12.0
func (c *Client) SetCredentials(ctx context.Context, id string, credentials []Credential) (Sandbox, error)
SetCredentials replaces the credential bindings of one sandbox.
func (*Client) SetEgress ¶ added in v0.9.0
SetEgress replaces the egress policy of one sandbox. It returns after the host cuts every connection the guest opened.
func (*Client) SignalProcess ¶ added in v0.9.0
SignalProcess signals the process group of a detached process. An empty signal is TERM.
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.
func (*Client) StartProcess ¶ added in v0.9.0
StartProcess starts a detached process and returns its id.
type Credential ¶ added in v0.12.0
type Credential struct {
Name string `json:"name"`
Host string `json:"host"`
Header string `json:"header"`
Value string `json:"value,omitempty"`
Path string `json:"path,omitempty"`
Methods []string `json:"methods,omitempty"`
}
Credential is one credential binding. Value is sent and never returned.
type EgressLog ¶ added in v0.11.0
type EgressLog struct {
Records []EgressRecord `json:"records"`
Dropped int64 `json:"dropped"`
}
EgressLog is the egress record of one sandbox. Dropped counts the records that had no room.
type EgressRecord ¶ added in v0.11.0
type EgressRecord struct {
Host string `json:"host"`
Port int `json:"port"`
Decision string `json:"decision"`
Count int64 `json:"count"`
BytesOut int64 `json:"bytes_out"`
BytesIn int64 `json:"bytes_in"`
FirstSeen time.Time `json:"first_seen"`
LastSeen time.Time `json:"last_seen"`
}
EgressRecord is one destination of one sandbox.
type EgressRequest ¶ added in v0.12.0
type EgressRequest struct {
Method string `json:"method"`
Host string `json:"host"`
Path string `json:"path"`
Status int `json:"status"`
Binding string `json:"binding"`
At time.Time `json:"at"`
}
EgressRequest is one request a guard read on a bound host.
type EgressRequests ¶ added in v0.12.0
type EgressRequests struct {
Requests []EgressRequest `json:"requests"`
Dropped int64 `json:"dropped"`
}
EgressRequests is the request log of one sandbox. Dropped counts the requests that had no room.
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"`
// Template names the template of a build event. Phase and DurationMS say
// how long one step of a build or a restore took.
Template string `json:"template,omitempty"`
Phase string `json:"phase,omitempty"`
DurationMS *int64 `json:"duration_ms,omitempty"`
}
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 Process ¶ added in v0.9.0
type Process struct {
ID string `json:"id"`
Running bool `json:"running"`
ExitCode *int `json:"exit_code"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
StdoutOffset int64 `json:"stdout_offset"`
StderrOffset int64 `json:"stderr_offset"`
StdoutLost int64 `json:"stdout_lost"`
StderrLost int64 `json:"stderr_lost"`
More bool `json:"more"`
}
Process is one read of a detached process. ExitCode is nil while it runs.
type ProcessRequest ¶ added in v0.9.0
type ProcessRequest struct {
Cmd []string `json:"cmd"`
Cwd string `json:"cwd,omitempty"`
Env map[string]string `json:"env,omitempty"`
}
ProcessRequest is one detached process to start.
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"`
EgressAllow []string `json:"egress_allow"`
// EgressObserve lets any TLS name through and records it.
EgressObserve bool `json:"egress_observe"`
// Credentials names each binding, with no value.
Credentials []Credential `json:"credentials"`
}
Sandbox is one sandbox row.
type SandboxLogs ¶ added in v0.10.0
type SandboxLogs struct {
Services []ServiceLog `json:"services"`
}
SandboxLogs is the answer of Logs.
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 ServiceLog ¶ added in v0.10.0
type ServiceLog struct {
Name string `json:"name"`
Running bool `json:"running"`
ExitCode int `json:"exit_code"`
Output string `json:"output"`
}
ServiceLog is what the guest kept of one service.
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"`
User string `json:"user,omitempty"`
}
Template is one template row.
type TemplateCredential ¶ added in v0.9.0
TemplateCredential is the registry login of one build.
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"`
// User is who everything a caller asks for runs as. Empty is root.
User string `json:"user,omitempty"`
// Start and Port run the application. A port with no start runs the
// command the image names.
Start []string `json:"start,omitempty"`
Port int `json:"port,omitempty"`
// Services run beside the application, and Seed runs once they are ready.
Services []TemplateService `json:"services,omitempty"`
Seed []string `json:"seed,omitempty"`
// Credential pulls the images of this build and goes no further.
Credential *TemplateCredential `json:"credential,omitempty"`
}
TemplateRequest is one POST /v1/templates body. EgressAllow is required and may be empty.
type TemplateService ¶ added in v0.10.0
type TemplateService struct {
Name string `json:"name"`
Image string `json:"image"`
Env map[string]string `json:"env,omitempty"`
Port int `json:"port,omitempty"`
Start []string `json:"start,omitempty"`
Ready []string `json:"ready,omitempty"`
}
TemplateService is one image that runs beside the application.