snap

package
v0.0.0-...-677ed08 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2016 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddImplicitSlots

func AddImplicitSlots(snapInfo *Info)

AddImplicitSlots adds implicitly defined slots to a given snap.

Only the OS snap has implicit slots.

It is assumed that slots have names matching the interface name. Existing slots are not changed, only missing slots are added.

func AppSecurityTag

func AppSecurityTag(snapName, appName string) string

AppSecurityTag returns the application-specific security tag.

func GuessAppsForBroken

func GuessAppsForBroken(info *Info) map[string]*AppInfo

func HookSecurityTag

func HookSecurityTag(snapName, hookName string) string

HookSecurityTag returns the hook-specific security tag.

func IsHookSupported

func IsHookSupported(hookName string) bool

IsHookSupported returns true if the given hook name matches one of the supported hooks.

func MountDir

func MountDir(name string, revision Revision) string

MountDir returns the base directory where it gets mounted of the snap with the given name and revision.

func NoneSecurityTag

func NoneSecurityTag(snapName, uniqueName string) string

NoneSecurityTag returns the security tag for interfaces that are not associated to an app or hook in the snap.

func SecurityTag

func SecurityTag(snapName string) string

SecurityTag returns the snap-specific security tag.

func SplitSnapApp

func SplitSnapApp(snapApp string) (snap, app string)

SplitSnapApp will split a string of the form `snap.app` into the `snap` and the `app` part. It also deals with the special case of snapName == appName.

func Validate

func Validate(info *Info) error

Validate verifies the content in the info.

func ValidateApp

func ValidateApp(app *AppInfo) error

ValidateApp verifies the content in the app info.

func ValidateEpoch

func ValidateEpoch(epoch string) error

ValidateEpoch checks if a string can be used as a snap epoch.

func ValidateHook

func ValidateHook(hook *HookInfo) error

ValidateHook validates the content of the given HookInfo

func ValidateName

func ValidateName(name string) error

ValidateName checks if a string can be used as a snap name.

Types

type AppInfo

type AppInfo struct {
	Snap *Info

	Name    string
	Command string

	Daemon          string
	StopTimeout     timeout.Timeout
	StopCommand     string
	PostStopCommand string
	RestartCond     systemd.RestartCondition

	Socket       bool
	SocketMode   string
	ListenStream string

	// TODO: this should go away once we have more plumbing and can change
	// things vs refactor
	// https://github.com/snapcore/snapd/pull/794#discussion_r58688496
	BusName string

	Plugs map[string]*PlugInfo
	Slots map[string]*SlotInfo

	Environment map[string]string
}

AppInfo provides information about a app.

func (*AppInfo) Env

func (app *AppInfo) Env() []string

Env returns the app specific environment overrides

func (*AppInfo) LauncherCommand

func (app *AppInfo) LauncherCommand() string

LauncherCommand returns the launcher command line to use when invoking the app binary.

func (*AppInfo) LauncherPostStopCommand

func (app *AppInfo) LauncherPostStopCommand() string

LauncherPostStopCommand returns the launcher command line to use when invoking the app post-stop command binary.

func (*AppInfo) LauncherStopCommand

func (app *AppInfo) LauncherStopCommand() string

LauncherStopCommand returns the launcher command line to use when invoking the app stop command binary.

func (*AppInfo) SecurityTag

func (app *AppInfo) SecurityTag() string

SecurityTag returns application-specific security tag.

Security tags are used by various security subsystems as "profile names" and sometimes also as a part of the file name.

func (*AppInfo) ServiceFile

func (app *AppInfo) ServiceFile() string

ServiceFile returns the systemd service file path for the daemon app.

func (*AppInfo) ServiceSocketFile

func (app *AppInfo) ServiceSocketFile() string

ServiceSocketFile returns the systemd socket file path for the daemon app.

func (*AppInfo) WrapperPath

func (app *AppInfo) WrapperPath() string

WrapperPath returns the path to wrapper invoking the app binary.

type ConfinementType

type ConfinementType string

ConfinementType represents the kind of confinement supported by the snap (devmode only, or strict confinement)

