Documentation
¶
Overview ¶
Package client is the secret-free side of locksql: lockkit's client (dial, hello, call) with locksql's names and its SQL methods. The CLI client commands and the MCP server are built on it.
A call carries no client-side timeout: query.run waits for the human as long as the console allows (5 minutes for an approval). The caller's context is the only way to abandon a call, and abandoning one closes the connection, which the console sees as "client gone".
Index ¶
- Constants
- Variables
- func ErrorText(err error) string
- func FormatDescribe(w io.Writer, d Description)
- func FormatGrant(w io.Writer, r ipc.GrantResult)
- func FormatGrantInfo(g ipc.GrantInfo) string
- func FormatLimits(l config.Limits) string
- func FormatPII(w io.Writer, r PIIRules)
- func FormatPIIAdded(w io.Writer, pattern string, r PIIRules)
- func FormatPlan(w io.Writer, p ipc.PlanResult)
- func FormatProfiles(w io.Writer, list []ProfileStatus)
- func FormatRun(w io.Writer, r ipc.RunResult)
- func FormatStatus(w io.Writer, s ipc.StatusResult)
- func FormatTables(w io.Writer, t ipc.TablesResult)
- func Group(n int64) string
- func MaskedColumns(info engine.TableInfo, rules ipc.PIIListResult) []string
- func RefusalDetail(err error) string
- func ResolveInstance(flagValue string) (string, error)
- func RetryText(r refusal.Retry) string
- func ShellQuote(s string) string
- func SocketPath(cwd, profile string) (string, error)
- func SocketPathInstance(cwd, profile, instance string) (string, error)
- func StartCommand(profile, project string) string
- func WriteJSON(w io.Writer, v any) error
- type Client
- func (c *Client) ActivateGrant(ctx context.Context, ticket string) (ipc.GrantResult, error)
- func (c *Client) Describe(ctx context.Context, db, table string) (engine.TableInfo, error)
- func (c *Client) Grant(ctx context.Context, p ipc.GrantParams) (ipc.GrantResult, error)
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) PIIAdd(ctx context.Context, pattern string) (ipc.PIIListResult, error)
- func (c *Client) PIIList(ctx context.Context) (ipc.PIIListResult, error)
- func (c *Client) PIIUnmatched(ctx context.Context) (ipc.PIIUnmatchedResult, error)
- func (c *Client) Plan(ctx context.Context, p ipc.PlanParams) (ipc.PlanResult, error)
- func (c *Client) Request(ctx context.Context, change string) (ipc.ChangeResult, error)
- func (c *Client) Run(ctx context.Context, planID string) (ipc.RunResult, error)
- func (c *Client) RunTicket(ctx context.Context, ticket string) (ipc.RunResult, error)
- func (c *Client) Status(ctx context.Context) (ipc.StatusResult, error)
- func (c *Client) Tables(ctx context.Context, db string) (ipc.TablesResult, error)
- type Description
- type ErrorInfo
- type Locks
- type NoConsoleError
- type PIIChecker
- type PIIRules
- type ProfileStatus
Constants ¶
const FlagInstance = kclient.FlagInstance
FlagInstance is the name of the --instance flag.
const StartHint = kclient.StartHint
StartHint is what an agent asks of the user when no console runs; it carries no value.
Variables ¶
var ErrConsoleClosed = kclient.ErrConsoleClosed
ErrConsoleClosed means the console closed the connection before answering (the session ended, or the console stopped).
var ErrNoConsole = kclient.ErrNoConsole
ErrNoConsole means no console listens for the profile. Errors that match it are *NoConsoleError values carrying the command the human must run.
var Requester = mcpkit.RequesterFromEnv
Requester is the agent behind the plan and run requests: from lea's environment (mcpkit.RequesterFromEnv), empty outside lea. A plan or ticket runs only for the agent that asked for it.
Functions ¶
func ErrorText ¶
ErrorText is the one-line text form of err: "<kind>: <message>" for console errors, the message alone otherwise.
func FormatDescribe ¶
func FormatDescribe(w io.Writer, d Description)
FormatDescribe writes a header, the columns as TSV (column, type, null, key, default, pii) and the indexes.
func FormatGrant ¶ added in v0.16.0
func FormatGrant(w io.Writer, r ipc.GrantResult)
FormatGrant writes the answer of a grant request: pending with its ticket, or the active grant.
func FormatGrantInfo ¶ added in v0.16.0
FormatGrantInfo renders an active grant on one line: its id, scope, time left and what is left of its budget.
func FormatLimits ¶
FormatLimits renders limits on one line; 0 means unlimited.
func FormatPII ¶
FormatPII writes the rules as "mask<TAB>pattern" and "allow<TAB>pattern", a rule that names no column flagged.
func FormatPIIAdded ¶ added in v0.18.0
FormatPIIAdded confirms a mask rule added, with a warning when it names no column yet (a glob: the console refuses any other such pattern).
func FormatPlan ¶
func FormatPlan(w io.Writer, p ipc.PlanResult)
FormatPlan writes a plan and the command that runs it.
func FormatProfiles ¶
func FormatProfiles(w io.Writer, list []ProfileStatus)
FormatProfiles writes one block per profile: the status of a running console, or how to start it.
func FormatStatus ¶
func FormatStatus(w io.Writer, s ipc.StatusResult)
FormatStatus writes the console status as aligned "key value" lines.
func FormatTables ¶
func FormatTables(w io.Writer, t ipc.TablesResult)
FormatTables writes one table name per line.
func MaskedColumns ¶
func MaskedColumns(info engine.TableInfo, rules ipc.PIIListResult) []string
MaskedColumns lists the columns of info that the rules mask.
func RefusalDetail ¶ added in v0.5.0
RefusalDetail is the structured part of a refusal as text lines: where it points, the hint and the retry rule; "" for any other error.
func ResolveInstance ¶ added in v0.14.0
ResolveInstance is the lock instance the client reaches: flagValue (the --instance flag) or what the environment names; "" when there is one lock of this type or none.
func ShellQuote ¶ added in v0.1.2
ShellQuote quotes s for a POSIX shell when it holds anything beyond letters, digits and ./_-+:,@%=.
func SocketPath ¶
SocketPath is the console socket of profile for the project of cwd.
func SocketPathInstance ¶ added in v0.14.0
SocketPathInstance is SocketPath of the lock instance (ResolveInstance) when several locks of this type share the machine. With instance "" it is SocketPath.
func StartCommand ¶
StartCommand is the command that starts the console: `lox run`, for every profile and project (a console is started by `lox run` only, so no profile or project value is put in it).
Types ¶
type Client ¶
Client is one connection to a console. Calls are serialised.
func Dial ¶
Dial connects to the console of profile for the project of cwd. It returns a *NoConsoleError (matching ErrNoConsole) when none is running. The hello handshake happens on the first call, under that call's context.
func DialInstance ¶ added in v0.14.0
DialInstance is Dial to the lock instance (ResolveInstance). With instance "" it is Dial.
func (*Client) ActivateGrant ¶ added in v0.16.0
ActivateGrant activates the grant of a decided ticket: from then on, the reads it covers run without a ticket, for its duration and within its budget.
func (*Client) Grant ¶ added in v0.16.0
func (c *Client) Grant(ctx context.Context, p ipc.GrantParams) (ipc.GrantResult, error)
Grant asks for a grant: one human decision for reads of the tables of p within a duration and a budget. It answers pending with the ticket the human decides in lockhub; activate it with ActivateGrant once decided.
func (*Client) PIIAdd ¶
PIIAdd adds a mask rule "db.table.column" (a tightening, applied at once) and returns the rules in force.
func (*Client) PIIUnmatched ¶ added in v0.18.0
PIIUnmatched returns the rules in force that name no column of the catalog.
func (*Client) Plan ¶
func (c *Client) Plan(ctx context.Context, p ipc.PlanParams) (ipc.PlanResult, error)
Plan validates and weighs a statement and returns a one-shot plan.
func (*Client) Request ¶
Request queues a policy change proposal for the human. It never changes the policy itself.
func (*Client) Run ¶
Run asks the human to approve a plan and returns its result. It waits as long as the console does: there is no client-side timeout.
func (*Client) RunTicket ¶ added in v0.10.0
RunTicket runs the plan of a ticket decided in lockhub (hub mode).
type Description ¶
Description is a table description with the columns the PII rules mask.
type ErrorInfo ¶
type ErrorInfo struct {
Kind string `json:"kind"`
Code int `json:"code,omitempty"`
Message string `json:"message"`
// Start is the command that starts the console (kind no_console).
Start string `json:"start,omitempty"`
// Refusal is the structured form of a refusal (kind refused): its
// code, retry rule, hint and the place of the statement it points at.
Refusal *refusal.Info `json:"refusal,omitempty"`
}
ErrorInfo is the --json form of a failed command.
func DescribeError ¶
DescribeError classifies err for output: kind is one of no_console, refused, denied, timeout, no_such_plan, connection_lost, policy_pending, invalid_params, console_closed, cancelled or error.
type Locks ¶ added in v0.18.0
type Locks struct {
// contains filtered or unexported fields
}
Locks are the locksql locks a client of the project of a directory reaches, and which of them serves each profile.
lea mounts each lock of the agent's workspace on <shared socket dir>/<instance> and lists their names in LEA_LOCKSQL_INSTANCES. With one lock, or one chosen by --instance or LOCKSQL_INSTANCE, every profile is dialled on that lock. With several and none chosen, a profile is dialled on the lock whose directory holds its console socket: profile names are unique in a workspace, so one server or command reaches them all.
Nothing here is locksql-specific beyond product.P: it is the shape a lockkit client.Locks would take for every lock type.
func ResolveLocks ¶ added in v0.18.0
ResolveLocks resolves the locks of the project of cwd reached with flagValue (the --instance flag): ResolveInstance, except that several mounted locks and none chosen is not an error but routing by profile. Every name is checked before any path is built; errors never echo one.
func (Locks) Filter ¶ added in v0.18.0
Filter keeps the profiles of names these locks serve (Serves).
func (Locks) Instance ¶ added in v0.18.0
Instance is the instance that serves profile. When routing, it is the one whose directory holds the profile's console socket; a *NoConsoleError when none does, and an error naming the instances when several do.
func (Locks) Serves ¶ added in v0.18.0
Serves reports whether profile belongs on these locks. It is false only when one lock is chosen among those lea mounted and the profile's console socket is in another of them: that profile is another lock's, and a server bound to this one neither reports it nor counts it.
type NoConsoleError ¶
type NoConsoleError = kclient.NoConsoleError
NoConsoleError reports a missing console and how to start it.
type PIIChecker ¶ added in v0.18.0
type PIIChecker interface {
PIIUnmatched(ctx context.Context) (ipc.PIIUnmatchedResult, error)
}
PIIChecker reads the rules that name no column (pii.unmatched).
type PIIRules ¶ added in v0.18.0
type PIIRules struct {
Mask []string `json:"mask"`
Allow []string `json:"allow"`
// UnmatchedMask and UnmatchedAllow are the rules that name no column.
UnmatchedMask []string `json:"unmatched_mask"`
UnmatchedAllow []string `json:"unmatched_allow"`
// Unchecked says why the rules could not be checked against the
// catalog, "" when they were.
Unchecked string `json:"unchecked,omitempty"`
}
PIIRules are the rules in force and those of them that name no column of the catalog (dead rules: a mask rule that masks nothing).
func CheckPII ¶ added in v0.18.0
func CheckPII(ctx context.Context, c PIIChecker, r ipc.PIIListResult) PIIRules
CheckPII returns r with its rules checked against the catalog. A console that cannot check them leaves Unchecked set.
type ProfileStatus ¶
type ProfileStatus struct {
Profile string `json:"profile"`
Running bool `json:"running"`
Status *ipc.StatusResult `json:"status,omitempty"`
// Start is the command that starts the console, when none runs.
Start string `json:"start,omitempty"`
// Error is set when the console could not be asked.
Error string `json:"error,omitempty"`
}
ProfileStatus is one line of `locksql status` without a profile: every configured profile, with the console status when one runs.