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
- func DefaultHomeDir() (string, error)
- func WriteFile(path string, data []byte, perm os.FileMode) error
- type BusyError
- type CertRecord
- type Home
- func (h Home) CACertPath(name string) string
- func (h Home) CADir() string
- func (h Home) ConfigPath() string
- func (h Home) Ensure() (created bool, err error)
- func (h Home) LoadCA(name string) (certPEM, keyPEM []byte, ok bool, err error)
- func (h Home) LockCA(operation string) (*Lock, error)
- func (h Home) SaveCA(name string, certPEM, keyPEM []byte) error
- type Lock
- type Project
- func (p Project) CertServices() ([]string, error)
- func (p Project) Ensure(bbVersion string) (created bool, err error)
- func (p Project) LoadSecrets() (*Secrets, error)
- func (p Project) LoadState() (*ProjectState, error)
- func (p Project) Lock(operation string) (*Lock, error)
- func (p Project) ReadCert(service string) (certPEM, keyPEM []byte, ok bool, err error)
- func (p Project) ReadNamedCert(service, name string) (certPEM, keyPEM []byte, ok bool, err error)
- func (p Project) RemoveCert(service string) error
- func (p Project) RemoveNamedCert(service, name string) error
- func (p Project) RuntimeDir() string
- func (p Project) SaveSecrets(s *Secrets) error
- func (p Project) SaveState(st *ProjectState, bbVersion string) error
- func (p Project) StateDir() string
- func (p Project) WriteCert(service string, certPEM, keyPEM []byte) error
- func (p Project) WriteNamedCert(service, name string, certPEM, keyPEM []byte) error
- type ProjectState
- type Secrets
Constants ¶
const ( StateFormat = 1 SecretsFormat = 1 )
Format versions of the project state files.
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).
const (
DirName = ".bb"
)
Directory and file names inside a project.
const HomeEnv = "BB_HOME"
HomeEnv overrides the install home.
Variables ¶
This section is empty.
Functions ¶
func DefaultHomeDir ¶
DefaultHomeDir returns $BB_HOME, or <user config dir>/breadboard.
Types ¶
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 ¶
CACertPath is the certificate file of the named CA.
func (Home) Ensure ¶
Ensure creates the home and CA directories with mode 0700 and reports whether the home was created.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is a held advisory lock on a project's .bb/lock file.
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 ¶
CertServices lists services with a stored certificate.
func (Project) Ensure ¶
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 ¶
LoadSecrets reads secrets.json.
func (Project) LoadState ¶
func (p Project) LoadState() (*ProjectState, error)
LoadState reads state.json, upgrading older formats in memory.
func (Project) ReadNamedCert ¶
ReadNamedCert returns the pair <name>.crt and <name>.key stored for a service, or ok=false.
func (Project) RemoveCert ¶
RemoveCert deletes a service's stored certificate, if any.
func (Project) RemoveNamedCert ¶
RemoveNamedCert deletes a service's pair <name>.crt and <name>.key, if present, leaving its other files.
func (Project) RuntimeDir ¶
RuntimeDir holds the generated compose project.
func (Project) SaveSecrets ¶
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.
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.