bootstrap

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDBEncrypted

func IsDBEncrypted(dbPath string) bool

IsDBEncrypted checks whether a SQLite database file is encrypted. An encrypted DB will not have the standard "SQLite format 3" magic header.

Types

type Options

type Options struct {
	// DBPath is the SQLite database path (default: ~/.lango/lango.db).
	DBPath string
	// KeyfilePath is the path to the passphrase keyfile (default: ~/.lango/keyfile).
	KeyfilePath string
	// ForceProfile overrides the active profile selection.
	ForceProfile string
	// KeepKeyfile prevents the keyfile from being shredded after crypto initialization.
	// Default (false) shreds the keyfile for security.
	KeepKeyfile bool
	// DBEncryption configures SQLCipher transparent database encryption.
	DBEncryption config.DBEncryptionConfig
	// SkipSecureDetection disables secure hardware provider detection (biometric/TPM).
	// When true, the bootstrap falls back to keyfile or interactive prompt only.
	// Useful for testing and headless environments.
	SkipSecureDetection bool
}

Options configures the bootstrap process.

type Phase

type Phase struct {
	Name    string
	Run     func(ctx context.Context, state *State) error
	Cleanup func(state *State) // called in reverse order if a later phase fails
}

Phase represents a single step in the bootstrap pipeline.

func DefaultPhases

func DefaultPhases() []Phase

DefaultPhases returns the standard bootstrap phase sequence.

type Pipeline

type Pipeline struct {
	// contains filtered or unexported fields
}

Pipeline executes phases sequentially. If a phase fails, cleanup functions of all previously completed phases are called in reverse order.

func NewPipeline

func NewPipeline(phases ...Phase) *Pipeline

NewPipeline creates a pipeline from the given phases.

func (*Pipeline) Execute

func (p *Pipeline) Execute(ctx context.Context, opts Options) (*Result, error)

Execute runs all phases. On failure, cleans up in reverse order.

type Result

type Result struct {
	// Config is the decrypted, active configuration.
	Config *config.Config
	// DBClient is the shared ent.Client for the application database.
	DBClient *ent.Client
	// RawDB is the underlying *sql.DB for direct SQL operations (e.g., sqlite-vec).
	RawDB *sql.DB
	// Crypto is the initialized CryptoProvider for the session.
	Crypto security.CryptoProvider
	// ConfigStore provides encrypted profile CRUD operations.
	ConfigStore *configstore.Store
	// ProfileName is the name of the loaded profile.
	ProfileName string
}

Result holds everything produced by the bootstrap process.

func Run

func Run(opts Options) (*Result, error)

Run executes the full bootstrap sequence using the phase pipeline:

  1. Ensure ~/.lango/ directory
  2. Detect DB encryption status
  3. Acquire passphrase
  4. Open SQLite/SQLCipher DB + ent schema migration
  5. Load security state (salt/checksum)
  6. Initialize crypto provider
  7. Load or create configuration profile

type State

type State struct {
	Options Options
	Result  Result

	// Internal state passed between phases.
	Home     string
	LangoDir string

	// Encryption detection.
	DBEncrypted bool
	NeedsDBKey  bool

	// Passphrase acquisition.
	Passphrase     string
	PassSource     passphrase.Source
	SecureProvider keyring.Provider
	SecurityTier   keyring.SecurityTier
	FirstRunGuess  bool

	// Database handles (set by phaseOpenDatabase).
	Client *ent.Client
	RawDB  *sql.DB

	// Security state from DB.
	Salt     []byte
	Checksum []byte
	FirstRun bool

	// Crypto.
	DBKey  string
	Crypto security.CryptoProvider
}

State carries data between pipeline phases. Each phase can read from and write to State.

Jump to

Keyboard shortcuts

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