inventory

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 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 keeps track of the artifacts drop installs in the local system. The data lives in a single versioned JSON document in the user's configuration directory and records, for every installed app, what was installed and enough metadata to later verify, update or uninstall it.

Index

Constants

View Source
const FileName = "installed.json"

FileName is the name of the inventory database file.

View Source
const Version = 1

Version is the current schema version of the inventory file.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns the location of the inventory database in the user's configuration directory.

Types

type Inventory

type Inventory struct {
	Version  int                `json:"version"`
	Installs map[string]*Record `json:"installs"`
	// contains filtered or unexported fields
}

Inventory is the database of artifacts installed by drop.

func Open

func Open() (*Inventory, error)

Open loads the inventory from its default location, returning an empty inventory if no database exists yet.

func OpenFile

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

OpenFile loads the inventory from a file, returning an empty inventory bound to the path if the file does not exist yet.

func (*Inventory) Add

func (inv *Inventory) Add(record *Record)

Add upserts a record into the inventory. When the app is already recorded, the original installation timestamp is preserved.

func (*Inventory) Dir added in v0.2.2

func (inv *Inventory) Dir() string

Dir returns the directory of the file the inventory is bound to, where the files it refers to are kept. It is empty when the inventory is not bound to a file.

func (*Inventory) Get

func (inv *Inventory) Get(key string) *Record

Get returns the record stored under a key or nil if there is none.

func (*Inventory) Remove

func (inv *Inventory) Remove(key string) bool

Remove deletes the record stored under a key, returning true if it existed.

func (*Inventory) Save

func (inv *Inventory) Save() error

Save atomically writes the inventory back to the file it was loaded from.

type Record

type Record struct {
	// Repository coordinates and installable name identifying the app.
	Host string `json:"host"`
	Org  string `json:"org"`
	Repo string `json:"repo"`
	Name string `json:"name"`

	// Version is the release tag the installed artifact came from.
	Version string `json:"version"`

	// Kind is the artifact type that was installed (binary, package or
	// archive).
	Kind string `json:"kind"`

	// Asset is the exact release asset that was downloaded.
	Asset string `json:"asset"`

	// OS and Arch are the platform of the asset, when the release tells.
	// The policies an asset is verified with can read them, so verifying
	// it again takes them.
	OS   string `json:"os,omitempty"`
	Arch string `json:"arch,omitempty"`

	// Digest captures the hashes of the verified artifact, keyed by
	// algorithm. For binaries it can be checked against the installed
	// file, for packages integrity checks are delegated to the package
	// manager and the digest ties the record to the verified file.
	Digest map[string]string `json:"digest,omitempty"`

	// FileDigest captures the hashes of the file that was installed, keyed
	// by algorithm (binaries and archives only). For a binary it is the
	// digest of the verified artifact; for an archive, that of the file
	// extracted from it. It is what tells if the installed file is still
	// the one that was installed.
	FileDigest map[string]string `json:"fileDigest,omitempty"`

	// BinPath is the path where the binary was installed (binaries and
	// archives only).
	BinPath string `json:"binPath,omitempty"`

	// ArchiveEntry is the path inside the release archive of the file that
	// was installed (archives only). Updates reuse it to pick the same
	// file without asking again.
	ArchiveEntry string `json:"archiveEntry,omitempty"`

	// PackageFormat is the package type handed to the package manager
	// (packages only).
	PackageFormat string `json:"packageFormat,omitempty"`

	// Verification points to the results of the verification the artifact
	// passed when it was installed, kept with the evidence it was verified
	// on. It is absent when the artifact was installed without verifying
	// it, or recorded before the results were kept.
	Verification *Verification `json:"verification,omitempty"`

	// Verified records if the artifact passed policy verification or was
	// installed with verification disabled.
	Verified bool `json:"verified"`

	InstalledAt time.Time `json:"installedAt"`
	UpdatedAt   time.Time `json:"updatedAt"`
}

Record stores the data of one installed app.

func (*Record) InstalledDigest added in v0.2.2

func (r *Record) InstalledDigest() map[string]string

InstalledDigest returns the hashes the installed file is expected to have, nil when the record does not tell: a package, whose files are the package manager's, or an archive recorded before the digest of the extracted file was kept. A binary recorded without it has the digest of its artifact, which is the file that was installed.

func (*Record) Key

func (r *Record) Key() string

Key returns the string keying the record in the inventory.

type Verification added in v0.2.2

type Verification struct {
	// Path of the results attestation, relative to the directory of the
	// inventory.
	Path string `json:"path"`

	// Digest captures the hashes of the results attestation, keyed by
	// algorithm.
	Digest map[string]string `json:"digest,omitempty"`
}

Verification locates the results of the verification of an installed artifact: an attestation of the results that carries the evidence they were reached on, enough to run the verification again.

Jump to

Keyboard shortcuts

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