client

package
v0.36.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 36 Imported by: 2 modules, 5 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 starts runs and reads what happened to them. The command line, the gateway and an application written in Go all use it, so there is one behaviour and one set of words for all of them.

Index

Constants

View Source
const ConfigName = ".corbie"

ConfigName is the name of the config directory corbie up makes in the directory it submits. Nothing in it is a machine.

View Source
const ScriptStage = "script"

ScriptStage is the name of the one stage a script is wrapped in.

Variables

View Source
var ErrCalled = errors.New("the run is a call into a tree of another client, and only the call's result is shown")

ErrCalled is a run this client started as a call into a tree of another client: only the call's result is shown.

View Source
var ErrFilesTooLarge = errors.New("the blobs of the output are more than are given with a run")

ErrFilesTooLarge is an output whose blobs are more than are given with a run.

View Source
var ErrNeverTaken = fmt.Errorf("%w: its start was never taken up", ErrNoRun)

ErrNeverTaken is a run whose start stopped being good before a controller took it up.

View Source
var ErrNoFile = errors.New("the run shows no file at the path")

ErrNoFile is a path that names no blob of the run.

View Source
var ErrNoRecord = errors.New("the run has no record to read")

ErrNoRecord is a run with nothing in its record to read yet: it is waiting to start, or its start was refused.

View Source
var ErrNoRun = errors.New("there is no such run")

ErrNoRun is a run that does not exist: it was never started, or it is past keeping and gone.

View Source
var ErrNoStep = errors.New("the run has no step")

ErrNoStep is a step's number that a run's record does not hold.

View Source
var ErrNotTaken = errors.New("the message was not taken up: it is no longer good and no receipt has come (is a controller running?)")

ErrNotTaken is a message that stopped being good before a controller answered it.

View Source
var ErrOthers = fmt.Errorf("%w of this client's", ErrNoRun)

ErrOthers is a run in a tree of another client, whose file's read: does not list this client: to this client it is no run.

View Source
var ErrStart = errors.New("the start cannot be sent")

ErrStart is a start that cannot be sent as it was given.

View Source
var LocalInterval = time.Second

LocalInterval is how long a role in one process sleeps when nothing is due and nothing wakes it.

Statuses are the words a listing can be narrowed to by status: what a run that is listed can be.

Functions

func ReadMachine added in v0.12.0

func ReadMachine(dir, rel string) (*machine.Draft, error)

ReadMachine reads the machine at rel in the context dir. A path in it may name any file inside dir and none outside.

func Script added in v0.7.0

func Script(name string, script []byte, job ScriptJob) (*machine.Draft, error)

Script wraps a script in a flow of one stage, whose job runs it with the run's input and whose output is the flow's. name is the script's file name, and the flow is named after it. Nothing is sent.

func Taking added in v0.28.0

func Taking(life time.Duration) time.Duration

Taking is how long after it is sent a controller may still take a message: its life and the allowance for clocks, by a controller's clock that may be the allowance behind this client's.

func WithFiles added in v0.7.0

func WithFiles(input any, files map[string]InputFile) (any, error)

WithFiles gives an input with each file standing under its name. The input is a map of names, or nothing.

Types

type Client

type Client struct {
	ID         *identity.Identity
	Controller identity.Card
	Store      store.Store
	// Now is the client's clock.
	Now func() time.Time
	// Principal is the principal the client sends its messages for, if it says:
	// the controller writes it into the cause of what each message does.
	Principal string
	// contains filtered or unexported fields
}

A Client is one party's way into a controller's store. With no identity it is a viewer: it can list the heads the store lets it read and nothing more.

func New

func New(id *identity.Identity, controller identity.Card, s store.Store) *Client

New makes a client of a controller's store.

func Remote added in v0.30.0

func Remote(address, token string) *Client

Remote makes a client that sends everything to a gateway, as the client the token names. It holds no key and reads no store: each thing the package does is one request to the gateway, which does it.

func (*Client) Address added in v0.17.0

func (c *Client) Address(ctx context.Context, text string) (machine.Address, error)

Address reads the address of a run as a client writes it: a location from /, a location and a key as /location#key, or a run's ID, which is at the location its head names. A run of the client's own is named by its ID alone until it has a head.

func (*Client) As added in v0.30.0

func (c *Client) As(principal string) *Client

As gives the same client sending its messages for a principal.

func (*Client) Cancel

func (c *Client) Cancel(ctx context.Context, run string, life time.Duration) (string, error)

