naming

package
v0.0.0-...-1a99902 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package naming implements naming constraints and concepts for snaps and their elements.

Index

Constants

This section is empty.

Variables

View Source
var ValidAlias = regexp.MustCompile("^[a-zA-Z0-9][-_.a-zA-Z0-9]*$")

ValidAlias is a regular expression describing a valid alias

View Source
var ValidApp = regexp.MustCompile("^[a-zA-Z0-9](?:-?[a-zA-Z0-9])*$")

ValidApp is a regular expression describing a valid application name

View Source
var ValidSnapID = regexp.MustCompile("^[a-z0-9A-Z]{32}$")

ValidSnapID is a regular expression describing a valid snapd-id

Functions

func SameSnap

func SameSnap(snapRef1, snapRef2 SnapRef) bool

SameSnap returns whether the two arguments refer to the same snap. If ids are not available for both it will fallback to names.

func UseStagingIDs

func UseStagingIDs(staging bool) (restore func())

func ValidateAlias

func ValidateAlias(alias string) error

ValidateAlias checks if a string can be used as an alias name.

func ValidateApp

func ValidateApp(n string) error

ValidateApp tells whether a string is a valid application name.

func ValidateHook

func ValidateHook(name string) error

ValidateHook checks if a string can be used as a hook name.

func ValidateInstance

func ValidateInstance(instanceName string) error

ValidateInstance checks if a string can be used as a snap instance name.

func ValidateInterface

func ValidateInterface(name string) error

ValidateInterface checks if a string can be used as an interface name.

func ValidatePlug

func ValidatePlug(name string) error

ValidatePlug checks if a string can be used as a slot name.

Slot names and plug names within one snap must have unique names. This is not enforced by this function but is enforced by snap-level validation.

func ValidateSecurityTag

func ValidateSecurityTag(tag string) error

ValidateSecurityTag validates known variants of snap security tag.

Two forms are recognised, one for apps and one for hooks. Other forms are possible but are not handled here.

TODO: handle the weird udev variant.

func ValidateSlot

func ValidateSlot(name string) error

ValidateSlot checks if a string can be used as a slot name.

Slot names and plug names within one snap must have unique names. This is not enforced by this function but is enforced by snap-level validation.

func ValidateSnap

func ValidateSnap(name string) error

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

func ValidateSnapID

func ValidateSnapID(id string) error

ValidateSnapID checks whether the string is a valid snap-id.

func ValidateSocket

func ValidateSocket(name string) error

ValidateSockeName checks if a string ca be used as a name for a socket (for socket activation).

func WellKnownSnapID

func WellKnownSnapID(snapName string) string

WellKnownSnapID returns the snap-id of well-known snaps (snapd, core*) given the snap name or the empty string otherwise.

Types

type AppSecurityTag

type AppSecurityTag interface {
	SecurityTag
	// AppName returns the name of the application.
	AppName() string
}

AppSecurityTag exposes details of a validated snap application security tag.

func ParseAppSecurityTag

func ParseAppSecurityTag(tag string) (AppSecurityTag, error)

ParseAppSecurityTag parses an app security tag.

type HookSecurityTag

type HookSecurityTag interface {
	SecurityTag
	// HookName returns the name of the hook.
	HookName() string
}

HookSecurityTag exposes details of a validated snap hook security tag.

func ParseHookSecurityTag

func ParseHookSecurityTag(tag string) (HookSecurityTag, error)

ParseHookSecurityTag parses a hook security tag.

type SecurityTag

type SecurityTag interface {
	// String returns the entire security tag.
	String() string

	// InstanceName returns the snap name and instance key.
	InstanceName() string
}

SecurityTag exposes details of a validated snap security tag.

func ParseSecurityTag

func ParseSecurityTag(tag string) (SecurityTag, error)

ParseSecurityTag parses a snap security tag and returns a parsed representation or an error.

Further type assertions can be used to described the particular form, either describing an application or a hook specific security tag.

type Snap

type Snap string

Snap references a snap by name only.

func (Snap) ID

func (s Snap) ID() string

func (Snap) SnapName

func (s Snap) SnapName() string

type SnapRef

type SnapRef interface {
	SnapName() string
	ID() string
}

A SnapRef references a snap by name and/or id.

func NewSnapRef

func NewSnapRef(name, id string) SnapRef

NewSnapRef returns a reference to the snap with given name and id.

type SnapSet

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

SnapSet can hold a set of references to snaps.

func NewSnapSet

func NewSnapSet(refs []SnapRef) *SnapSet

NewSnapSet builds a snap set with the given references.

func (*SnapSet) Add

func (s *SnapSet) Add(ref SnapRef)

Add adds one reference to the set. Already added ids or names will be ignored. The assumption is that a SnapSet is populated with distinct snaps.

func (*SnapSet) Contains

func (s *SnapSet) Contains(ref SnapRef) bool

Contains returns whether the set has a matching reference already.

func (*SnapSet) Empty

func (s *SnapSet) Empty() bool

Empty returns whether the snap set is empty.

func (*SnapSet) Lookup

func (s *SnapSet) Lookup(which SnapRef) SnapRef

Lookup finds the reference in the set matching the given one if any.

func (*SnapSet) Size

func (s *SnapSet) Size() int

Size returns the number of snaps in the snap set.

Jump to

Keyboard shortcuts

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