client

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 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) 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) 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) Health

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

Health returns the daemon's health.

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) 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) 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) 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 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"`
}

PublishCreated is the answer to a publish call.

type PublishRequest

type PublishRequest struct {
	Port       int    `json:"port"`
	Visibility string `json:"visibility"`
}

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"`
}

Sandbox is one sandbox row.

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 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"`
	// 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.

Jump to

Keyboard shortcuts

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