Cancel asks for a run to be cancelled. It gives the name of the message, by which its receipt is found. Like a start, a cancel, an event and an answer are each good for the life given, or for a few minutes if it is zero.

func (*Client) Definition

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

Definition gives the definition a run was started from, in its full form, as it is shown: each script and each machine it names as a blob's type, its size and the path to ask for it by.

func (*Client) Fetch

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

Fetch gives the contents of a blob of a run, by the path it was shown with.

A path shown in a run's result says where the blob is in the output: report, pages[2]. A path shown anywhere else begins with the place of what holds the blob (steps/<number> or emits/<job>/<number>, which is an entry of the run's record, input or definition) and after the next slash says where the blob is in that.

func (*Client) Files

func (c *Client) Files(ctx context.Context, id string) (map[string]File, error)

Files lists the blobs in a run's result by their paths, each with the name it has in the value that holds it. It lists every blob a path of the result fetches: one written out inside a text is among them.

func (*Client) Follow

func (c *Client) Follow(ctx context.Context, id string, interval time.Duration, tell func(Entry)) (*Run, error)

Follow gives each entry of a run's record as it is written, with those of every instance below it, and ends when the run and everything below it have ended, saying how the run ended. Each entry is read once. A look that cannot reach the store is made again at the next interval. A follow that is cut short gives the run as it stands.

func (*Client) List

func (c *Client) List(ctx context.Context, filter Filter) ([]*Run, error)

List gives the runs this party may read, each as its head gives it: every instance, not only roots. A client sees its own and those whose file's read: lists it; a viewer with access to heads sees everyone's.

func (*Client) ListSecrets added in v0.26.0

func (c *Client) ListSecrets(ctx context.Context, life time.Duration) (string, error)

ListSecrets asks the controller for the names of the secrets set where this client may set them, and where each is set. The receipt lists them.

func (*Client) ListValues added in v0.26.0

func (c *Client) ListValues(ctx context.Context, life time.Duration) (string, error)

ListValues asks the controller for the values set where this client may set them, and where each is set. The receipt lists them.

func (*Client) NewRun

func (c *Client) NewRun() (string, error)

NewRun chooses the name of a run before it is started, so that an application can note it before anything is sent.

func (*Client) OutputWithBytes added in v0.36.0

func (c *Client) OutputWithBytes(ctx context.Context, id string, most int64) (any, error)

OutputWithBytes gives a run's output as Show gives it, with the bytes of each blob beside its path, type and size, as base64 in data. The blobs are named where the shown output is made, so each is the one its path fetches.

The blobs are at most most bytes together, each counted where it is named: past that the error is ErrFilesTooLarge and no more is read. Through a gateway, the limit is that gateway's.

func (*Client) Receipt

func (c *Client) Receipt(ctx context.Context, message string) (*instance.Receipt, error)

Receipt reads the controller's answer to a message this client sent. It gives nil while there is none.

func (*Client) Record

func (c *Client) Record(ctx context.Context, id string, tell func(Entry)) (*Run, error)

Record gives each entry of a run's record so far, with those of every instance below it, and then the run as it stands: what a follow gives, without staying.

func (*Client) RemoveSecret added in v0.26.0

func (c *Client) RemoveSecret(ctx context.Context, at, name string, life time.Duration) (string, error)

RemoveSecret asks the controller to remove a secret set at a location.

func (*Client) RemoveTree added in v0.34.0

func (c *Client) RemoveTree(ctx context.Context, prefix string, life time.Duration) (string, error)

RemoveTree removes the tree at a prefix: the controller cancels every run at its locations, removes the locations and the secrets and values set at or under the prefix, and then the tree. It gives the name of the message, by which its receipt is found.

func (*Client) RemoveValue added in v0.26.0

func (c *Client) RemoveValue(ctx context.Context, at, name string, life time.Duration) (string, error)

RemoveValue asks the controller to remove a value set at a location.

func (*Client) Reply

func (c *Client) Reply(ctx context.Context, run, ticket string, value any, life time.Duration) (string, error)

Reply answers a ticket of a run. The ticket is the authority: any client that holds it may answer.

func (*Client) Send

func (c *Client) Send(ctx context.Context, to machine.Address, event string, data any, life time.Duration) (string, error)

Send sends a named event to a run by its address. The controller takes it as it takes a run's send, and its receipt names the run that took it.

func (*Client) SetSecret added in v0.26.0

func (c *Client) SetSecret(ctx context.Context, at, name, value string, life time.Duration) (string, error)

SetSecret sends the controller a secret to set at a location, at or under a prefix where this client could submit a tree. It gives the name of the message, by which its receipt is found; the receipt never holds the value.

