repositories

package
v0.0.0-...-b0bff92 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetResource

func GetResource(args GetResourceArgs) (resource.Resource, io.ReadCloser, error)

GetResource returns a reader for the resource's data. That data is streamed from the charm store.

If a cache is set up then the resource is read from there. If the resource is not in the cache at all then errors.NotFound is returned. If only the resource's details are in the cache (but not the actual file) then the file is read from the charm store. In that case the cache is updated to contain the file too.

Types

type CharmID

type CharmID struct {

	// URL of the given charm, includes the reference name and a revision.
	// Old style charm URLs are also supported i.e. charmstore.
	URL *charm.URL

	// Origin holds the origin of a charm. This includes the source of the
	// charm, along with the revision and channel to identify where the charm
	// originated from.
	Origin state.CharmOrigin
}

CharmID represents the underlying charm for a given application. This includes both the URL and the origin.

type EntityRepository

type EntityRepository interface {
	// GetResource returns the resource data for the identified resource.
	GetResource(name string) (resource.Resource, error)

	// SetResource stores the resource in the local cache.
	SetResource(res charmresource.Resource, reader io.Reader, _ state.IncrementCharmModifiedVersionType) (resource.Resource, error)

	// OpenResource returns metadata about the resource, and a reader
	// for the resource.
	OpenResource(name string) (resource.Resource, io.ReadCloser, error)

	// FetchLock provides a lock to serialize resource fetching.
	FetchLock(name string) sync.Locker
}

EntityRepository exposes the functionality needed to access data from a repository. If the data is not in state, get it from charm hub or charm store and store in state. The operations apply to a single application (or unit).

type GetResourceArgs

type GetResourceArgs struct {
	// Client is the charm store client to use.
	Client ResourceGetter

	// EntityRepository is the charm store cache to use. It is optional.
	Repository EntityRepository

	// CharmID indicates the charm for which to get the resource.
	CharmID CharmID

	// Name is the name of the resource.
	Name string
}

GetResourceArgs holds the arguments to GetResource().

type ResourceGetter

type ResourceGetter interface {
	// GetResource returns a reader for the resource's data. That data
	// is streamed from the charm store. The charm's revision, if any,
	// is ignored. If the identified resource is not in the charm store
	// then errors.NotFound is returned.
	//
	// But if you write any code that assumes a NotFound error returned
	// from this method means that the resource was not found, you fail
	// basic logic.
	GetResource(ResourceRequest) (charmstore.ResourceData, error)
}

ResourceGetter provides the functionality for getting a resource file.

type ResourceRequest

type ResourceRequest struct {
	// Channel is the channel from which to request the resource info.
	CharmID CharmID

	// Name is the name of the resource we're asking about.
	Name string

	// Revision is the specific revision of the resource we're asking about.
	Revision int
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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