server

package
v0.0.0-...-61a7a57 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2017 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Version is the version number of the current Facade.
	Version = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CharmStore

type CharmStore interface {
	// ListResources composes, for each of the identified charms, the
	// list of details for each of the charm's resources. Those details
	// are those associated with the specific charm revision. They
	// include the resource's metadata and revision.
	ListResources([]charmstore.CharmID) ([][]charmresource.Resource, error)

	// ResourceInfo returns the metadata for the given resource.
	ResourceInfo(charmstore.ResourceRequest) (charmresource.Resource, error)
}

CharmStore exposes the functionality of the charm store as needed here.

type Closer

type Closer func() error

Closer is a function that should be called to indicate that the datastore is finished with and can be closed.

type DataStore

type DataStore interface {
	DownloadDataStore
	UploadDataStore
	// contains filtered or unexported methods
}

DataStore is the functionality of Juju's state needed for the resources API.

type DownloadDataStore

type DownloadDataStore interface {
	// OpenResource returns the identified resource and its content.
	OpenResource(applicationID, name string) (resource.Resource, io.ReadCloser, error)
}

DownloadDataStore describes the the portion of Juju's "state" needed for handling resource download requests.

type DownloadHandler

type DownloadHandler struct {
	// Store is the data store from the resource will be retrieved.
	Store DownloadDataStore
}

DownloadHandler provides the functionality to handle download requests.

func (DownloadHandler) HandleRequest

func (dh DownloadHandler) HandleRequest(req *http.Request) (io.ReadCloser, int64, error)

HandleRequest handles a resource download request.

type Facade

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

Facade is the public API facade for resources.

func NewFacade

func NewFacade(store DataStore, newClient func() (CharmStore, error)) (*Facade, error)

NewFacade returns a new resoures facade for the given Juju state.

func (Facade) AddPendingResources

func (f Facade) AddPendingResources(args api.AddPendingResourcesArgs) (api.AddPendingResourcesResult, error)

AddPendingResources adds the provided resources (info) to the Juju model in a pending state, meaning they are not available until resolved.

func (Facade) ListResources

func (f Facade) ListResources(args api.ListResourcesArgs) (api.ResourcesResults, error)

ListResources returns the list of resources for the given application.

type HTTPHandler

type HTTPHandler struct {
	// Connect opens a connection to state resources.
	Connect func(*http.Request) (DataStore, Closer, names.Tag, error)

	// HandleDownload provides the download functionality.
	HandleDownload func(st DataStore, req *http.Request) (io.ReadCloser, int64, error)

	// HandleUpload provides the upload functionality.
	HandleUpload func(username string, st DataStore, req *http.Request) (*api.UploadResult, error)
}

HTTPHandler is the HTTP handler for the resources endpoint. We use it rather having a separate handler for each HTTP method since registered API handlers must handle *all* HTTP methods currently.

func NewHTTPHandler

func NewHTTPHandler(connect func(*http.Request) (DataStore, Closer, names.Tag, error)) *HTTPHandler

NewHTTPHandler creates a new http.Handler for the application resources endpoint.

func (*HTTPHandler) ServeHTTP

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

ServeHTTP implements http.Handler.

type UploadDataStore

type UploadDataStore interface {
	// GetResource returns the identified resource.
	GetResource(applicationID, name string) (resource.Resource, error)

	// GetPendingResource returns the identified resource.
	GetPendingResource(applicationID, name, pendingID string) (resource.Resource, error)

	// SetResource adds the resource to blob storage and updates the metadata.
	SetResource(applicationID, userID string, res charmresource.Resource, r io.Reader) (resource.Resource, error)

	// UpdatePendingResource adds the resource to blob storage and updates the metadata.
	UpdatePendingResource(applicationID, pendingID, userID string, res charmresource.Resource, r io.Reader) (resource.Resource, error)
}

UploadDataStore describes the the portion of Juju's "state" needed for handling upload requests.

type UploadHandler

type UploadHandler struct {
	// Username is the ID of the user making the upload request.
	Username string

	// Store is the data store into which the resource will be stored.
	Store UploadDataStore
}

UploadHandler provides the functionality to handle upload requests.

func (UploadHandler) HandleRequest

func (uh UploadHandler) HandleRequest(req *http.Request) (*api.UploadResult, error)

HandleRequest handles a resource upload request.

func (UploadHandler) ReadResource

func (uh UploadHandler) ReadResource(req *http.Request) (*UploadedResource, error)

ReadResource extracts the relevant info from the request.

type UploadedResource

type UploadedResource struct {
	// Service is the name of the application associated with the resource.
	Service string

	// PendingID is the resource-specific sub-ID for a pending resource.
	PendingID string

	// Resource is the information about the resource.
	Resource charmresource.Resource

	// Data holds the resource blob.
	Data io.ReadCloser
}

UploadedResource holds both the information about an uploaded resource and the reader containing its data.

Jump to

Keyboard shortcuts

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