func (*Client) SetValue added in v0.26.0

func (c *Client) SetValue(ctx context.Context, at, name, value string, life time.Duration) (string, error)

SetValue sends the controller a value to set at a location, as SetSecret does a secret.

func (*Client) Show

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

Show gives one run: where it stands and, once it has ended, how. It is shown from its record: the head may be a moment behind, or not there yet.

func (*Client) Start

func (c *Client) Start(ctx context.Context, start Start) (string, error)

Start starts a run of a location. The files of the input, and then the input itself, are written into the run's record first, and then the start is sent. It gives the run's name.

func (*Client) Started added in v0.17.0

func (c *Client) Started(ctx context.Context, id string, interval time.Duration) error

Started stays until a run a submit started has been taken up. The controller's start of it is good for ever, as a singleton started again waits for the runs it replaces to end, and so the wait has no limit.

func (*Client) Step

func (c *Client) Step(ctx context.Context, id string, number int) (*Entry, error)

Step gives one step entry of a run's record, as it is shown.

func (*Client) Submit added in v0.17.0

func (c *Client) Submit(ctx context.Context, tree *Tree, life time.Duration) (string, error)

Submit records a tree at its prefix. Each machine of the tree is written among the message's uploads, a bounded number at a time, and then the submit is sent. A file with a problem is sent as one, and its location keeps what was recorded before. It gives the name of the message, by which its receipt is found.

func (*Client) Taken added in v0.17.0

func (c *Client) Taken(ctx context.Context, id string, life, interval time.Duration) error

Taken stays until a run this client started has been taken up: it is no longer waiting to start. A run is waited for while a controller may take its start: for the life it was sent with, a few minutes if none, and the allowance for clocks.

func (*Client) Tickets added in v0.2.0

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

Tickets gives the tickets a run is waiting on, each name with its value. The value is the whole right to answer; it is in the record, which only the client of the run's tree and the clients its file's read: lists can read.

func (*Client) Wait

func (c *Client) Wait(ctx context.Context, id string, interval time.Duration) (*Run, error)

Wait stays until a run has ended and gives it. It looks again when this process writes to the store, and otherwise at the interval; a look that cannot reach the store is made again. A wait that is cut short, by the context's limit or by its caller going away, gives the run as it stands.

func (*Client) WaitReceipt

func (c *Client) WaitReceipt(ctx context.Context, message string, life, interval time.Duration) (*instance.Receipt, error)

WaitReceipt stays until the controller has answered a message this client has just sent, and gives the receipt. life is the life the message was sent with. Once no controller may take the message and no receipt has come, the wait ends, saying the message was not taken up. It looks again when this process writes to the store, and otherwise at the interval.

func (*Client) Watch

func (c *Client) Watch(ctx context.Context, filter Filter, interval time.Duration, tell func(Update)) error

Watch follows a listing as it changes: the runs that already exist, then the mark, then each run that appears or changes, until the context ends. A run is given once more when it ends, saying how, also when the listing does not take in the finished. A run that the listing keeps, and that started and ended between two looks, is given once, as new and ended. It writes nothing and asks nothing of the controller. A look that cannot reach the store is made again at the next interval, and nothing is given on its account.

func (*Client) Who added in v0.30.0

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

Who says which client this is. Through a gateway it is the client and the principal the token names.

type Entry

type Entry struct {
	ID   string    `json:"id"` // the instance whose record it is in
	Time time.Time `json:"time"`
	// For a step.
	Step   int                `json:"step,omitzero"`
	Events []instance.Arrived `json:"events,omitzero"`
	Asks   []instance.Ask     `json:"asks,omitzero"`
	Status string             `json:"status,omitzero"`
	Shown  machine.Shown      `json:"state,omitzero"` // the run's state after the step
	// For an emit.
	Job  string `json:"job,omitzero"` // the job that emitted
	Name string `json:"name,omitzero"`
	Data any    `json:"data,omitzero"`
}

An Entry is one entry of a run's record as a follower is given it: a step, or a value a job emitted. Values are as they are shown: a blob is its type, its size and the path to ask for it by.

type File

type File struct {
	Name string `json:"name,omitzero"`
	Type string `json:"type"`
	Size int64  `json:"size"`
}

A File is a blob of a run as it is shown: what it is and how large, and no key. Name is what the value that holds it calls it.

type Filter

