state

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package state owns Breadboard's files: the install home (BB_HOME) and each project's .bb/ directory. Writes are atomic, state-changing operations hold an advisory lock, and every versioned file only upgrades forward.

Index

Constants

View Source
const (
	StateFormat   = 1
	SecretsFormat = 1
)

Format versions of the project state files.

View Source
const (
	LeafCert = "tls"
	HostCert = "host"
)

Names of a service's certificate pairs under certs/<service>/: its lab leaf, and for the host router its host certificate (host.crt, host.key).

View Source
const (
	DirName = ".bb"
)

Directory and file names inside a project.

View Source
const HomeEnv = "BB_HOME"

HomeEnv overrides the install home.

Variables

This section is empty.

Functions

func DefaultHomeDir

func DefaultHomeDir() (string, error)

DefaultHomeDir returns $BB_HOME, or <user config dir>/breadboard.

func WriteFile

func WriteFile(path string, data []byte, perm os.FileMode) error

WriteFile writes data atomically: a temp file in the same directory is written, synced, given perm, and renamed over path. A crash leaves either the old file or the new one, never a partial file.

Types

type BusyError

type BusyError struct {
	Operation string
	PID       int
	Since     time.Time
}

BusyError reports the operation holding the lock. It matches errs.ErrBusy.

func (*BusyError) Error

func (e *BusyError) Error() string

func (*BusyError) Is

func (e *BusyError) Is(target error) bool

Is makes errors.Is(err, errs.ErrBusy) true.

type CertRecord

type CertRecord struct {
	Issuer   string    `json:"issuer"`
	Serial   string    `json:"serial"`
	NotAfter time.Time `json:"notAfter"`
}

CertRecord describes an issued leaf certificate.

type Home

type Home struct {
	Dir string
}

Home is the install home: settings and certificate authorities.

func (Home) CACertPath

func (h Home) CACertPath(name string) string

CACertPath is the certificate file of the named CA.

func (Home) CADir

func (h Home) CADir() string

CADir holds one certificate and key pair per CA name.

func (Home) ConfigPath

func (h Home) ConfigPath() string

ConfigPath is the install settings file.

func (Home) Ensure

func (h Home) Ensure() (created bool, err error)

Ensure creates the home and CA directories with mode 0700 and reports whether the home was created.

func (Home) LoadCA

func (h Home) LoadCA(name string) (certPEM, keyPEM []byte, ok bool, err error)

LoadCA reads the named CA's certificate and key PEM, or ok=false.

func (Home) LockCA

func (h Home) LockCA(operation string) (*Lock, error)

LockCA takes the install-wide CA lock, waiting while another bb process holds it. Every project shares the CA, so project locks cannot protect it: hold this lock from reading the CA until any replacement is saved.

func (Home) SaveCA

func (h Home) SaveCA(name string, certPEM, keyPEM []byte) error

SaveCA writes the named CA: the key first (0600), then the certificate (0644).

type Lock

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

Lock is a held advisory lock on a project's .bb/lock file.

func (*Lock) Release

func (l *Lock) Release() error

Release drops the lock.

type Project

type Project struct {
	Dir string // the directory holding experiment.yaml
}

Project is one experiment's directory and its .bb/ state.

func (Project) CertServices

func (p Project) CertServices() ([]string, error)

CertServices lists services with a stored certificate.

func (Project) Ensure

func (p Project) Ensure(bbVersion string) (created bool, err error)

Ensure creates any missing part of .bb/: the directory (0700) with its self-ignoring .gitignore, the certs and runtime directories, state.json, and secrets.json (0600). Existing files are left alone. It reports whether the .bb directory itself was created.

func (Project) LoadSecrets

func (p Project) LoadSecrets() (*Secrets, error)

LoadSecrets reads secrets.json.

func (Project) LoadState

func (p Project) LoadState() (*ProjectState, error)

LoadState reads state.json, upgrading older formats in memory.

func (Project) Lock

func (p Project) Lock(operation string) (*Lock, error)

Lock takes the project's exclusive operation lock, or returns a *BusyError.

func (Project) ReadCert

func (p Project) ReadCert(service string) (certPEM, keyPEM []byte, ok bool, err error)

ReadCert returns a service's stored certificate and key, or ok=false.

func (Project) ReadNamedCert

func (p Project) ReadNamedCert(service, name string) (certPEM, keyPEM []byte, ok bool, err error)

ReadNamedCert returns the pair <name>.crt and <name>.key stored for a service, or ok=false.

func (Project) RemoveCert

func (p Project) RemoveCert(service string) error

RemoveCert deletes a service's stored certificate, if any.

func (Project) RemoveNamedCert

func (p Project) RemoveNamedCert(service, name string) error

RemoveNamedCert deletes a service's pair <name>.crt and <name>.key, if present, leaving its other files.

func (Project) RuntimeDir

func (p Project) RuntimeDir() string

RuntimeDir holds the generated compose project.

func (Project) SaveSecrets

func (p Project) SaveSecrets(s *Secrets) error

SaveSecrets writes secrets.json with mode 0600.

func (Project) SaveState

func (p Project) SaveState(st *ProjectState, bbVersion string) error

SaveState writes state.json, stamping the format and the bb version.

func (Project) StateDir

func (p Project) StateDir() string

StateDir is the project's .bb directory.

func (Project) WriteCert

func (p Project) WriteCert(service string, certPEM, keyPEM []byte) error

WriteCert stores a service's certificate (0644) and key (0600).

func (Project) WriteNamedCert

func (p Project) WriteNamedCert(service, name string, certPEM, keyPEM []byte) error

WriteNamedCert stores a service's pair <name>.crt (0644) and <name>.key (0600).

type ProjectState

type ProjectState struct {
	FormatVersion int    `json:"formatVersion"`
	BBVersion     string `json:"bbVersion"`
	ExperimentID  string `json:"experimentId"`
	// Certificates records which CA issued each service's leaf.
	Certificates map[string]CertRecord `json:"certificates"`
	// Segments maps each private network segment to its allocated subnet.
	Segments map[string]string `json:"segments"`
	// Network is the default network's allocated subnet, set while the
	// experiment has a transparent pod (whose egress policy allows
	// destinations by address).
	Network string `json:"network,omitempty"`
	// Addresses maps each container on the default network (an infra
	// service, an app instance, or a pod holder) to its fixed address in
	// Network, so addresses survive bb up.
	Addresses map[string]string `json:"addresses,omitempty"`
	// HostPort is the 127.0.0.1 port the host router is published on,
	// chosen by the first bb up with a host target and kept while it stays
	// free, even after the last host target goes (D-190).
	HostPort int `json:"hostPort,omitempty"`
}

ProjectState is .bb/state.json.

type Secrets

type Secrets struct {
	FormatVersion int                          `json:"formatVersion"`
	Services      map[string]map[string]string `json:"services"`
}

Secrets is .bb/secrets.json: generated values per service.

func (*Secrets) Get

func (s *Secrets) Get(service, key string) (string, bool)

Get returns a service's secret.

func (*Secrets) Set

func (s *Secrets) Set(service, key, value string)

Set stores a service's secret.

Jump to

Keyboard shortcuts

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