inventory

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 9 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 inventory is the deployment-tracking model. Keyed by SHA256 fingerprint, it turns rotation into a checklist and is persisted atomically.

Index

Constants

View Source
const (
	StatusNotDeployed   = "not-deployed"   // no deployment recorded: a fresh or regenerated key
	StatusNeedsRedeploy = "needs-redeploy" // deployments recorded, none verified
	StatusDeployed      = "deployed"       // at least one verified deployment
)

Deployment status values, as list, audit, export and the web show them.

Variables

This section is empty.

Functions

func ComputeExpiry

func ComputeExpiry(created string, rotateAfterDays int) (string, error)

ComputeExpiry returns created (YYYY-MM-DD) + rotateAfterDays as YYYY-MM-DD.

func IsArchivedPathIn added in v0.1.6

func IsArchivedPathIn(path, root string) bool

IsArchivedPathIn reports whether path is a rotation's /old/ predecessor slot under the key root, i.e. .../<root>/[<category>/]<profile>/old/<key_name> (by structure, so a profile literally named "old" is not mistaken for an archived key).

func RetiredPath added in v0.1.6

func RetiredPath(inventoryPath string) string

RetiredPath is retired.json, beside the inventory at inventoryPath. A file of its own for the reason revoked.json is one: the inventory decodes strictly, so a new field would make an older authama refuse it.

func RevokedPath added in v0.1.6

func RevokedPath(inventoryPath string) string

RevokedPath is revoked.json, beside the inventory at inventoryPath. A file of its own, not a field: the inventory decodes strictly, so a new field would make an older authama refuse the whole inventory.

func Today

func Today() string

Today returns today's date as YYYY-MM-DD.

Types

type Deployment

type Deployment struct {
	Target   string  `json:"target"`
	Method   string  `json:"method"` // ssh-copy-id | web-panel | manual | <adapter>
	Date     *string `json:"date"`
	Verified bool    `json:"verified"` // all false == needs-redeploy
}

Deployment records a key installed on one target.

func (*Deployment) UnmarshalJSON

func (d *Deployment) UnmarshalJSON(b []byte) error

type Inventory

type Inventory struct {
	Version int                  `json:"version"`
	Keys    map[string]KeyRecord `json:"keys"`
}

Inventory is the whole inventory, keyed by fingerprint.

func Load

func Load(path string) (*Inventory, error)

Load reads an inventory; a missing file yields an empty inventory (matching v1).

func New

func New() *Inventory

New returns an empty inventory.

func (*Inventory) Record

func (inv *Inventory) Record(fingerprint string, rec KeyRecord)

Record stores a key record under its fingerprint.

func (*Inventory) Save

func (inv *Inventory) Save(path string) error

Save writes the inventory as indented JSON, atomically.

Via a temp file and a rename, not os.WriteFile: WriteFile truncates the target and then writes, so a crash or a full disk mid-write leaves a truncated inventory - the record of every key's expiry and deployments, lost to a partial write. It also keeps whatever mode the file already had, so an inventory that had somehow become group-readable stayed that way.

func (*Inventory) UnmarshalJSON

func (inv *Inventory) UnmarshalJSON(b []byte) error

type KeyRecord

type KeyRecord struct {
	Profile         string       `json:"profile"`
	Path            string       `json:"path"`
	Type            string       `json:"type"`
	Comment         *string      `json:"comment"`
	Created         *string      `json:"created"`
	RotateAfterDays int          `json:"rotate_after_days"`
	ExpiresOn       *string      `json:"expires_on"`
	Deployments     []Deployment `json:"deployments"`
}

KeyRecord is one managed key and where it is deployed. All fields serialize unconditionally (null for an unset pointer, [] for no deployments) to match the serializer v1 and v2 used, byte-for-byte.

func (KeyRecord) DeployStatus added in v0.1.6

func (r KeyRecord) DeployStatus() string

DeployStatus names the key's state: not-deployed when nothing is recorded, needs-redeploy when deployments are recorded but none is verified, deployed otherwise.

func (KeyRecord) MarshalJSON

func (r KeyRecord) MarshalJSON() ([]byte, error)

MarshalJSON emits a nil Deployments slice as [] (not null), matching the default_factory=list. The pointer fields already emit null when unset.

func (KeyRecord) NeedsRedeploy

func (r KeyRecord) NeedsRedeploy() bool

NeedsRedeploy is true when no deployment is verified (e.g. a fresh key). It is true for not-deployed keys too; DeployStatus tells the two apart.

func (*KeyRecord) UnmarshalJSON

func (r *KeyRecord) UnmarshalJSON(b []byte) error

type Retirement added in v0.1.6

type Retirement struct {
	Key        string            `json:"key"` // profile/key_name
	Successor  string            `json:"successor"`
	RetiredOn  string            `json:"retired_on"`
	Removed    []string          `json:"removed_from"`
	NotRemoved []string          `json:"not_removed_from"`
	ByHand     map[string]string `json:"by_hand,omitempty"` // target -> where its keys are managed
}

Retirement is one key a rotation replaced: what it was, its successor, when it was retired, and the targets the rotation removed it from, could not remove it from, and that take it off by hand (with where). It is not a revocation: rollback may still bring a retired key back, while deploy and rollback refuse a revoked one.

type Retirements added in v0.1.6

type Retirements map[string]Retirement

Retirements is retired.json: retirements by the retired key's fingerprint.

func LoadRetirements added in v0.1.6

func LoadRetirements(path string) (Retirements, error)

LoadRetirements reads path; a missing file is no retirements.

func (Retirements) Save added in v0.1.6

func (r Retirements) Save(path string) error

Save writes the record owner-only, lists sorted.

type Revocation added in v0.1.6

type Revocation struct {
	Key        string   `json:"key"` // profile/key_name
	RevokedOn  string   `json:"revoked_on"`
	Reason     string   `json:"reason,omitempty"`
	Removed    []string `json:"removed_from"`
	NotRemoved []string `json:"not_removed_from"`
}

Revocation is one revoked key: the key it was, when it was revoked, and the targets it was removed from and could not be removed from. A fingerprint in the record is never deployed again; a regenerated or rotated key has a new fingerprint and is not affected.

type Revocations added in v0.1.6

type Revocations map[string]Revocation

Revocations is revoked.json: revocations by fingerprint.

func LoadRevocations added in v0.1.6

func LoadRevocations(path string) (Revocations, error)

LoadRevocations reads path; a missing file is no revocations.

func (Revocations) Save added in v0.1.6

func (r Revocations) Save(path string) error

Save writes the record owner-only, keys sorted (json sorts map keys).

Jump to

Keyboard shortcuts

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