snapasserts

package
v0.0.0-...-9e584df Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package snapasserts offers helpers to handle snap related assertions and their checking for installation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CrossCheck

func CrossCheck(instanceName, snapSHA3_384 string, snapSize uint64, si *snap.SideInfo, db Finder) error

CrossCheck tries to cross check the instance name, hash digest and size of a snap plus its metadata in a SideInfo with the relevant snap assertions in a database that should have been populated with them.

func DeriveSideInfo

func DeriveSideInfo(snapPath string, db Finder) (*snap.SideInfo, error)

DeriveSideInfo tries to construct a SideInfo for the given snap using its digest to find the relevant snap assertions with the information in the given database. It will fail with an asserts.NotFoundError if it cannot find them.

func FetchSnapAssertions

func FetchSnapAssertions(f asserts.Fetcher, snapSHA3_384 string) error

FetchSnapAssertions fetches the assertions matching the snap file digest using the given fetcher.

func FetchSnapDeclaration

func FetchSnapDeclaration(f asserts.Fetcher, snapID string) error

FetchSnapDeclaration fetches the snap declaration and its prerequisites for the given snap id using the given fetcher.

func FetchStore

func FetchStore(f asserts.Fetcher, storeID string) error

FetchStore fetches the store assertion and its prerequisites for the given store id using the given fetcher.

func SideInfoFromSnapAssertions

func SideInfoFromSnapAssertions(snapDecl *asserts.SnapDeclaration, snapRev *asserts.SnapRevision) *snap.SideInfo

SideInfoFromSnapAssertions returns a *snap.SideInfo reflecting the given snap assertions.

Types

type Finder

type Finder interface {
	// Find an assertion based on arbitrary headers.  Provided
	// headers must contain the primary key for the assertion
	// type.  It returns a asserts.NotFoundError if the assertion
	// cannot be found.
	Find(assertionType *asserts.AssertionType, headers map[string]string) (asserts.Assertion, error)
}

type InstalledSnap

type InstalledSnap struct {
	naming.SnapRef
	Revision snap.Revision
}

InstalledSnap holds the minimal details about an installed snap required to check it against validation sets.

func NewInstalledSnap

func NewInstalledSnap(name, snapID string, revision snap.Revision) *InstalledSnap

NewInstalledSnap creates InstalledSnap.

type PresenceConstraintError

type PresenceConstraintError struct {
	SnapName string
	Presence asserts.Presence
}

PresenceConstraintError describes an error where presence of the given snap has unexpected value, e.g. it's "invalid" while checking for "required".

func (*PresenceConstraintError) Error

func (e *PresenceConstraintError) Error() string

type ValidationSets

type ValidationSets struct {
	// contains filtered or unexported fields
}

ValidationSets can hold a combination of validation-set assertions and can check for conflicts or help applying them.

func NewValidationSets

func NewValidationSets() *ValidationSets

NewValidationSets returns a new ValidationSets.

func (*ValidationSets) Add

func (v *ValidationSets) Add(valset *asserts.ValidationSet) error

Add adds the given asserts.ValidationSet to the combination. It errors if a validation-set with the same sequence key has been added already.

func (*ValidationSets) CheckInstalledSnaps

func (v *ValidationSets) CheckInstalledSnaps(snaps []*InstalledSnap) error

CheckInstalledSnaps checks installed snaps against the validation sets.

func (*ValidationSets) CheckPresenceInvalid

func (v *ValidationSets) CheckPresenceInvalid(snapRef naming.SnapRef) ([]string, error)

CheckPresenceInvalid returns the list of all validation sets that declare presence of the given snap as invalid. PresenceConstraintError is returned if presence of the snap is "optional" or "required". The method assumes that validation sets are not in conflict.

func (*ValidationSets) CheckPresenceRequired

func (v *ValidationSets) CheckPresenceRequired(snapRef naming.SnapRef) ([]string, snap.Revision, error)

CheckPresenceRequired returns the list of all validation sets that declare presence of the given snap as required and the required revision (or snap.R(0) if no specific revision is required). PresenceConstraintError is returned if presence of the snap is "invalid". The method assumes that validation sets are not in conflict.

func (*ValidationSets) Conflict

func (v *ValidationSets) Conflict() error

Conflict returns a non-nil error if the combination is in conflict, nil otherwise.

type ValidationSetsConflictError

type ValidationSetsConflictError struct {
	Sets  map[string]*asserts.ValidationSet
	Snaps map[string]error
}

ValidationSetsConflictError describes an error where multiple validation sets are in conflict about snaps.

func (*ValidationSetsConflictError) Error

type ValidationSetsValidationError

type ValidationSetsValidationError struct {
	// MissingSnaps maps missing snap names to the validation sets requiring them.
	MissingSnaps map[string][]string
	// InvalidSnaps maps snap names to the validation sets declaring them invalid.
	InvalidSnaps map[string][]string
	// WronRevisionSnaps maps snap names to the expected revisions and respective
	// validation sets that require them.
	WrongRevisionSnaps map[string]map[snap.Revision][]string
	// Sets maps validation set keys referenced by above maps to actual
	// validation sets.
	Sets map[string]*asserts.ValidationSet
}

ValidationSetsValidationError describes an error arising from validation of snaps against ValidationSets.

func (*ValidationSetsValidationError) Error

Jump to

Keyboard shortcuts

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