naming

package
v0.0.0-...-2d3d2a1 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: GPL-3.0 Imports: 6 Imported by: 186

Documentation

Overview

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

Index

Constants

View Source
const DefaultProvenance = "global-upload"

DefaultProvenance is the default value for provenance, i.e the provenance for snaps uplodaded through the global store pipeline.

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 ValidProvenance = regexp.MustCompile("^[a-zA-Z0-9](?:-?[a-zA-Z0-9])*$")

ValidProvenance is a regular expression describing a valid provenance.

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

ValidSnapID is a regular expression describing a valid snapd-id

Functions

func CoreVersion

func CoreVersion(base string) (int, error)

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

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 SplitFullComponentName

func SplitFullComponentName(fullComp string) (string, string, error)

SplitFullComponentName splits <snap>+<comp> in <snap> and <comp> strings.

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 ValidateIfaceTag

func ValidateIfaceTag(name string) error

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

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 ValidateProvenance

func ValidateProvenance(prov string) error

ValidateProvenance checks fi the given string is valid non-empty provenance value.

func ValidateQuotaGroup

func ValidateQuotaGroup(grp string) error

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

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 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 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