Documentation
¶
Overview ¶
Package client is the secret-free side of locksql: it dials the console socket of a project and profile and calls the console's JSON-RPC 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 ¶
- Variables
- func ErrorText(err error) string
- func FormatDescribe(w io.Writer, d Description)
- func FormatLimits(l config.Limits) string
- func FormatPII(w io.Writer, r ipc.PIIListResult)
- 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 RetryText(r refusal.Retry) string
- func ShellQuote(s string) string
- func SocketPath(cwd, profile string) (string, error)
- func StartCommand(profile, project string) string
- func WriteJSON(w io.Writer, v any) error
- type Client
- func (c *Client) Call(ctx context.Context, method string, params, result any) error
- func (c *Client) Close() error
- func (c *Client) Describe(ctx context.Context, db, table string) (engine.TableInfo, 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) Plan(ctx context.Context, p ipc.PlanParams) (ipc.PlanResult, error)
- func (c *Client) Profile() string
- 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) Status(ctx context.Context) (ipc.StatusResult, error)
- func (c *Client) Tables(ctx context.Context, db string) (ipc.TablesResult, error)
- type Description
- type ErrorInfo
- type NoConsoleError
- type ProfileStatus
Constants ¶
This section is empty.
Variables ¶
var ErrConsoleClosed = errors.New("the console closed the connection")
ErrConsoleClosed means the console closed the connection before answering (the session ended, or the console stopped).
var ErrNoConsole = errors.New("no console is running")
ErrNoConsole means no console listens for the profile. Errors that match it are *NoConsoleError values carrying the command the human must run.
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 FormatLimits ¶
FormatLimits renders limits on one line; 0 means unlimited.
func FormatPII ¶
func FormatPII(w io.Writer, r ipc.PIIListResult)
FormatPII writes the rules as "mask<TAB>pattern" and "allow<TAB>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 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. The console computes the same path: in the shared socket directory when the machine separates the console from the agent (sysconf), in the user's runtime directory otherwise.
func StartCommand ¶
StartCommand is the exact command that starts the console for profile (left out when empty) on project (left out when "": the user config).
Types ¶
type Client ¶
type Client struct {
// Name identifies the client in the hello handshake ("locksql" when
// empty).
Name string
// ConsoleVersion is the console's version, known after the first call.
ConsoleVersion string
// contains filtered or unexported fields
}
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 (*Client) Call ¶
Call sends one request and decodes its result into result (nil to ignore it). A console error is returned as *ipc.RPCError. Numbers in result decode as json.Number when result holds interface values.
func (*Client) PIIAdd ¶
PIIAdd adds a mask rule "db.table.column" (a tightening, applied at once) and returns the rules in force.
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.
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 NoConsoleError ¶
type NoConsoleError struct {
Profile string
// Project is the project root of the client's directory, "" outside
// any project. The console must serve the same project.
Project string
Socket string
Err error
}
NoConsoleError reports a missing console and how to start it.
func (*NoConsoleError) Command ¶ added in v0.1.2
func (e *NoConsoleError) Command() string
Command is the exact command that starts the missing console.
func (*NoConsoleError) Error ¶
func (e *NoConsoleError) Error() string
func (*NoConsoleError) Hint ¶ added in v0.1.2
func (e *NoConsoleError) Hint() string
Hint tells the agent what to ask of the user. Inside a project, only a console started on that project serves the agent, so the hint names it; outside one, the hint asks for the project's directory, since the console runs in the locksql account and reads the profiles from the project's config.
func (*NoConsoleError) Is ¶
func (e *NoConsoleError) Is(target error) bool
Is makes errors.Is(err, ErrNoConsole) true.
func (*NoConsoleError) Unwrap ¶
func (e *NoConsoleError) Unwrap() error
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.