const (
	DevmodeConfinement ConfinementType = "devmode"
	StrictConfinement  ConfinementType = "strict"
)

The various confinement types we support

func (*ConfinementType) UnmarshalJSON

func (confinementType *ConfinementType) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *confinementType to a copy of data, assuming validation passes

func (*ConfinementType) UnmarshalYAML

func (confinementType *ConfinementType) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML so ConfinementType implements yaml's Unmarshaler interface

type Container

type Container interface {
	// ReadFile returns the content of a single file from the snap.
	ReadFile(relative string) ([]byte, error)

	// ListDir returns the content of a single directory inside the snap.
	ListDir(path string) ([]string, error)

	// Install copies the snap file to targetPath (and possibly unpacks it to mountDir)
	Install(targetPath, mountDir string) error

	// Unpack unpacks the src parts to the dst directory
	Unpack(src, dst string) error
}

Container is the interface to interact with the low-level snap files

func Open

func Open(path string) (Container, error)

Open opens a given snap file with the right backend

type Content

type Content struct {
	Source string
	Target string

	Image       string
	Offset      int64
	OffsetWrite int64
	Size        int64

	Unpack bool
}

type DeltaInfo

type DeltaInfo struct {
	FromRevision    int    `json:"from-revision,omitempty"`
	ToRevision      int    `json:"to-revision,omitempty"`
	Format          string `json:"format,omitempty"`
	AnonDownloadURL string `json:"anon-download-url,omitempty"`
	DownloadURL     string `json:"download-url,omitempty"`
	Size            int64  `json:"size,omitempty"`
	Sha3_384        string `json:"sha3-384,omitempty"`
}

DeltaInfo contains the information to download a delta from one revision to another.

type DownloadInfo

type DownloadInfo struct {
	AnonDownloadURL string `json:"anon-download-url,omitempty"`
	DownloadURL     string `json:"download-url,omitempty"`

	Size     int64  `json:"size,omitempty"`
	Sha3_384 string `json:"sha3-384,omitempty"`

	Deltas []DeltaInfo `json:"deltas,omitempty"`
}

DownloadInfo contains the information to download a snap. It can be marshalled.

type GadgetInfo

type GadgetInfo struct {
	Volumes map[string]Volume
}

func ReadGadgetInfo

func ReadGadgetInfo(info *Info) (*GadgetInfo, error)

type HookInfo

type HookInfo struct {
	Snap *Info

	Name  string
	Plugs map[string]*PlugInfo
}

HookInfo provides information about a hook.

func (*HookInfo) Env

func (hook *HookInfo) Env() []string

Env returns the hook-specific environment overrides

func (*HookInfo) SecurityTag

func (hook *HookInfo) SecurityTag() string

SecurityTag returns the hook-specific security tag.

Security tags are used by various security subsystems as "profile names" and sometimes also as a part of the file name.

type HookType

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

HookType represents a pattern of supported hook names.

func (HookType) Match

func (hookType HookType) Match(hookName string) bool

Match returns true if the given hook name matches this hook type.

type Info

type Info struct {
	SuggestedName string
	Version       string
	Type          Type
	Architectures []string
	Assumes       []string

	OriginalSummary     string
	OriginalDescription string

	Environment map[string]string

	LicenseAgreement string
	LicenseVersion   string
	Epoch            string
	Confinement      ConfinementType
	Apps             map[string]*AppInfo
	Hooks            map[string]*HookInfo
	Plugs            map[string]*PlugInfo
	Slots            map[string]*SlotInfo

	// The information in all the remaining fields is not sourced from the snap blob itself.
	SideInfo

	// Broken marks if set whether the snap is broken and the reason.
	Broken string

	// The information in these fields is ephemeral, available only from the store.
	DownloadInfo

	IconURL string
	Prices  map[string]float64 `yaml:"prices,omitempty" json:"prices,omitempty"`
	MustBuy bool

	Screenshots []ScreenshotInfo
}

Info provides information about snaps.

func InfoFromSnapYaml

func InfoFromSnapYaml(yamlData []byte) (*Info, error)

