bootstrap

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 24 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 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

View Source
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.

View Source
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

View Source
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.

View Source
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

func MintAdminCreds(accountKey nkeys.KeyPair) ([]byte, error)

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

func Preflight(dir string) error

Preflight refuses when dir holds any file that Build would create (or Start would write). A missing dir is fine.

func Start

func Start(p Params, url string, generatedHere bool) (int, error)

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 File

type File struct {
	Path string
	Data []byte
}

File is one file to create.

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

func (p Params) AdminCredsPath() string

AdminCredsPath is the mashadmin creds path.

func (Params) ConfPath

func (p Params) ConfPath() string

ConfPath is the server.conf path.

func (Params) LogPath

func (p Params) LogPath() string

LogPath is the server log path used by Start.

func (Params) PIDPath

func (p Params) PIDPath() string

PIDPath is the pid file path used by Start.

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.

func Build

func Build(p Params, ks *ctlkeys.Authority) (*Plan, error)

Build creates the keys (operator, system, account) in ks if absent and computes every file. It writes nothing but those keys; call Plan.Write for the rest. It refuses before touching anything when Preflight does.

func (*Plan) Write

func (pl *Plan) Write() (err error)

Write creates the directories (0700) and files (0600) of the plan, never replacing one. If a step fails, what this call created is removed again (the keys stay).

Jump to

Keyboard shortcuts

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