Documentation
¶
Overview ¶
Package bootstrap stands up the configuration of a local operator-mode NATS server with JetStream for one developer (`mashctl init --local`, ADR 0052): keys through the ctlkeys store, the operator, system account, MASH account and two user JWTs, a server.conf that preloads them and a config.json. Build computes every file's content and creates the keys; Plan.Write puts the files down without clobbering anything.
Index ¶
Constants ¶
const ( ServerConf = "server.conf" OperatorJWT = "operator.jwt" AdminCreds = "mashadmin.creds" SysCreds = "sys.creds" ServerLog = "server.log" ServerPID = "server.pid" // DefaultPort is the client port of the local server. DefaultPort = 4222 ServerName = "mash-local" )
File names inside the server directory.
const ( CACert = "ca.pem" CAKey = "ca.key" ServerCert = "server.pem" ServerKey = "server.key" )
File names of the local certificate authority and the server certificate, inside the server directory.
Variables ¶
var ErrNoServerBinary = errors.New("mashctl: nats-server is not on PATH: nothing was started (the files remain). Install it from nats.io or your package manager, then run: nats-server -c <dir>/server.conf")
ErrNoServerBinary is wrapped by Start when nats-server is not on PATH; nothing was started.
var ErrNotGeneratedHere = errors.New("mashctl: Start trusts only the CA this run generated, so it only connects to a loopback server that this run generated: nothing was started")
ErrNotGeneratedHere is returned by Start, before it starts anything, when the server was not generated by the current run: Start's readiness probe trusts the CA of this run, so it only connects to a loopback server of this run.
Functions ¶
func MintAdminCreds ¶
MintAdminCreds mints the mashadmin user (full access within the account) signed by the account identity key and returns its .creds bytes, which hold the user seed: never log or print them. `mashctl adopt --mint-admin` uses it.
func Preflight ¶
Preflight refuses when dir holds any file that Build would create (or Start would write). A missing dir is fine.
func Start ¶
Start launches nats-server -c <Dir>/server.conf detached (its own process group; output to server.log, pid in server.pid), and waits until it accepts a connection with the mashadmin credentials. It returns the pid. On a failure after the launch it stops only the process it started.
The readiness probe is a TLS connection that trusts only the ca.pem of this run's server directory. It is only made when generatedHere says the server was generated by this very run (it is an internal parameter, not a setting) and url is a loopback address; otherwise Start returns an error before it starts anything.
Types ¶
type Params ¶
type Params struct {
Dir string // the server directory (absolute)
Owner string
Port int
ConfigPath string // where config.json goes if none exists; "" skips it
// JetStreamDisk is the account's JetStream disk limit in bytes; zero means the 2 GiB default. Callers other than
// tests leave it zero.
JetStreamDisk int64
}
Params says what to build.
func (Params) AdminCredsPath ¶
AdminCredsPath is the mashadmin creds path.
type Plan ¶
type Plan struct {
Params
Files []File // the server directory's files
Dirs []string
Config *File // nil when a config.json exists or no path was given
URL string
CA string // the path of ca.pem: the CA that signed the server certificate
Creds string // the admin creds path
Account string // public keys, safe to print
Operator string
System string
// OperatorJWT is the operator JWT written to the server directory; init --local also stores a copy in the key directory.
OperatorJWT string
}
Plan is everything Build decided: the files to create, with the config.json outcome.