type Filter struct {
	// Labels keeps runs that carry every one of these: a label with a
	// value must match it, and one with none need only be there.
	Labels map[string]string
	// Status keeps runs with this status.
	Status string
	// Parent keeps the runs this instance started.
	Parent string
	// Location keeps the runs at a location.
	Location string
	// Key keeps the runs of a keyed location with this key.
	Key string
	// Finished takes in the runs that have ended and are still kept. A
	// Status of a run that has ended takes them in as well.
	Finished bool
}

A Filter narrows a listing of runs, or widens it to take in those that have ended.

type InputFile

type InputFile struct {
	Name     string
	Contents io.Reader
}

An InputFile is a file given as input: the name it has as a file, from which the blob's type follows, and its contents.

func (InputFile) MarshalJSON added in v0.7.0

func (f InputFile) MarshalJSON() ([]byte, error)

MarshalJSON refuses a file that Start cannot find in the input: one that is not an InputFile in a map[string]any or a []any.

type Local

type Local struct {
	*Client
	Memory     *store.Memory
	Controller *controller.Controller
	Runner     *runner.Runner
	// contains filtered or unexported fields
}

Local is every role in one process with the store in memory: a controller, a runner and a client that trust each other. It is the same loop as on a computer, and each role works under its own row of the table of who may touch what. Nothing is set up beforehand and nothing is left behind.

func NewLocal

func NewLocal(ctx context.Context, ceiling permission.Layer, report func(role string, err error)) (*Local, error)

NewLocal starts a controller and a runner in this process. The ceiling is what jobs may do on this computer. report is told of each pass of a role that failed.

func (*Local) Close

func (l *Local) Close()

Close stops the roles and waits for them.

func (*Local) Run added in v0.17.0

func (l *Local) Run(ctx context.Context, draft *machine.Draft, start Start) (string, error)

Run submits a definition as a tree of one file, at a prefix of its own that begins with the machine's name, and gives the run RunTree gives.

func (*Local) RunTree added in v0.17.0

func (l *Local) RunTree(ctx context.Context, tree *Tree, at string, start Start) (string, error)

RunTree submits a tree and gives the run at one of its locations: the one the submit starts for a singleton, and otherwise one started there with what start carries. A start that carries anything but its life to a singleton is an error.

func (*Local) SetSecret added in v0.17.0

func (l *Local) SetSecret(ctx context.Context, at, name, value string) error

SetSecret sets a secret at a location, as the controller's owner does.

func (*Local) SetValue added in v0.17.0

func (l *Local) SetValue(ctx context.Context, at, name, value string) error

SetValue sets a value at a location, as the controller's owner does.

type Machine added in v0.12.0

type Machine struct {
	Path     string // from the directory, such as devices/boiler.yaml
	Location string // such as /home/devices/boiler
	Draft    *machine.Draft
	Problem  error // what stopped the file being read; Draft is nil
}

A Machine is one *.yaml file of a tree.

type Run

type Run struct {
	ID      string `json:"id"`
	Machine string `json:"machine,omitzero"`
	Type    string `json:"type,omitzero"`
	// Status is waiting (to start), running, done, failed or cancelled.
	Status string `json:"status"`
	// Failure says why a failed run failed: error, timeout or denied.
	Failure string `json:"failure,omitzero"`
	Error   string `json:"error,omitzero"`
	// A denial says what was refused, which layer refused it and what
	// would fix it.
	Refused string `json:"refused,omitzero"`
	Layer   string `json:"layer,omitzero"`
	Fix     string `json:"fix,omitzero"`

	// Title, Input and Output are shown only to a client that reads the
	// run's record.
	Title  string `json:"title,omitzero"`
	Input  any    `json:"input,omitzero"`
	Output any    `json:"output,omitzero"`
	// Used lists the permissions the run used: those of every job in it
	// and below it.
	Used []string `json:"used,omitzero"`

	Step    int       `json:"step,omitzero"`
	Started time.Time `json:"started,omitzero"`
	Ended   time.Time `json:"ended,omitzero"`
	Parent  string    `json:"parent,omitzero"`
	// Location is where the run's machine lives, Key is the run's key at a
	// keyed location, and Cause what started it: a step of another run, or
	// a client's message.
	Location string         `json:"location,omitzero"`
	Key      string         `json:"key,omitzero"`
	Cause    instance.Cause `json:"cause,omitzero"`
	// Called is, for a start of a location in a tree another client owns,
	// the run the call started there. The client is shown only its status
	// and its output or error, from the call's result.
	Called  string            `json:"called,omitzero"`
	Jobs    int               `json:"jobs,omitzero"`
	Timers  int               `json:"timers,omitzero"`
	Tickets []string          `json:"tickets,omitzero"`
	Labels  map[string]string `json:"labels,omitzero"`
}

