Documentation
¶
Overview ¶
Package localapi is how a process on this machine reaches the running cockpit. The assistant answers from a coder process that has a shell, so it could touch the state files directly, and that is exactly what it must not do: a state directory belongs to one serve process, and a second writer would bypass its caches and its event stream. Instead the server listens on a unix socket inside its own state directory, and everything that changes state goes through the same HTTP surface a browser uses.
The socket is the whole credential. Opening it means being on this machine with permission to enter a directory the server owns, so nothing here mints, stores, rotates or compares a token, and nothing is left behind that a later process would have to invalidate.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Listen ¶
Listen binds the socket for one serve process. A socket file a dead process left behind is removed first: nothing listens on it, so it can only refuse connections.
func SocketPath ¶
SocketPath is where the cockpit of one state directory listens. It is derived from the state directory alone, so a caller needs nothing but the flag it already passes, and the server and the command always agree.
A state directory whose path is too long for a socket falls back to a private directory in the system temp directory, named after it. Refusing to start over the length of a path the user chose for something else would be the worst kind of failure: nothing about --state-dir suggests it has a length limit.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a caller on this machine. It speaks plain HTTP over the socket, so the server sees the requests a browser makes and answers them in the same handlers.
func Dial ¶
Dial returns a client for the cockpit of one state directory. It probes the socket and waits out a restart window: a missing socket file and a refused connection are retried until the budget is spent, everything else, and the spent budget, answer with the message that no cockpit is running.
The waiting lives here and not in the transport's DialContext on purpose. Only the connection probe may ever be repeated: a request is one attempt with its own timeout, a repeated send would double a prompt. And the request timeouts are partly shorter than this budget, so a retry inside the request would be cut off before the budget mattered; Dial has no context, the budget collides with nothing.