InfoFromSnapYaml creates a new info based on the given snap.yaml data

func ReadInfo

func ReadInfo(name string, si *SideInfo) (*Info, error)

ReadInfo reads the snap information for the installed snap with the given name and given side-info.

func ReadInfoFromSnapFile

func ReadInfoFromSnapFile(snapf Container, si *SideInfo) (*Info, error)

ReadInfoFromSnapFile reads the snap information from the given File and completes it with the given side-info if this is not nil.

func (*Info) CommonDataDir

func (s *Info) CommonDataDir() string

CommonDataDir returns the data directory common across revisions of the snap.

func (*Info) CommonDataHomeDir

func (s *Info) CommonDataHomeDir() string

CommonDataHomeDir returns the per user data directory common across revisions of the snap.

func (*Info) DataDir

func (s *Info) DataDir() string

DataDir returns the data directory of the snap.

func (*Info) DataHomeDir

func (s *Info) DataHomeDir() string

DataHomeDir returns the per user data directory of the snap.

func (*Info) Description

func (s *Info) Description() string

Description returns the blessed description for the snap.

func (*Info) HooksDir

func (s *Info) HooksDir() string

HooksDir returns the directory containing the snap's hooks.

func (*Info) MountDir

func (s *Info) MountDir() string

MountDir returns the base directory of the snap where it gets mounted.

func (*Info) MountFile

func (s *Info) MountFile() string

MountFile returns the path where the snap file that is mounted is installed.

func (*Info) Name

func (s *Info) Name() string

Name returns the blessed name for the snap.

func (*Info) NeedsDevMode

func (s *Info) NeedsDevMode() bool

NeedsDevMode retursn whether the snap needs devmode.

func (*Info) Summary

func (s *Info) Summary() string

Summary returns the blessed summary for the snap.

func (*Info) UserCommonDataDir

func (s *Info) UserCommonDataDir(home string) string

UserCommonDataDir returns the user-specific data directory common across revision of the snap.

func (*Info) UserDataDir

func (s *Info) UserDataDir(home string) string

UserDataDir returns the user-specific data directory of the snap.

type NotFoundError

type NotFoundError struct {
	Snap     string
	Revision Revision
}

func (NotFoundError) Error

func (e NotFoundError) Error() string

type PlaceInfo

type PlaceInfo interface {
	// Name returns the name of the snap.
	Name() string

	// MountDir returns the base directory of the snap.
	MountDir() string

	// MountFile returns the path where the snap file that is mounted is installed.
	MountFile() string

	// HooksDir returns the directory containing the snap's hooks.
	HooksDir() string

	// DataDir returns the data directory of the snap.
	DataDir() string

	// CommonDataDir returns the data directory common across revisions of the snap.
	CommonDataDir() string

	// DataHomeDir returns the per user data directory of the snap.
	DataHomeDir() string

	// CommonDataHomeDir returns the per user data directory common across revisions of the snap.
	CommonDataHomeDir() string
}

PlaceInfo offers all the information about where a snap and its data are located and exposed in the filesystem.

func MinimalPlaceInfo

func MinimalPlaceInfo(name string, revision Revision) PlaceInfo

MinimalPlaceInfo returns a PlaceInfo with just the location information for a snap of the given name and revision.

type PlugInfo

type PlugInfo struct {
	Snap *Info

	Name      string
	Interface string
	Attrs     map[string]interface{}
	Label     string
	Apps      map[string]*AppInfo
	Hooks     map[string]*HookInfo
}

PlugInfo provides information about a plug.

type Revision

type Revision struct {
	N int
}

func ParseRevision

func ParseRevision(s string) (Revision, error)

ParseRevisions returns the representation in r as a revision. See R for a function more suitable for hardcoded revisions.

func R

func R(r interface{}) Revision

R returns a Revision given an int or a string. Providing an invalid revision type or value causes a runtime panic. See ParseRevision for a polite function that does not panic.

func (Revision) Local

func (r Revision) Local() bool

func (Revision) MarshalJSON

func (r Revision) MarshalJSON() ([]byte, error)

