Documentation ¶
Index ¶
- Constants
- func API2CharmResource(apiInfo CharmResource) (charmresource.Resource, error)
- func API2Resource(apiRes Resource) (resource.Resource, error)
- func APIResult2ServiceResources(apiResult ResourcesResult) (resource.ServiceResources, error)
- func ExtractDownloadRequest(req *http.Request) string
- func ExtractDownloadResponse(resp *http.Response) (int64, charmresource.Fingerprint, error)
- func ExtractEndpointDetails(url *url.URL) (service, name string)
- func NewEndpointPath(service, name string) string
- func NewHTTPDownloadRequest(resourceName string) (*http.Request, error)
- func SendHTTPError(w http.ResponseWriter, err error)
- func SendHTTPStatusAndJSON(w http.ResponseWriter, statusCode int, response interface{})
- func UpdateDownloadResponse(resp http.ResponseWriter, resource resource.Resource)
- type AddPendingResourcesArgs
- type AddPendingResourcesResult
- type CharmResource
- type ListResourcesArgs
- type Resource
- type ResourcesResult
- type ResourcesResults
- type UnitResources
- type UploadRequest
- type UploadResult
Constants ¶
const ( // HTTPEndpointPattern is the URL path pattern registered with // the API server. This includes wildcards (starting with ":") that // are converted into URL query values by the pattern mux. Also see // apiserver/apiserver.go. HTTPEndpointPattern = "/applications/:application/resources/:resource" // HTTPEndpointPath is the URL path, with substitutions, for // a resource request. HTTPEndpointPath = "/applications/%s/resources/%s" )
const ( // ContentTypeRaw is the HTTP content-type value used for raw, unformattedcontent. ContentTypeRaw = "application/octet-stream" // ContentTypeJSON is the HTTP content-type value used for JSON content. ContentTypeJSON = "application/json" )
const ( // HeaderContentType is the header name for the type of a file upload. HeaderContentType = "Content-Type" // HeaderContentSha384 is the header name for the sha hash of a file upload. HeaderContentSha384 = "Content-Sha384" // HeaderContentLength is the header name for the length of a file upload. HeaderContentLength = "Content-Length" // HeaderContentDisposition is the header name for value that holds the filename. // The params are formatted according to RFC 2045 and RFC 2616 (see // mime.ParseMediaType and mime.FormatMediaType). HeaderContentDisposition = "Content-Disposition" )
const ( // MediaTypeFormData is the media type for file uploads (see // mime.FormatMediaType). MediaTypeFormData = "form-data" // QueryParamPendingID is the query parameter we use to send up the pending id. QueryParamPendingID = "pendingid" )
const (
// MethodPut is the common HTTP PUT method.
MethodPut = "PUT"
)
Variables ¶
This section is empty.
Functions ¶
func API2CharmResource ¶
func API2CharmResource(apiInfo CharmResource) (charmresource.Resource, error)
API2CharmResource converts an API CharmResource struct into a charm resource.
func API2Resource ¶
API2Resource converts an API Resource struct into a resource.Resource.
func APIResult2ServiceResources ¶
func APIResult2ServiceResources(apiResult ResourcesResult) (resource.ServiceResources, error)
APIResult2ServiceResources converts a ResourcesResult into a resource.ServiceResources.
func ExtractDownloadRequest ¶
ExtractDownloadRequest pulls the download request info out of the given HTTP request.
Intended for use on the server side.
func ExtractDownloadResponse ¶
func ExtractDownloadResponse(resp *http.Response) (int64, charmresource.Fingerprint, error)
ExtractDownloadResponse pulls the download size and checksum from the HTTP response.
func ExtractEndpointDetails ¶
ExtractEndpointDetails pulls the endpoint wildcard values from the provided URL.
func NewEndpointPath ¶
NewEndpointPath returns the API URL path for the identified resource.
func NewHTTPDownloadRequest ¶
NewHTTPDownloadRequest creates a new HTTP download request for the given resource.
Intended for use on the client side.
func SendHTTPError ¶
func SendHTTPError(w http.ResponseWriter, err error)
SendHTTPError sends a JSON-encoded error response for errors encountered during processing.
func SendHTTPStatusAndJSON ¶
func SendHTTPStatusAndJSON(w http.ResponseWriter, statusCode int, response interface{})
SendStatusAndJSON sends an HTTP status code and a JSON-encoded response to a client.
func UpdateDownloadResponse ¶
func UpdateDownloadResponse(resp http.ResponseWriter, resource resource.Resource)
UpdateDownloadResponse sets the appropriate headers in the response to an HTTP download request.
Intended for use on the server side.
Types ¶
type AddPendingResourcesArgs ¶
type AddPendingResourcesArgs struct { params.Entity params.AddCharmWithAuthorization // Resources is the list of resources to add as pending. Resources []CharmResource }
AddPendingResourcesArgs holds the arguments to the AddPendingResources API endpoint.
func NewAddPendingResourcesArgs ¶
func NewAddPendingResourcesArgs(applicationID string, chID charmstore.CharmID, csMac *macaroon.Macaroon, resources []charmresource.Resource) (AddPendingResourcesArgs, error)
NewAddPendingResourcesArgs returns the arguments for the AddPendingResources API endpoint.
type AddPendingResourcesResult ¶
type AddPendingResourcesResult struct { params.ErrorResult // PendingIDs holds the "pending ID" for each of the requested // resources. PendingIDs []string `json:"pending-ids"` }
AddPendingResourcesResult holds the result of the AddPendingResources API endpoint.
type CharmResource ¶
type CharmResource struct { // Name identifies the resource. Name string `json:"name"` // Type is the name of the resource type. Type string `json:"type"` // Path is where the resource will be stored. Path string `json:"path"` // Description contains user-facing info about the resource. Description string `json:"description,omitempty"` // Origin is where the resource will come from. Origin string `json:"origin"` // Revision is the revision, if applicable. Revision int `json:"revision"` // Fingerprint is the SHA-384 checksum for the resource blob. Fingerprint []byte `json:"fingerprint"` // Size is the size of the resource, in bytes. Size int64 `json:"size"` }
CharmResource contains the definition for a resource.
func CharmResource2API ¶
func CharmResource2API(res charmresource.Resource) CharmResource
CharmResource2API converts a charm resource into a CharmResource struct.
type ListResourcesArgs ¶
ListResourcesArgs are the arguments for the ListResources endpoint.
func NewListResourcesArgs ¶
func NewListResourcesArgs(services []string) (ListResourcesArgs, error)
NewListResourcesArgs returns the arguments for the ListResources endpoint.
type Resource ¶
type Resource struct { CharmResource // ID uniquely identifies a resource-application pair within the model. // Note that the model ignores pending resources (those with a // pending ID) except for in a few clearly pending-related places. ID string `json:"id"` // PendingID identifies that this resource is pending and // distinguishes it from other pending resources with the same model // ID (and from the active resource). PendingID string `json:"pending-id"` // ApplicationID identifies the application for the resource. ApplicationID string `json:"application"` // Username is the ID of the user that added the revision // to the model (whether implicitly or explicitly). Username string `json:"username"` // Timestamp indicates when the resource was added to the model. Timestamp time.Time `json:"timestamp"` }
Resource contains info about a Resource.
func Resource2API ¶
Resource2API converts a resource.Resource into a Resource struct.
type ResourcesResult ¶
type ResourcesResult struct { params.ErrorResult // Resources is the list of resources for the application. Resources []Resource `json:"resources"` // CharmStoreResources is the list of resources associated with the charm in // the charmstore. CharmStoreResources []CharmResource `json:"charm-store-resources"` // UnitResources contains a list of the resources for each unit in the // application. UnitResources []UnitResources `json:"unit-resources"` }
ResourcesResult holds the resources that result from an API call for a single application.
func ServiceResources2APIResult ¶
func ServiceResources2APIResult(svcRes resource.ServiceResources) ResourcesResult
type ResourcesResults ¶
type ResourcesResults struct { // Results is the list of resource results. Results []ResourcesResult `json:"results"` }
ResourcesResults holds the resources that result from a bulk API call.
type UnitResources ¶
type UnitResources struct { params.Entity // Resources is a list of resources for the unit. Resources []Resource `json:"resources"` // DownloadProgress indicates the number of bytes of a resource file // have been downloaded so far the uniter. Only currently downloading // resources are included. DownloadProgress map[string]int64 `json:"download-progress"` }
A UnitResources contains a list of the resources the unit defined by Entity.
type UploadRequest ¶
type UploadRequest struct { // Service is the application ID. Service string // Name is the resource name. Name string // Filename is the name of the file as it exists on disk. Filename string // Size is the size of the uploaded data, in bytes. Size int64 // Fingerprint is the fingerprint of the uploaded data. Fingerprint charmresource.Fingerprint // PendingID is the pending ID to associate with this upload, if any. PendingID string }
UploadRequest defines a single upload request.
func ExtractUploadRequest ¶
func ExtractUploadRequest(req *http.Request) (UploadRequest, error)
ExtractUploadRequest pulls the required info from the HTTP request.
func NewUploadRequest ¶
func NewUploadRequest(service, name, filename string, r io.ReadSeeker) (UploadRequest, error)
NewUploadRequest generates a new upload request for the given resource.
func (UploadRequest) HTTPRequest ¶
func (ur UploadRequest) HTTPRequest() (*http.Request, error)
HTTPRequest generates a new HTTP request.
type UploadResult ¶
type UploadResult struct { params.ErrorResult // Resource describes the resource that was stored in the model. Resource Resource `json:"resource"` }
UploadResult is the response from an upload request.