resource

package
v0.0.0-...-0a82276 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewResourceDownloadLimiter

func NewResourceDownloadLimiter(globalLimit, applicationLimit int) *resourceDownloadLimiter

NewResourceDownloadLimiter creates a new resource download limiter.

func NewResourceOpener

func NewResourceOpener(
	args ResourceOpenerArgs,
	resourceDownloadLimiterFunc func() ResourceDownloadLock,
	unitName string,
) (opener resource.Opener, err error)

NewResourceOpener returns a new resource.Opener for the given unit.

The caller owns the State provided. It is the caller's responsibility to close it.

func NewResourceOpenerForApplication

func NewResourceOpenerForApplication(
	args ResourceOpenerArgs,
	applicationName string,
) (opener resource.Opener, err error)

NewResourceOpenerForApplication returns a new resource.Opener for the given app.

The caller owns the State provided. It is the caller's responsibility to close it.

Types

type CharmHub

type CharmHub interface {
	DownloadResource(ctx context.Context, resourceURL *url.URL) (r io.ReadCloser, err error)
	Refresh(ctx context.Context, config charmhub.RefreshConfig) ([]transport.RefreshResponse, error)
}

CharmHub represents methods required from a charmhub client talking to the charmhub api used by the local CharmHubClient

type CharmHubClient

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

func (*CharmHubClient) GetResource

func (ch *CharmHubClient) GetResource(req ResourceRequest) (ResourceData, error)

GetResource returns data about the resource including an io.ReadCloser to download the resource. The caller is responsible for closing it.

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 ModelConfigService

type ModelConfigService interface {
	// ModelConfig returns the current config for the model.
	ModelConfig(context.Context) (*config.Config, error)
}

ModelConfigService provides access to the model configuration.

type ResourceData

type ResourceData struct {
	// ReadCloser holds the bytes for the resource.
	io.ReadCloser

	// Resource holds the metadata for the resource.
	Resource charmresource.Resource
}

ResourceData represents the response from store about a request for resource bytes.

type ResourceDownloadLock

type ResourceDownloadLock interface {
	// Acquire grabs the lock for a given application so long as the
	// per application limit is not exceeded and total across all
	// applications does not exceed the global limit.
	Acquire(appName string)

	// Release releases the lock for the given application.
	Release(appName string)
}

ResourceDownloadLock is used to limit the number of concurrent resource downloads and per application. The total number of downloads across all applications cannot exceed the global limit.

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) (ResourceData, error)
}

ResourceGetter provides the functionality for getting a resource file.

type ResourceOpener

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

ResourceOpener is a ResourceOpener for charmhub. It will first look in the supplied cache for the requested resource.

func (*ResourceOpener) OpenResource

func (ro *ResourceOpener) OpenResource(ctx context.Context, name string) (o resource.Opened, err error)

OpenResource implements server.ResourceOpener.

type ResourceOpenerArgs

type ResourceOpenerArgs struct {
	State              *state.State
	ModelConfigService ModelConfigService
	Store              objectstore.ObjectStore
}

ResourceOpenerArgs are common arguments for the 2 types of ResourceOpeners: for unit and for application.

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
}

type ResourceRetryClient

type ResourceRetryClient struct {
	ResourceGetter
	// contains filtered or unexported fields
}

ResourceRetryClient is a wrapper around a Juju repository client that retries GetResource() calls.

func (ResourceRetryClient) GetResource

func (client ResourceRetryClient) GetResource(req ResourceRequest) (ResourceData, error)

GetResource returns a reader for the resource's data.

type Resources

type Resources interface {
	// GetResource returns the identified resource.
	GetResource(applicationID, name string) (resource.Resource, error)
	// OpenResource returns the metadata for a resource and a reader for the resource.
	OpenResource(applicationID, name string) (resource.Resource, io.ReadCloser, error)
	// OpenResourceForUniter returns the metadata for a resource and a reader for the resource.
	OpenResourceForUniter(unitName, resName string) (resource.Resource, io.ReadCloser, error)
	// SetResource adds the resource to blob storage and updates the metadata.
	SetResource(applicationID, userID string, res charmresource.Resource, r io.Reader, _ state.IncrementCharmModifiedVersionType) (resource.Resource, error)
}

Resources represents the methods used by the resource opener from state.Resources.

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