resources

package
v0.0.0-...-ed0863b Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewResourceMigrationUploadHandler

func NewResourceMigrationUploadHandler(
	resourceServiceGetter ResourceServiceGetter,
	logger logger.Logger,
) *resourcesMigrationUploadHandler

NewResourceMigrationUploadHandler returns a new HTTP handler for resources uploads during model migrations.

Types

type Downloader

type Downloader interface {
	// Download takes a request body ReadCloser containing a resource blob and
	// checks that the size and hash match the expected values. It downloads the
	// blob to a temporary file and returns a ReadCloser that deletes the
	// temporary file on closure.
	Download(
		ctx context.Context,
		reader io.ReadCloser,
		expectedSHA384 string,
		expectedSize int64,
	) (io.ReadCloser, error)
}

Downloader downloads and validates resource blobs.

type ResourceHandler

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

ResourceHandler is the HTTP handler for client downloads and uploads of resources.

func NewResourceHandler

func NewResourceHandler(
	authFunc func(*http.Request, ...string) (names.Tag, error),
	changeAllowedFunc func(context.Context) error,
	resourceServiceGetter ResourceServiceGetter,
	downloader Downloader,
	logger logger.Logger,
) *ResourceHandler

NewResourceHandler returns a new HTTP client resource handler.

func (*ResourceHandler) ServeHTTP

func (h *ResourceHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler.

type ResourceOpenerGetter

type ResourceOpenerGetter interface {
	Opener(*http.Request, ...string) (coreresource.Opener, error)
}

type ResourceService

type ResourceService interface {
	// GetResourceUUIDByApplicationAndResourceName returns the ID of the
	// application resource specified by natural key of application and resource
	// Name.
	// The following error types can be expected to be returned:
	//   - [resourceerrors.ResourceNotFound] if the specified resource does not
	//     exist.
	//   - [resourceerrors.ApplicationNotFound] if the specified application
	//     does not exist.
	GetResourceUUIDByApplicationAndResourceName(ctx context.Context, appName string, resName string) (coreresource.UUID, error)

	// GetResource returns the identified application resource.
	// The following error types can be expected to be returned:
	//   - [resourceerrors.ResourceNotFound] if the specified resource does not
	//     exist.
	GetResource(ctx context.Context, resourceUUID coreresource.UUID) (coreresource.Resource, error)

	// OpenResource returns the details of and a reader for the resource.
	// The following error types can be expected to be returned:
	//   - [resourceerrors.ResourceNotFound] if the specified resource does not
	//     exist.
	//   - [resourceerrors.StoredResourceNotFound] if the specified resource is
	//     not in the resource store.
	OpenResource(ctx context.Context, resourceUUID coreresource.UUID) (coreresource.Resource, io.ReadCloser, error)

	// StoreResource adds the application resource to blob storage and updates
	// the metadata. It also sets the retrival information for the resource.
	StoreResource(ctx context.Context, args resource.StoreResourceArgs) error

	// StoreResourceAndIncrementCharmModifiedVersion adds the application
	// resource to blob storage and updates the metadata. It also sets the
	// retrival information for the resource.
	StoreResourceAndIncrementCharmModifiedVersion(ctx context.Context, args resource.StoreResourceArgs) error

	// GetApplicationResourceID returns the ID of the application resource
	// specified by the application and resource name.
	GetApplicationResourceID(ctx context.Context, args resource.GetApplicationResourceIDArgs) (coreresource.UUID, error)

	// SetUnitResource records that the unit is using the resource.
	SetUnitResource(ctx context.Context, resourceUUID coreresource.UUID, unitUUID coreunit.UUID) error

	// UpdateUploadResource adds a new entry for an uploaded blob in the resource
	// table with the desired parameters and sets it on the application. Any previous
	// resource blob is removed. The new resource UUID is returned.
	UpdateUploadResource(ctx context.Context, resourceToUpdate coreresource.UUID) (coreresource.UUID, error)
}

ResourceService defines operations related to managing application resources.

type ResourceServiceGetter

type ResourceServiceGetter interface {
	// Resource retrieves a ResourceService for handling resource-related
	// operations.
	Resource(*http.Request) (ResourceService, error)
}

ResourceServiceGetter is an interface for retrieving a ResourceService instance.

type UnitResourcesHandler

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

UnitResourcesHandler is the HTTP handler for unit agent downloads of resources.

func NewUnitResourcesHandler

func NewUnitResourcesHandler(
	resourceOpenerGetter ResourceOpenerGetter,
	logger logger.Logger,
) *UnitResourcesHandler

NewUnitResourcesHandler returns a new HTTP handler for unit agent downloads of resources.

func (*UnitResourcesHandler) ServeHTTP

func (h *UnitResourcesHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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