inventory

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 7 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

This section is empty.

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 IsArchivedPath

func IsArchivedPath(path string) bool

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

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"` // 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) 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).

func (*KeyRecord) UnmarshalJSON

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

Jump to

Keyboard shortcuts

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