func (Revision) MarshalYAML

func (r Revision) MarshalYAML() (interface{}, error)

func (Revision) Store

func (r Revision) Store() bool

func (Revision) String

func (r Revision) String() string

func (*Revision) UnmarshalJSON

func (r *Revision) UnmarshalJSON(data []byte) error

func (*Revision) UnmarshalYAML

func (r *Revision) UnmarshalYAML(unmarshal func(interface{}) error) error

func (Revision) Unset

func (r Revision) Unset() bool

type ScreenshotInfo

type ScreenshotInfo struct {
	URL    string
	Width  int64
	Height int64
}

ScreenshotInfo provides information about a screenshot.

type Seed

type Seed struct {
	Snaps []*SeedSnap `yaml:"snaps"`
}

func ReadSeedYaml

func ReadSeedYaml(fn string) (*Seed, error)

func (*Seed) Write

func (seed *Seed) Write(seedFn string) error

type SeedSnap

type SeedSnap struct {
	Name string `yaml:"name"`

	// cross-reference/audit
	SnapID string `yaml:"snap-id,omitempty"`

	// bits that are orthongonal/not in assertions
	Channel string `yaml:"channel,omitempty"`
	DevMode bool   `yaml:"devmode,omitempty"`

	Private bool `yaml:"private,omitempty"`

	// no assertions are available in the seed for this snap
	Unasserted bool `yaml:"unasserted,omitempty"`

	File string `yaml:"file"`
}

SeedSnap points to a snap in the seed to install, together with assertions (or alone if unasserted is true) it will be used to drive the installation and ultimately set SideInfo/SnapState for it.

type SideInfo

type SideInfo struct {
	RealName          string   `yaml:"name,omitempty" json:"name,omitempty"`
	SnapID            string   `yaml:"snap-id" json:"snap-id"`
	Revision          Revision `yaml:"revision" json:"revision"`
	Channel           string   `yaml:"channel,omitempty" json:"channel,omitempty"`
	DeveloperID       string   `yaml:"developer-id,omitempty" json:"developer-id,omitempty"`
	Developer         string   `yaml:"developer,omitempty" json:"developer,omitempty"` // XXX: obsolete, will be retired after full backfilling of DeveloperID
	EditedSummary     string   `yaml:"summary,omitempty" json:"summary,omitempty"`
	EditedDescription string   `yaml:"description,omitempty" json:"description,omitempty"`
	Private           bool     `yaml:"private,omitempty" json:"private,omitempty"`
}

SideInfo holds snap metadata that is crucial for the tracking of snaps and for the working of the system offline and which is not included in snap.yaml or for which the store is the canonical source overriding snap.yaml content.

It can be marshalled and will be stored in the system state for each currently installed snap revision so it needs to be evolved carefully.

Information that can be taken directly from snap.yaml or that comes from the store but is not required for working offline should not end up in SideInfo.

type SlotInfo

type SlotInfo struct {
	Snap *Info

	Name      string
	Interface string
	Attrs     map[string]interface{}
	Label     string
	Apps      map[string]*AppInfo
}

SlotInfo provides information about a slot.

type Structure

type Structure struct {
	Label       string
	Offset      int64
	OffsetWrite int64
	Size        int64
	Type        string
	ID          string
	Filesystem  string
	Content     []Content
}

type Type

type Type string

Type represents the kind of snap (app, core, gadget, os, kernel)

const (
	TypeApp    Type = "app"
	TypeGadget Type = "gadget"
	TypeOS     Type = "os"
	TypeKernel Type = "kernel"
)

The various types of snap parts we support

func (*Type) UnmarshalJSON

func (m *Type) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data.

func (*Type) UnmarshalYAML

func (m *Type) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML so ConfinementType implements yaml's Unmarshaler interface

type Volume

type Volume struct {
	Schema     string
	Bootloader string
	ID         string
	Structure  []Structure
}

Directories

Path Synopsis
Package snaptest contains helper functions for mocking snaps.
Package snaptest contains helper functions for mocking snaps.

Jump to

Keyboard shortcuts

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