preflight

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package preflight checks a command's requirements before it starts doing work.

Two kinds matter. pgtransfer drives PostgreSQL's own client tools, so a machine without pg_dump or pg_restore cannot dump or restore at all. And a tunnelled profile needs an SSH identity the tunnel can present. Either one missing otherwise surfaces part-way through: a migration that has already written its archive, an import that fails on its first batch. The checks here are cheap — a PATH lookup, a stat — and run once, up front, so the message names what to install or which profile field to set.

Index

Constants

This section is empty.

Variables

View Source
var (
	PgDump    = Tool{"pg_dump", "export dump and migrate database"}
	PgRestore = Tool{"pg_restore", "restoring a custom, tar or directory archive"}
	Psql      = Tool{"psql", "restoring a plain SQL dump"}
)

The tools pgtransfer invokes.

View Source
var Lookup = func(name string) (string, error) { return exec.LookPath(name) }

Lookup reports whether name is on PATH.

It is a variable so tests can stand in for the real PATH.

Functions

func AgentAvailable

func AgentAvailable() bool

AgentAvailable reports whether an SSH agent is reachable.

It looks at the environment variable only: connecting to the socket is what BuildAuthMethods does, and that error is more informative from there.

func Check

func Check(tools ...Tool) error

Check returns a *MissingError naming every tool in tools that is not on PATH. It reports all of them at once: being told about one missing binary, fixing it, and being told about the next is a worse experience than one list.

func CheckProfiles

func CheckProfiles(profiles ...ProfileSSH) error

CheckProfiles checks the SSH identity of every profile in profiles that has SSH enabled. It returns the first problem, naming the profile it belongs to.

A migration has two ends and either may be tunnelled, so both are checked before the archive is written.

func CheckSSHIdentity

func CheckSSHIdentity(id SSHIdentity) error

CheckSSHIdentity reports why a tunnelled profile cannot authenticate.

The order mirrors BuildAuthMethods: an agent first, then an explicit key, then a password. A profile needs at least one of them, and a key path that is set but unreadable is an error even when a password is also present, because the profile says the key is what it wants to use.

Types

type MissingError

type MissingError struct {
	Tools []Tool
}

MissingError reports a tool that is not on PATH.

func (*MissingError) Error

func (e *MissingError) Error() string

type ProfileSSH

type ProfileSSH struct {
	Name       string
	Enabled    bool
	KeyPath    string
	Passphrase string
	Password   string
}

ProfileSSH describes one end of a transfer, for a tunnel check.

It is defined here rather than taking config.Profile so that this package stays free of the config import, matching sshx.

type SSHIdentity

type SSHIdentity struct {
	KeyPath    string
	Passphrase string
	Password   string
	// AgentAvailable reports whether SSH_AUTH_SOCK points at a usable agent.
	AgentAvailable bool
}

SSHIdentity describes the credentials a tunnelled profile will present.

type Tool

type Tool struct {
	Name string // the executable, as looked up on PATH
	Why  string // what needs it, for the error message
}

Tool is an external program pgtransfer may need.

Jump to

Keyboard shortcuts

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