client

package
v0.16.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0, MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Conflict

func Conflict(err error) bool

Conflict reports whether err is a 409 from the API.

func NotFound

func NotFound(err error) bool

NotFound reports whether err is a 404 from the API.

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 New

func New(baseURL, token string) *Client

New returns a client for one control listener.

func (*Client) CreateSandbox

func (c *Client) CreateSandbox(ctx context.Context, req SandboxRequest) (Sandbox, error)

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) DeletePoint added in v0.13.0

func (c *Client) DeletePoint(ctx context.Context, id, point string) error

DeletePoint removes one timeline point.

func (*Client) DeleteSandbox

func (c *Client) DeleteSandbox(ctx context.Context, id string) error

DeleteSandbox destroys one sandbox and every host resource named after it.

func (*Client) DeleteSnapshot

func (c *Client) DeleteSnapshot(ctx context.Context, id string) error

DeleteSnapshot removes one listing once no live child reads it.

func (*Client) DeleteTemplate

func (c *Client) DeleteTemplate(ctx context.Context, name string) error

DeleteTemplate removes one template.

func (*Client) EgressLog added in v0.11.0

func (c *Client) EgressLog(ctx context.Context, id string) (EgressLog, error)

EgressLog reads the egress record of one sandbox.

func (*Client) EgressRequests added in v0.12.0

func (c *Client) EgressRequests(ctx context.Context, id string) (EgressRequests, error)

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) Health

func (c *Client) Health(ctx context.Context) (Health, error)

Health returns the daemon's health.

func (*Client) Logs added in v0.10.0

func (c *Client) Logs(ctx context.Context, id string) (SandboxLogs, error)

Logs reads what the guest kept of one sandbox.

func (*Client) MarkPoint added in v0.13.0

func (c *Client) MarkPoint(ctx context.Context, id, label string) (TimelinePoint, error)

MarkPoint marks a timeline point on one sandbox.

func (*Client) ObserveEgress added in v0.11.0

func (c *Client) ObserveEgress(ctx context.Context, id string) (Sandbox, error)

ObserveEgress lets any public TLS name through one sandbox and records it.

func (*Client) Points added in v0.13.0

func (c *Client) Points(ctx context.Context, id string) ([]TimelinePoint, error)

Points lists the timeline points of one sandbox, oldest first.

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

func (c *Client) ReadFile(ctx context.Context, id, path string) (io.ReadCloser, error)

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) Retire

func (c *Client) Retire(ctx context.Context, id string, port int) error

Retire removes one published hostname. It 404s from then on.

func (*Client) RewindPoint added in v0.13.0

func (c *Client) RewindPoint(ctx context.Context, id, point string) (Sandbox, error)

RewindPoint restores one timeline point under the same sandbox id.

func (*Client) Sandbox

func (c *Client) Sandbox(ctx context.Context, id string) (Sandbox, error)

Sandbox returns one sandbox. A row read never wakes a sleeping sandbox.

func (*Client) Sandboxes

func (c *Client) Sandboxes(ctx context.Context) ([]Sandbox, error)

Sandboxes lists every sandbox.

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

func (c *Client) SetEgress(ctx context.Context, id string, allow []string) (Sandbox, error)

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

func (c *Client) SignalProcess(ctx context.Context, id, pid, signal string) error

SignalProcess signals the process group of a detached process. An empty signal is TERM.

func (*Client) Snapshot

func (c *Client) Snapshot(ctx context.Context, id string, stop bool) (SnapshotCreated, error)

Snapshot writes a listed snapshot of one sandbox. With stop set the sandbox sleeps afterwards.

func (*Client) SnapshotInfo

func (c *Client) SnapshotInfo(ctx context.Context, id string) (Snapshot, error)

SnapshotInfo returns one listed snapshot.

func (*Client) Snapshots

func (c *Client) Snapshots(ctx context.Context) ([]Snapshot, error)

Snapshots lists every listed snapshot.

func (*Client) StartProcess added in v0.9.0

func (c *Client) StartProcess(ctx context.Context, id string, req ProcessRequest) (string, error)

StartProcess starts a detached process and returns its id.

func (*Client) Template

func (c *Client) Template(ctx context.Context, name string) (Template, error)

Template returns one template.

func (*Client) Templates

func (c *Client) Templates(ctx context.Context) ([]Template, error)

Templates lists every template.

func (*Client) WriteFile

func (c *Client) WriteFile(ctx context.Context, id, path string, body io.Reader) error

WriteFile writes one guest file. Parent directories are created.

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 Error

type Error struct {
	Status  int
	Code    string
	Message string
}

Error is an API error with its stable code.

func (*Error) Error

func (e *Error) Error() string

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

type PublishCreated struct {
	URL        string `json:"url"`
	Visibility string `json:"visibility"`
	// ViewerCap and ViewerResetURL are set on a viewer fork origin.
	ViewerCap      int    `json:"viewer_cap,omitempty"`
	ViewerResetURL string `json:"viewer_reset_url,omitempty"`
}

PublishCreated is the answer to a publish call.

type PublishRequest

type PublishRequest struct {
	Port       int    `json:"port"`
	Visibility string `json:"visibility"`
	// ViewerFork gives each viewer login its own fork. It needs visibility team
	// and ViewerCap.
	ViewerFork      bool `json:"viewer_fork,omitempty"`
	ViewerCap       int  `json:"viewer_cap,omitempty"`
	AllowSecretFork bool `json:"allow_secret_fork,omitempty"`
}

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

type SandboxRef struct {
	ID    string `json:"id"`
	State string `json:"state"`
}

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

type TemplateCredential struct {
	Username string `json:"username"`
	Token    string `json:"token"`
}

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.

type TimelinePoint added in v0.13.0

type TimelinePoint struct {
	ID            string    `json:"id"`
	Label         string    `json:"label,omitempty"`
	Kind          string    `json:"kind"`
	Bytes         int64     `json:"bytes"`
	Merged        int       `json:"merged,omitempty"`
	SecretBearing bool      `json:"secret_bearing,omitempty"`
	CreatedAt     time.Time `json:"created_at"`
}

TimelinePoint is one marked state of one sandbox.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL