Documentation
¶
Index ¶
- Constants
- func CleanupBudget(ctx context.Context) time.Duration
- func CloseMachine(ctx context.Context, client *pg.MachineClient) error
- func Dispatch(parent context.Context, args []string, streams IO, registry map[string]Command) (bool, int)
- func IsLegacyRoute(args []string) bool
- func LoadProfiles(fs afero.Fs, path string) ([]models.Connection, error)
- func ParseFlags(args []string, values, switches []string) (map[string]string, []string, error)
- func ReadParameters(ctx context.Context, path string) ([][]byte, error)
- func ReadSQL(ctx context.Context, path string, stdin io.ReadCloser) (string, error)
- func ResolveExactProfile(profiles []models.Connection, name string) (models.Connection, error)
- func WriteJSON(ctx context.Context, out io.WriteCloser, envelope Envelope) error
- type ApprovalProvider
- type ApprovalRequest
- type Command
- type Envelope
- type ErrorCode
- type IO
- type InvocationService
- type PublicError
- type PublicProfile
Constants ¶
const ( InvocationTimeout = 30 * time.Second ConnectionTimeout = 10 * time.Second HelperTimeout = 5 * time.Second StatementTimeout = 10 * time.Second LockTimeout = time.Second CleanupTimeout = 2 * time.Second MaxHelperBytes = 32 << 10 )
const ( ExitSuccess = 0 ExitInput = 2 ExitPolicy = 4 ExitDatabase = 5 ExitTimeout = 6 ExitResource = 7 )
const ( MaxInputBytes = 1 << 20 MaxOutputBytes = 1 << 20 MaxParameters = 256 MaxProfileBytes = 256 DefaultRows = 100 MaxRows = 1000 MaxCellBytes = 64 << 10 )
Variables ¶
This section is empty.
Functions ¶
func CleanupBudget ¶
CleanupBudget is fresh time reserved inside the invocation's outer deadline.
func CloseMachine ¶
func CloseMachine(ctx context.Context, client *pg.MachineClient) error
func Dispatch ¶
func Dispatch(parent context.Context, args []string, streams IO, registry map[string]Command) (bool, int)
Dispatch never enters the legacy application. The caller composes its registry.
func IsLegacyRoute ¶
IsLegacyRoute recognizes valid legacy route words without admitting ignored positional command words into the TUI. The legacy app still validates values.
func LoadProfiles ¶
func ParseFlags ¶
ParseFlags accepts exact long names and preserves positional names literally.
func ResolveExactProfile ¶
func ResolveExactProfile(profiles []models.Connection, name string) (models.Connection, error)
Types ¶
type ApprovalProvider ¶ added in v0.15.0
type ApprovalProvider func(context.Context, ApprovalRequest) error
func NewTerminalApprovalProvider ¶ added in v0.15.0
func NewTerminalApprovalProvider(open func(context.Context) (io.ReadWriteCloser, error)) ApprovalProvider
NewTerminalApprovalProvider takes ownership of each acquired handle. Close must interrupt and join concurrent I/O, as with the machineio stream contract.
type ApprovalRequest ¶ added in v0.15.0
type ApprovalRequest struct {
Connection, SQL, Schema string
MaxRows, ParameterCount, StatementCount int
WritesApprovalRequired, DDLApprovalRequired bool
}
ApprovalRequest is a captured invocation, without parameters or credentials.
type Command ¶
Command returns only after its backend operation and cleanup have completed.
func CapabilitiesCommand ¶
func CapabilitiesCommand() Command
func ConnectionsCommand ¶
func ConnectionsCommand(service InvocationService) Command
func LLMHelpCommand ¶ added in v0.15.0
func LLMHelpCommand() Command
LLMHelpCommand is static discovery: no service, files, stdin or credentials.
func QueryCommand ¶
func QueryCommand(service InvocationService) Command
func SchemaCommand ¶
func SchemaCommand(service InvocationService) Command
type Envelope ¶
type Envelope struct {
SchemaVersion int `json:"schema_version"`
OK bool `json:"ok"`
Command string `json:"command"`
Connection string `json:"connection,omitempty"`
Data any `json:"data,omitempty"`
Error *PublicError `json:"error,omitempty"`
Warnings []ErrorCode `json:"warnings"`
ResultComplete bool `json:"result_complete"`
Truncated bool `json:"truncated"`
TruncationReason string `json:"truncation_reason,omitempty"`
Execution *executionMetadata `json:"execution,omitempty"`
}
type ErrorCode ¶
type ErrorCode string
const ( InvalidInput ErrorCode = "INVALID_INPUT" UnsupportedSQL ErrorCode = "UNSUPPORTED_SQL" TrustRequired ErrorCode = "TRUST_REQUIRED" UnsupportedPgpassFailover ErrorCode = "UNSUPPORTED_PGPASS_FAILOVER" PolicyDenied ErrorCode = "POLICY_DENIED" ApprovalRequired ErrorCode = "APPROVAL_REQUIRED" ApprovalMismatch ErrorCode = "APPROVAL_MISMATCH" ApprovalCancelled ErrorCode = "APPROVAL_CANCELLED" IncompleteTransaction ErrorCode = "INCOMPLETE_TRANSACTION" DatabaseFailure ErrorCode = "DATABASE_FAILURE" ObjectNotFound ErrorCode = "OBJECT_NOT_FOUND" Timeout ErrorCode = "TIMEOUT" ResourceFailure ErrorCode = "RESOURCE_FAILURE" HistoryUpgradeRequired ErrorCode = "HISTORY_UPGRADE_REQUIRED" )
type IO ¶
type IO struct {
In io.ReadCloser
Out, Err io.WriteCloser
// Cancel interrupts operation/input work without prematurely closing output.
Cancel <-chan struct{}
}
IO handles belong to one invocation. Close must interrupt concurrent I/O.
type InvocationService ¶
type InvocationService struct {
Load func() ([]models.Connection, error)
Options pg.MachineOptions
Approve ApprovalProvider
// contains filtered or unexported fields
}
func (InvocationService) Open ¶
func (s InvocationService) Open(ctx context.Context, name string, required models.CLIAccess) (*pg.MachineClient, models.Connection, error)
func (InvocationService) Profiles ¶
func (s InvocationService) Profiles() ([]models.Connection, error)
type PublicError ¶
PublicError contains only allowlisted output, never backend error text.
func PublicMachineError ¶
func PublicMachineError(err error) *PublicError
func (*PublicError) Error ¶
func (e *PublicError) Error() string
func (*PublicError) MarshalJSON ¶
func (e *PublicError) MarshalJSON() ([]byte, error)
type PublicProfile ¶
type PublicProfile struct {
Name string `json:"name"`
Driver string `json:"driver"`
Tags []string `json:"tags"`
Label string `json:"label"`
CLIAccess models.CLIAccess `json:"cli_access"`
ReadOnly bool `json:"read_only"`
CredentialStatus string `json:"credential_status"`
}
PublicProfile is an explicit allowlist, never a serialized connection config.
func PublicConnection ¶
func PublicConnection(profile models.Connection) PublicProfile