events

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: 17 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 events tracks the files authama is responsible for - everything under ~/.ssh, the config home, and each tool's credential file - and records every change to them, whoever made it: authama, an editor, ssh-keygen run by hand, a package manager rewriting its token file.

It never records a file's contents. Each scan keeps, per file, its size, mode, modification time and a SHA-256 of its bytes, in an owner-only state file; an event names the file, what changed (added, changed, removed, mode) and when it was seen. The hash detects a change and cannot be turned back into a key or a token.

Index

Constants

View Source
const (
	AreaSSH    = "ssh"    // under ~/.ssh
	AreaConfig = "config" // the config home: manifest, inventory, settings, .env
	AreaAuth   = "auth"   // a tool's credential file: auth.json, .npmrc, …
)

The areas a tracked file belongs to.

View Source
const (
	KindStarted = "started" // the first scan: tracking began, nothing compared
	KindAdded   = "added"
	KindChanged = "changed" // the contents changed
	KindRemoved = "removed"
	KindMode    = "mode" // only the permissions changed
)

The kinds of event.

Variables

This section is empty.

Functions

func LogFile

func LogFile(p paths.Paths) string

func StateFile

func StateFile(p paths.Paths) string

StateFile and LogFile are where a home keeps the last scan and the events.

Types

type Event

type Event struct {
	Time   time.Time `json:"time"`
	Seen   time.Time `json:"seen"`
	Kind   string    `json:"kind"`
	Area   string    `json:"area"`
	Path   string    `json:"path"`
	Size   int64     `json:"size,omitempty"`
	Mode   string    `json:"mode,omitempty"`
	Detail string    `json:"detail,omitempty"`
	// Hash chains the log: SHA-256 of the previous line's Hash and this
	// event's other fields. An edited, removed or inserted line breaks the
	// chain from there on (see Verify).
	Hash string `json:"hash,omitempty"`
}

Event is one change seen by a scan. Time is when the change happened as far as the file says - its modification time, for an added or changed file - and Seen is the scan that found it; a removal or a mode change, which leaves no time behind, has Time equal to Seen.

func List

func List(p paths.Paths, f Filter) ([]Event, error)

List reads the events log, newest first. A home that has never been scanned has none.

func Scan

func Scan(p paths.Paths, roots []Tracked, now time.Time) ([]Event, error)

Scan compares the tracked files with the last scan, appends what changed to the events log, and returns it. The first scan records a single "started" event and the files it found.

type Filter

type Filter struct {
	Since time.Time
	Area  string
	Kind  string
	Limit int // 0 is no limit
}

Filter narrows List.

type Integrity

type Integrity struct {
	Lines     int    // lines read
	Chained   int    // lines carrying a hash
	Unchained int    // lines from before the log was chained, at its start
	Broken    int    // the first line (1-based) whose hash does not follow, 0 when none
	Reason    string // why, when Broken or Truncated
	Truncated bool   // the log ends before the head the state recorded
}

Integrity is what Verify found.

func Verify

func Verify(p paths.Paths) (Integrity, error)

Verify checks the events log's hash chain: every chained line must hash from the one before it, and the last must be the head the state recorded. Lines written before the log was chained, at its start, are counted, not checked. Tamper evidence, not proof: someone who can rewrite the state home can rewrite both files, but not one line without the chain showing it.

func (Integrity) OK

func (i Integrity) OK() bool

OK reports whether the log is intact.

type Tracked

type Tracked struct {
	Path string
	Area string
	Dir  bool
	Skip []string
}

Tracked is a file, or a directory walked for files, and its area. Skip names directories under it that are not walked.

func Roots

func Roots(p paths.Paths, tokenFiles []string) []Tracked

Roots is what a home tracks: ~/.ssh and the config home, walked, and each credential file named in tokenFiles.

Jump to

Keyboard shortcuts

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