shims

package
v1.28.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package shims is the single owner of the client-tool host shims that lerd services expose (mysqldump, pg_dump, psql…): the tri-state install decisions, host-conflict detection, script generation, and the reconcile that brings the shim dir in line with the installed services.

Scope is deliberately just these service client tools. The php/composer/node shims are a different category (always-on or a single global toggle, exec on the host or into the FPM container) and stay owned by the installer's addShellShims and the shim_sync mirror; they are intentionally not managed here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reconcile

func Reconcile(prompt Prompter) error

Reconcile brings the host shim dir in line with the tools the installed services expose and the recorded decisions. prompt resolves a host-conflict on first sight; pass nil on non-interactive paths (a removal, an update reconcile) to leave conflicts undecided. Shims for tools no longer exposed by any installed service are pruned.

func Set

func Set(tool string, enabled bool) error

Set is the single entry point for an explicit shim decision, shared by the CLI (`lerd shims add/remove`) and the web UI toggle. It validates that an installed service actually exposes the tool, records the decision, and reconciles so the change takes effect at once. It never prompts.

func Targets

func Targets() map[string]Target

Targets maps every client tool exposed by an installed service to the container and candidate binaries that back it. The first installed service to declare a given tool name wins, so a mysql and a mariadb install both exposing `mysql` resolve deterministically.

func ToolOwner

func ToolOwner(tool string) string

ToolOwner returns the installed service that backs the tool's shim, or "" when no installed service exposes it. Used to guard toggles so a shared shim is only managed from its owner.

Types

type Info

type Info struct {
	Tool    string `json:"tool"`
	Service string `json:"service,omitempty"`
	Owner   string `json:"owner,omitempty"`
	HostHas bool   `json:"host_has"`
	Enabled bool   `json:"enabled"`
	Decided bool   `json:"decided"`
}

Info is the per-tool shim state the CLI and web UI render: which service backs it, whether the host already has the tool (so callers can warn before shadowing it), whether a decision has been recorded, and whether it's on. Owner is the service that actually backs the shim when several same-family services expose the same tool; a service whose name differs from Owner does not manage the shim and its toggle is shown disabled.

func List

func List() []Info

List returns every exposed client tool with its state, sorted by tool name, for the `lerd shims` listing.

func ServiceShims

func ServiceShims(name string) []Info

ServiceShims returns the client-tool shim state for one installed service, one entry per tool it declares. Owner is filled from the global targets so a service that only shares a same-family tool (not its owner) is marked. Empty when the service exposes none.

type Prompter

type Prompter func(tool string) (enable, decided bool)

Prompter resolves a host-conflict when the host already has a tool. It returns whether to enable the shim and whether a decision was actually made. A nil Prompter leaves the conflict undecided so a later interactive run or the web UI can resolve it.

type Target

type Target struct {
	Service  string
	Binaries []string
}

Target records which service container a tool shim execs into and the candidate binaries to resolve there (mariadb images ship mariadb-dump in place of mysqldump, so the shim tries each in order).

func ResolveTarget

func ResolveTarget(tool, prefer string) (Target, bool)

ResolveTarget picks the container and binaries to run a tool in. When prefer names an installed service that exposes the tool, it wins (site-aware routing: a dump run from a project targets that project's own database service). Otherwise it falls back to the global owner. The bool is false only when no installed service exposes the tool at all.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL