charm

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

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

Go to latest
Published: Apr 6, 2021 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultChannelString represents the default track and risk if nothing
	// is found.
	DefaultChannelString = "latest/stable"
)

Variables

View Source
var (
	// DefaultChannel represents the default track and risk.
	DefaultChannel = Channel{
		Track: "latest",
		Risk:  Stable,
	}
	// DefaultRiskChannel represents the default only risk channel.
	DefaultRiskChannel = Channel{
		Risk: Stable,
	}
)
View Source
var Risks = []Risk{
	Stable,
	Candidate,
	Beta,
	Edge,
}

Risks is a list of the available channel risks.

Functions

func AlwaysMatchChecksum

func AlwaysMatchChecksum(string) bool

AlwaysMatchChecksum will always return true and is an effective no-op.

Types

type Channel

type Channel struct {
	Track  string
	Risk   Risk
	Branch string
}

Channel identifies and describes completely a store channel.

A channel consists of, and is subdivided by, tracks, risk-levels and branches:

  • Tracks enable snap developers to publish multiple supported releases of their application under the same snap name.
  • Risk-levels represent a progressive potential trade-off between stability and new features.
  • Branches are _optional_ and hold temporary releases intended to help with bug-fixing.

The complete channel name can be structured as three distinct parts separated by slashes:

<track>/<risk>/<branch>

func MakeChannel

func MakeChannel(track, risk, branch string) (Channel, error)

MakeChannel creates a core charm Channel from a set of component parts.

func MakePermissiveChannel

func MakePermissiveChannel(track, risk, branch string) Channel

MakePermissiveChannel creates a normalized core charm channel which never fails. It assumes that the risk has been prechecked.

func MakeRiskOnlyChannel

func MakeRiskOnlyChannel(risk string) Channel

MakeRiskOnlyChannel creates a charm channel that is backwards compatible with old style charm store channels. This creates a risk aware channel only. No validation is performed on the risk and is just accepted as is.

func MustParseChannel

func MustParseChannel(s string) Channel

MustParseChannel parses a given string or returns a panic.

func ParseChannel

func ParseChannel(s string) (Channel, error)

ParseChannel parses a string representing a store channel.

func ParseChannelNormalize

func ParseChannelNormalize(s string) (Channel, error)

ParseChannelNormalize parses a string representing a store channel. The returned channel's track, risk and name are normalized.

func (Channel) Empty

func (ch Channel) Empty() bool

Empty returns true if all it's components are empty.

func (Channel) Normalize

func (ch Channel) Normalize() Channel

Normalize the channel with normalized track, risk and names.

func (Channel) String

func (ch Channel) String() string

type ChecksumCheckFn

type ChecksumCheckFn func(string) bool

ChecksumCheckFn defines a function for running checksums against.

func MatchChecksum

func MatchChecksum(hash string) ChecksumCheckFn

MatchChecksum validates a checksum against another checksum.

type DownloadRepo

type DownloadRepo interface {
	DownloadCharm(resourceURL, archivePath string) (*charm.CharmArchive, error)
	FindDownloadURL(*charm.URL, Origin) (*url.URL, Origin, error)
}

DownloadRepo defines methods required for the repo to download a charm.

type DownloadResult

type DownloadResult struct {
	// Charm is the metadata about the charm for the archive.
	Charm StoreCharm

	// Data contains the bytes of the archive.
	Data io.Reader

	// Size is the number of bytes in Data.
	Size int64

	// SHA256 is the hash of the bytes in Data.
	SHA256 string
}

DownloadResult defines the result from the attempt to install a charm into state.

type JujuVersionValidator

type JujuVersionValidator interface {
	// Check the version is valid for the given Juju version.
	Validate(*charm.Meta) error
}

JujuVersionValidator validates the version of Juju against the charm meta data. The charm.Meta contains a MinJujuVersion and we can use that to check that for a valid charm.

type Logger

type Logger interface {
	Tracef(string, ...interface{})
	Debugf(string, ...interface{})
	Errorf(string, ...interface{})
	Warningf(string, ...interface{})

	Child(name string) Logger
}

Logger defines the logging methods that the package uses.

type Origin

type Origin struct {
	Source Source
	Type   string
	ID     string
	Hash   string

	// Users can request a revision to be installed instead of a channel, so
	// we should model that correctly here.
	Revision *int
	Channel  *Channel
	Platform Platform
}

Origin holds the original source of a charm. Information about where the charm was installed from (charm-hub, charm-store, local) and any additional information we can utilise when making modelling decisions for upgrading or changing.

type Platform

type Platform struct {
	Architecture string
	OS           string
	Series       string
}

Platform describes the platform used to install the charm with.

func MakePlatform

func MakePlatform(arch, os, series string) (Platform, error)

MakePlatform creates a core charm Platform from a set of component parts.

func MustParsePlatform

func MustParsePlatform(s string) Platform

MustParsePlatform parses a given string or returns a panic.

func ParsePlatform

func ParsePlatform(s string) (Platform, error)

ParsePlatform parses a string representing a store platform. Serialized version of platform can be expected to conform to the following:

  1. Architecture is mandatory.
  2. OS is optional and can be dropped. Release is mandatory if OS wants to be displayed.
  3. Release is also optional.

To indicate something is missing `unknown` can be used in place.

Examples:

  1. `<arch>/<os>/<series>`
  2. `<arch>`
  3. `<arch>/<series>`
  4. `<arch>/unknown/<series>`

func ParsePlatformNormalize

func ParsePlatformNormalize(s string) (Platform, error)

ParsePlatformNormalize parses a string presenting a store platform. The returned platform's architecture, os and series are normalized.

func (Platform) Normalize

func (p Platform) Normalize() Platform

Normalize the platform with normalized architecture, os and series.

func (Platform) String

func (p Platform) String() string

type Repository

type Repository interface {
	// FindDownloadURL returns a url from which a charm can be downloaded
	// based on the given charm url and charm origin.  A charm origin
	// updated with the ID and hash for the download is also returned.
	FindDownloadURL(*charm.URL, Origin) (*url.URL, Origin, error)

	// DownloadCharm reads the charm referenced the resource URL or downloads
	// into a file with the given path, which will be created if needed.
	// It is expected that the URL for charm store will be in the correct
	// form i.e that it parses to a charm.URL.
	DownloadCharm(resourceURL, archivePath string) (*charm.CharmArchive, error)

	// ResolveWithPreferredChannel verified that the charm with the requested
	// channel exists.  If no channel is specified, the latests, most stable is
	// is used. It returns a charm URL which includes the most current revision,
	// if none was provided, a charm origin, and a slice of series supported by
	// this charm.
	ResolveWithPreferredChannel(*charm.URL, Origin) (*charm.URL, Origin, []string, error)

	// ListResources returns a list of resources associated with a given charm.
	ListResources(*charm.URL, Origin) ([]charmresource.Resource, error)
}

Repository represents the necessary methods to resolve and download charms from a repository where they reside.

type Risk

type Risk string

Risk describes the type of risk in a current channel.

const (
	Stable    Risk = "stable"
	Candidate Risk = "candidate"
	Beta      Risk = "beta"
	Edge      Risk = "edge"
)

type Source

type Source string

Source represents the source of the charm.

const (
	// Local represents a local charm.
	Local Source = "local"
	// CharmStore represents a charm from the now old charmstore.
	CharmStore Source = "charm-store"
	// CharmHub represents a charm from the new charmHub.
	CharmHub Source = "charm-hub"
)

func (Source) Matches

func (c Source) Matches(o string) bool

Matches attempts to match a string to a given source.

func (Source) String

func (c Source) String() string

type State

type State interface {
	PrepareCharmUpload(*charm.URL) (StateCharm, error)
}

State defines the underlying state for handling charms.

type StateCharm

type StateCharm interface {
	IsUploaded() bool
}

StateCharm represents a stored charm from state.

type Store

type Store interface {
	// Validate checks to ensure that the charm URL is valid for the store.
	Validate(*charm.URL) error
	// Download a charm from the store using the charm URL.
	Download(*charm.URL, string, Origin) (StoreCharm, ChecksumCheckFn, Origin, error)
	// DownloadOrigin returns an origin with the id and hash, without
	// downloading the charm.
	DownloadOrigin(curl *charm.URL, origin Origin) (Origin, error)
}

Store defines the store for which the charm is being downloaded from.

type StoreCharm

type StoreCharm interface {
	charm.Charm
	charm.LXDProfiler
	Version() string
}

StoreCharm represents a store charm.

type StoreCharmHub

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

StoreCharmHub defines a type for interacting with the charm hub.

func (StoreCharmHub) Download

func (s StoreCharmHub) Download(curl *charm.URL, file string, origin Origin) (StoreCharm, ChecksumCheckFn, Origin, error)

Download the charm from the charm hub.

func (StoreCharmHub) DownloadOrigin

func (s StoreCharmHub) DownloadOrigin(curl *charm.URL, origin Origin) (Origin, error)

DownloadOrigin returns an origin with the id and hash, without downloading the charm.

func (StoreCharmHub) Validate

func (StoreCharmHub) Validate(curl *charm.URL) error

Validate checks to ensure that the schema is valid for the store.

type StoreCharmStore

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

StoreCharmStore defines a type for interacting with the charm store.

func (StoreCharmStore) Download

func (s StoreCharmStore) Download(curl *charm.URL, file string, origin Origin) (StoreCharm, ChecksumCheckFn, Origin, error)

Download the charm from the charm store.

func (StoreCharmStore) DownloadOrigin

func (s StoreCharmStore) DownloadOrigin(_ *charm.URL, origin Origin) (Origin, error)

DownloadOrigin returns the same origin provided. This operation is required for CharmHub.

func (StoreCharmStore) Validate

func (StoreCharmStore) Validate(curl *charm.URL) error

Validate checks to ensure that the schema is valid for the store.

type Strategy

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

Strategy defines a procedure for adding a charm to state.

func DownloadFromCharmHub

func DownloadFromCharmHub(logger loggo.Logger, repository DownloadRepo, curl string, force bool) (*Strategy, error)

DownloadFromCharmHub will creates a procedure to install a charm from the charm hub.

func DownloadFromCharmStore

func DownloadFromCharmStore(logger loggo.Logger, repository DownloadRepo, url string, force bool) (*Strategy, error)

DownloadFromCharmStore will creates a procedure to install a charm from the charm store.

func (*Strategy) CharmURL

func (p *Strategy) CharmURL() *charm.URL

CharmURL returns the strategy URL associated with it.

func (*Strategy) Finish

func (p *Strategy) Finish() error

Finish will attempt to close out the download procedure. Cleaning up any outstanding function tasks. If the function task errors out, then it prevents any further task from being executed. It is expected that each task correctly handles the error if they want to continue with finishing all the tasks.

func (*Strategy) Run

func (p *Strategy) Run(state State, version JujuVersionValidator, origin Origin) (DownloadResult, bool, Origin, error)

Run the download procedure against the supplied store adapter. Includes downloading the blob to a temp file and validating the contents of the charm.Meta and LXD profile data.

func (*Strategy) Validate

func (p *Strategy) Validate() error

Validate will attempt to validate the requirements for adding a charm to the store.

Jump to

Keyboard shortcuts

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