Documentation ¶
Overview ¶
Package naming implements naming constraints and concepts for snaps and their elements.
Index ¶
- Constants
- Variables
- func CoreVersion(base string) (int, error)
- func SameSnap(snapRef1, snapRef2 SnapRef) bool
- func SplitFullComponentName(fullComp string) (string, string, error)
- func UseStagingIDs(staging bool) (restore func())
- func ValidateAlias(alias string) error
- func ValidateApp(n string) error
- func ValidateHook(name string) error
- func ValidateIfaceTag(name string) error
- func ValidateInstance(instanceName string) error
- func ValidateInterface(name string) error
- func ValidatePlug(name string) error
- func ValidateProvenance(prov string) error
- func ValidateQuotaGroup(grp string) error
- func ValidateSecurityTag(tag string) error
- func ValidateSlot(name string) error
- func ValidateSnap(name string) error
- func ValidateSnapID(id string) error
- func ValidateSocket(name string) error
- func WellKnownSnapID(snapName string) string
- type AppSecurityTag
- type ComponentRef
- type HookSecurityTag
- type SecurityTag
- type Snap
- type SnapRef
- type SnapSet
Constants ¶
const DefaultProvenance = "global-upload"
DefaultProvenance is the default value for provenance, i.e the provenance for snaps uplodaded through the global store pipeline.
Variables ¶
var ValidAlias = regexp.MustCompile("^[a-zA-Z0-9][-_.a-zA-Z0-9]*$")
ValidAlias is a regular expression describing a valid alias
var ValidApp = regexp.MustCompile("^[a-zA-Z0-9](?:-?[a-zA-Z0-9])*$")
ValidApp is a regular expression describing a valid application name
var ValidProvenance = regexp.MustCompile("^[a-zA-Z0-9](?:-?[a-zA-Z0-9])*$")
ValidProvenance is a regular expression describing a valid provenance.
var ValidSnapID = regexp.MustCompile("^[a-z0-9A-Z]{32}$")
ValidSnapID is a regular expression describing a valid snapd-id
Functions ¶
func CoreVersion ¶
CoreVersion extract the version component of the core snap name Most core snap names are of the form coreXX where XX is a number. CoreVersion returns that number. In case of "core", it returns 16.
func SameSnap ¶
SameSnap returns whether the two arguments refer to the same snap. If ids are not available for both it will fallback to names.
func SplitFullComponentName ¶
SplitFullComponentName splits <snap>+<comp> in <snap> and <comp> strings.
func UseStagingIDs ¶
func UseStagingIDs(staging bool) (restore func())
func ValidateAlias ¶
ValidateAlias checks if a string can be used as an alias name.
func ValidateApp ¶
ValidateApp tells whether a string is a valid application name.
func ValidateHook ¶
ValidateHook checks if a string can be used as a hook name.
func ValidateIfaceTag ¶
ValidateIfaceTag can be used to check valid tags in interfaces. These tags are used to match plugs with slots, and although they could be arbitrary strings it is nice to keep naming consistent with what we do for snap names.
func ValidateInstance ¶
ValidateInstance checks if a string can be used as a snap instance name.
func ValidateInterface ¶
ValidateInterface checks if a string can be used as an interface name.
func ValidatePlug ¶
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 ValidateProvenance ¶
ValidateProvenance checks fi the given string is valid non-empty provenance value.
func ValidateQuotaGroup ¶
ValidateQuotaGroup checks if a string can be used as a name for a quota resource group. Currently the rules are exactly the same as for snap names. Higher levels might also reserve some names, that is not taken into account by ValidateQuotaGroup itself.
func ValidateSecurityTag ¶
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 ¶
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 ¶
ValidateSnap checks if a string can be used as a snap name.
func ValidateSnapID ¶
ValidateSnapID checks whether the string is a valid snap-id.
func ValidateSocket ¶
ValidateSockeName checks if a string ca be used as a name for a socket (for socket activation).
func WellKnownSnapID ¶
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 ComponentRef ¶
type ComponentRef struct { SnapName string `yaml:"snap-name" json:"snap-name"` ComponentName string `yaml:"component-name" json:"component-name"` }
ComponentRef contains the component name and the owner snap name.
func ComponentRefFromSnapPackFilename ¶
func ComponentRefFromSnapPackFilename(filename string) (ComponentRef, error)
ComponentRefFromSnapPackFilename parses a filename created when creating a component with "snap pack". These are generally in one of two forms:
- <snap>+<comp>.comp
- <snap>+<comp>_<version>.comp
func NewComponentRef ¶
func NewComponentRef(snapName, componentName string) ComponentRef
NewComponentRef returns a reference to a snap component.
func (ComponentRef) String ¶
func (cr ComponentRef) String() string
func (*ComponentRef) UnmarshalYAML ¶
func (cid *ComponentRef) UnmarshalYAML(unmarshall func(interface{}) error) error
func (ComponentRef) Validate ¶
func (cr ComponentRef) Validate() error
Validate validates the component.
type HookSecurityTag ¶
type HookSecurityTag interface { SecurityTag // HookName returns the name of the hook. HookName() string // ComponentName returns the name of the component that this hook is // associated with, if there is one. If this hook isn't a component hook, // this will return an empty string. ComponentName() 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 SnapRef ¶
A SnapRef references a snap by name and/or id.
func NewSnapRef ¶
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 ¶
NewSnapSet builds a snap set with the given references.
func (*SnapSet) Add ¶
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.