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
- Variables
- func ReadMachine(dir, rel string) (*machine.Draft, error)
- func Script(name string, script []byte, job ScriptJob) (*machine.Draft, error)
- func Taking(life time.Duration) time.Duration
- func WithFiles(input any, files map[string]InputFile) (any, error)
- type Client
- func (c *Client) Address(ctx context.Context, text string) (machine.Address, error)
- func (c *Client) As(principal string) *Client
- func (c *Client) Cancel(ctx context.Context, run string, life time.Duration) (string, error)
- func (c *Client) Definition(ctx context.Context, id string) (*machine.Definition, error)
- func (c *Client) Fetch(ctx context.Context, id, path string) (io.Reader, File, error)
- func (c *Client) Files(ctx context.Context, id string) (map[string]File, error)
- func (c *Client) Follow(ctx context.Context, id string, interval time.Duration, tell func(Entry)) (*Run, error)
- func (c *Client) List(ctx context.Context, filter Filter) ([]*Run, error)
- func (c *Client) ListSecrets(ctx context.Context, life time.Duration) (string, error)
- func (c *Client) ListValues(ctx context.Context, life time.Duration) (string, error)
- func (c *Client) NewRun() (string, error)
- func (c *Client) Receipt(ctx context.Context, message string) (*instance.Receipt, error)
- func (c *Client) Record(ctx context.Context, id string, tell func(Entry)) (*Run, error)
- func (c *Client) RemoveSecret(ctx context.Context, at, name string, life time.Duration) (string, error)
- func (c *Client) RemoveTree(ctx context.Context, prefix string, life time.Duration) (string, error)
- func (c *Client) RemoveValue(ctx context.Context, at, name string, life time.Duration) (string, error)
- func (c *Client) Reply(ctx context.Context, run, ticket string, value any, life time.Duration) (string, error)
- func (c *Client) Send(ctx context.Context, to machine.Address, event string, data any, ...) (string, error)
- func (c *Client) SetSecret(ctx context.Context, at, name, value string, life time.Duration) (string, error)
- func (c *Client) SetValue(ctx context.Context, at, name, value string, life time.Duration) (string, error)
- func (c *Client) Show(ctx context.Context, id string) (*Run, error)
- func (c *Client) Start(ctx context.Context, start Start) (string, error)
- func (c *Client) Started(ctx context.Context, id string, interval time.Duration) error
- func (c *Client) Step(ctx context.Context, id string, number int) (*Entry, error)
- func (c *Client) Submit(ctx context.Context, tree *Tree, life time.Duration) (string, error)
- func (c *Client) Taken(ctx context.Context, id string, life, interval time.Duration) error
- func (c *Client) Tickets(ctx context.Context, id string) (map[string]string, error)
- func (c *Client) Wait(ctx context.Context, id string, interval time.Duration) (*Run, error)
- func (c *Client) WaitReceipt(ctx context.Context, message string, life, interval time.Duration) (*instance.Receipt, error)
- func (c *Client) Watch(ctx context.Context, filter Filter, interval time.Duration, tell func(Update)) error
- func (c *Client) Who(ctx context.Context) (Who, error)
- type Entry
- type File
- type Filter
- type InputFile
- type Local
- func (l *Local) Close()
- func (l *Local) Run(ctx context.Context, draft *machine.Draft, start Start) (string, error)
- func (l *Local) RunTree(ctx context.Context, tree *Tree, at string, start Start) (string, error)
- func (l *Local) SetSecret(ctx context.Context, at, name, value string) error
- func (l *Local) SetValue(ctx context.Context, at, name, value string) error
- type Machine
- type Run
- type ScriptJob
- type Start
- type Tree
- type Update
- type Who
Constants ¶
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.
const ScriptStage = "script"
ScriptStage is the name of the one stage a script is wrapped in.
Variables ¶
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.
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.
var ErrNoFile = errors.New("the run shows no file at the path")
ErrNoFile is a path that names no blob of the run.
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.
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.
var ErrNoStep = errors.New("the run has no step")
ErrNoStep is a step's number that a run's record does not hold.
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.
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.
var ErrStart = errors.New("the start cannot be sent")
ErrStart is a start that cannot be sent as it was given.
var LocalInterval = time.Second
LocalInterval is how long a role in one process sleeps when nothing is due and nothing wakes it.
var Statuses = []string{instance.Running, instance.Done, instance.Failed, instance.Cancelled}
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
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
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.
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 Remote ¶ added in v0.30.0
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
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) Cancel ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
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
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 ¶
NewRun chooses the name of a run before it is started, so that an application can note it before anything is sent.
func (*Client) Receipt ¶
Receipt reads the controller's answer to a message this client sent. It gives nil while there is none.
func (*Client) Record ¶
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
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 ¶
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 ¶
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
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) Submit ¶ added in v0.17.0
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
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
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 ¶
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.
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 ¶
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
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) Run ¶ added in v0.17.0
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
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.
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.
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
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
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
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.
Source Files
¶
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. |