capability

package
v0.0.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: 16 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 capability is a room's inventory of what it can do: a declared list of named claims, a probe for each, and the newest result of every probe. It imports nothing from the daemon, the hub or the store.

A probe is an argv list and never a shell string. The only commands that run are the ones in the declared list, and an asker names ids from it. Output is cut and scrubbed before it is kept, and the raw output never leaves this package.

Index

Constants

View Source
const (
	Pass    = "pass"
	Fail    = "fail"
	Unknown = "unknown"

	DefaultTimeout = 10 * time.Second
	MaxTimeout     = 120 * time.Second
	ReasonMax      = 200
)

Variables

View Source
var ErrBusy = errors.New("a capability run is already going")

ErrBusy is a run asked for while one is going.

Functions

func Scrub

func Scrub(s string) string

Scrub cuts text to ReasonMax characters on one line, with anything shaped like a credential taken out first.

Types

type Auditor

type Auditor struct {
	// Scratch is a directory the room made for probes that write, and nothing else is written to.
	Scratch string
	// Repos is where ${ATRIUM_REPOS} points when the environment does not say.
	Repos string
	// File, when set, is where results are kept across a restart.
	File string
	Now  func() time.Time
	// contains filtered or unexported fields
}

Auditor runs the declared probes and keeps the newest result of each.

func NewAuditor

func NewAuditor(list List, scratch, file string) *Auditor

NewAuditor starts with list and any results saved in file.

func (*Auditor) Due

func (a *Auditor) Due() []string

Due is the capabilities whose newest result is older than their own cadence (every, else sixHours).

func (*Auditor) Probe

func (a *Auditor) Probe(ctx context.Context, c Cap) Result

Probe runs one capability's probe and judges it. It never returns an error: a probe that cannot run is a result.

func (*Auditor) Run

func (a *Auditor) Run(ctx context.Context, ids []string) ([]Result, error)

Run probes the named capabilities, or all of them when ids is empty, and anything they need first. Ids not in the declared list are refused before anything runs.

func (*Auditor) SetList

func (a *Auditor) SetList(l List)

SetList swaps the declared list. Results of capabilities no longer declared are dropped.

func (*Auditor) Snapshot

func (a *Auditor) Snapshot() Snapshot

type Cap

type Cap struct {
	ID    string   `yaml:"id" json:"id"`
	Kind  string   `yaml:"kind" json:"kind"`
	Probe []string `yaml:"probe" json:"-"`
	// Dir is where the probe runs. ${NAME} is read from the environment, and ${SCRATCH} is a directory the room made.
	Dir     string   `yaml:"dir,omitempty" json:"-"`
	Timeout string   `yaml:"timeout,omitempty" json:"-"`
	Pass    string   `yaml:"pass,omitempty" json:"-"`
	Match   string   `yaml:"match,omitempty" json:"-"`
	Version string   `yaml:"version,omitempty" json:"-"`
	Needs   []string `yaml:"needs,omitempty" json:"needs,omitempty"`
	// Optional shows a failure neutral everywhere. NotExpected does the same on the rooms it names.
	Optional    bool     `yaml:"optional,omitempty" json:"optional,omitempty"`
	NotExpected []string `yaml:"not_expected,omitempty" json:"not_expected,omitempty"`
	Every       string   `yaml:"every,omitempty" json:"every,omitempty"`
}

Cap is one declared capability.

type List

type List struct {
	Version int   `yaml:"version" json:"version"`
	Caps    []Cap `yaml:"caps" json:"caps"`
}

List is the declared list.

func Default

func Default() List

Default is the list atrium ships.

func Lint

func Lint(b []byte) (List, error)

Lint checks a hub list laid over the shipped one and answers the list as written.

func Load

func Load(path string) (List, error)

Load is the shipped list with the room's own additions from path laid over it. A local entry adds or replaces by id. A missing file is no additions, and a file that does not parse is an error so the room says so instead of dropping it.

func Parse

func Parse(b []byte) (List, error)

Parse reads a list and checks it: known kinds and pass rules, no duplicate id, every need resolves.

func WithHub

func WithHub(l List, hub []byte) (List, error)

WithHub lays the hub's list over l by id, so a room's own addition cannot loosen a hub entry.

type Result

type Result struct {
	Cap     string `json:"cap"`
	State   string `json:"state"`
	Version string `json:"version,omitempty"`
	Reason  string `json:"reason,omitempty"`
	At      string `json:"at"`
	MS      int64  `json:"ms,omitempty"`
}

Result is the outcome of one probe.

type Snapshot

type Snapshot struct {
	Version int      `json:"list_ver"`
	Caps    []Cap    `json:"caps"`
	Results []Result `json:"results"`
	Running []string `json:"running,omitempty"`
}

Snapshot is the declared list and the newest result of each capability, with a running probe shown as such.

Jump to

Keyboard shortcuts

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