A Run is a run as it is shown, wherever it is shown: the same shape and the same words at the command line, over HTTP and to an application.

func (*Run) HasEnded

func (r *Run) HasEnded() bool

Ended says whether the run has ended.

type ScriptJob added in v0.7.0

type ScriptJob struct {
	Allow, Deny []string
	Timeout     string // a length of time, such as 7s
	Memory      string // a size, such as 64MB
	Tags        []string
}

ScriptJob is what a script wrapped by Script may do, and its limits, as a definition writes them on a job.

type Start

type Start struct {
	// At is the location the run is started at: the run's machine is the
	// file recorded there.
	At string
	// Run is the run's name, if it was chosen beforehand with NewRun.
	Run string
	// Input is the run's input. An InputFile may stand in place of any
	// value in a map[string]any or a []any of it: the file is put into the
	// run's record, and stands in the input as a blob. A blob of another of
	// this client's runs is carried over by writing it as it was shown, with
	// the run it was shown for added: { "$blob": <its path>, "run": <that
	// run's ID> }, with or without the type and size it was shown with. The
	// blob is copied into the new run's record, and the copy stands in the
	// input.
	Input  any
	Labels map[string]string
	// Allow narrows what the run, and everything below it, may do.
	Allow *permission.Layer
	// Timeout is how long the run may take.
	Timeout time.Duration
	// Life is how long the start is good for; a few minutes if it says
	// nothing.
	Life time.Duration
}

A Start is what a start of a location carries.

type Tree added in v0.17.0

type Tree struct {
	Prefix string
	// Directory is the directory's absolute path, every link followed. A
	// machine reads it as run.context.
	Directory string
	Machines  []*Machine
	// Listed is each file and directory .corbieignore lists that the
	// directory holds, from the directory, a directory ending in /.
	Listed []string
	// Files is every file of the directory that was read, by its path from
	// the directory: the machines, the scripts and the files they name, the
	// files they include, and .corbieignore. A gateway is sent these.
	Files map[string][]byte
	// File is, for a tree of one file, that file's path from the directory.
	File string
}

A Tree is a directory read to be submitted at a prefix: each of its *.yaml files that .corbieignore does not list is a machine at a location.

func ReadFile added in v0.17.0

func ReadFile(dir, rel, at string, job ScriptJob) (*Tree, error)

ReadFile reads the file at rel in the context dir as a tree of its own, whose prefix at is the file's location. A script file is wrapped as Script wraps it, with job. A file that cannot be read as a machine is given with its Problem.

func ReadTree added in v0.17.0

func ReadTree(dir, at string) (*Tree, error)

ReadTree reads every *.yaml in dir and below it as a machine, but for .git and what the .corbieignore at the top of dir lists. A listed file has no location, and a machine may still read it. at is the prefix, by default / and the directory's own name, and one that cannot be a prefix is an error, as is a line of .corbieignore that is no path in dir. A file that cannot be read as a machine, or whose path gives no location, is given with its Problem.

func (*Tree) Unsent added in v0.18.0

func (t *Tree) Unsent() (problems map[*Machine][]string, empty map[string][]string)

Unsent gives, by machine, each send and call of the tree's machines that the controller would refuse or not deliver, whatever else it holds: one to a location whose lifetime the address does not fit, or whose receive: does not list the sender, or for which the sender's own allow: and deny: do not hold send:. A send whose location is an expression or in another tree, or that names a run, is not checked, and neither is a list with an expression in it. empty gives each location of the tree with no machine that a send or a call names, with where: such a send may be one a condition leaves out, or wait for a file still to come.

type Update

type Update struct {
	Run *Run `json:"run,omitzero"`
	New bool `json:"new,omitzero"`
	// Listed marks the end of the first listing: everything that already
	// existed has been given.
	Listed bool `json:"listed,omitzero"`
}

An Update is one thing a watcher of a listing is told: a run that is new or has changed, or the mark of the end of the first listing.

type Who added in v0.30.0

type Who struct {
	Client    string `json:"client"`
	Principal string `json:"principal,omitzero"`
}

Who is which client a Client is, and the principal it sends its messages for.

Directories

Path Synopsis
Package cli is Corbie's command line.
Package cli is Corbie's command line.
Package gateway is the client package over HTTP: a route for each thing the package sends and each thing it reads, and streams for what can be followed.
Package gateway is the client package over HTTP: a route for each thing the package sends and each thing it reads, and streams for what can be followed.

Jump to

Keyboard shortcuts

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