Documentation ¶
Overview ¶
The csclient package provides access to the charm store API.
Errors returned from the remote API server with an associated error code will have a cause of type params.ErrorCode holding that code.
If a call to the API returns an error because authorization has been denied, an error with a cause satisfying IsAuthorizationError will be returned. Note that these errors can also include errors returned by httpbakery when it attempts to discharge macaroons.
Index ¶
- Constants
- Variables
- func IsAuthorizationError(err error) bool
- type Client
- func (c *Client) Channel() params.Channel
- func (c *Client) DisableStats()
- func (c *Client) Do(req *http.Request, path string) (*http.Response, error)
- func (c *Client) DoWithBody(req *http.Request, path string, body io.ReadSeeker) (*http.Response, error)
- func (c *Client) Get(path string, result interface{}) error
- func (c *Client) GetArchive(id *charm.URL) (r io.ReadCloser, eid *charm.URL, hash string, size int64, err error)
- func (c *Client) GetResource(id *charm.URL, name string, revision int) (result ResourceData, err error)
- func (cs *Client) Latest(curls []*charm.URL) ([]params.CharmRevision, error)
- func (c *Client) ListResources(id *charm.URL) ([]params.Resource, error)
- func (cs *Client) Log(typ params.LogType, level params.LogLevel, message string, urls ...*charm.URL) error
- func (cs *Client) Login() error
- func (c *Client) Meta(id *charm.URL, result interface{}) (*charm.URL, error)
- func (s *Client) Publish(id *charm.URL, channels []params.Channel, resources map[string]int) error
- func (c *Client) Put(path string, val interface{}) error
- func (c *Client) PutCommonInfo(id *charm.URL, info map[string]interface{}) error
- func (c *Client) PutExtraInfo(id *charm.URL, info map[string]interface{}) error
- func (c *Client) PutWithResponse(path string, val, result interface{}) error
- func (c *Client) ResourceMeta(id *charm.URL, name string, revision int) (params.Resource, error)
- func (c *Client) ServerURL() string
- func (c *Client) SetHTTPHeader(header http.Header)
- func (c *Client) StatsUpdate(req params.StatsUpdateRequest) error
- func (c *Client) UploadBundle(id *charm.URL, b charm.Bundle) (*charm.URL, error)
- func (c *Client) UploadBundleWithRevision(id *charm.URL, b charm.Bundle, promulgatedRevision int) error
- func (c *Client) UploadCharm(id *charm.URL, ch charm.Charm) (*charm.URL, error)
- func (c *Client) UploadCharmWithRevision(id *charm.URL, ch charm.Charm, promulgatedRevision int) error
- func (c *Client) UploadResource(id *charm.URL, name, path string, file io.ReadSeeker) (revision int, err error)
- func (cs *Client) WhoAmI() (*params.WhoAmIResponse, error)
- func (c *Client) WithChannel(channel params.Channel) *Client
- type Params
- type ReadSeekCloser
- type ResourceData
Constants ¶
const JujuMetadataHTTPHeader = "Juju-Metadata"
JujuMetadataHTTPHeader is the HTTP header name used to send Juju metadata attributes to the charm store.
Variables ¶
var ServerURL = "https://api.jujucharms.com/charmstore"
ServerURL holds the default location of the global charm store. An alternate location can be configured by changing the URL field in the Params struct. For live testing or QAing the application, a different charm store location should be used, for instance "https://api.staging.jujucharms.com".
Functions ¶
func IsAuthorizationError ¶
IsAuthorizationError reports whether the given error was returned because authorization was denied for a charmstore request.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents the client side of a charm store.
func (*Client) DisableStats ¶
func (c *Client) DisableStats()
DisableStats disables incrementing download stats when retrieving archives from the charm store.
func (*Client) Do ¶
Do makes an arbitrary request to the charm store. It adds appropriate headers to the given HTTP request, sends it to the charm store, and returns the resulting response. Do never returns a response with a status that is not http.StatusOK.
The URL field in the request is ignored and overwritten.
This is a low level method - more specific Client methods should be used when possible.
For requests with a body (for example PUT or POST) use DoWithBody instead.
func (*Client) DoWithBody ¶
func (c *Client) DoWithBody(req *http.Request, path string, body io.ReadSeeker) (*http.Response, error)
DoWithBody is like Do except that the given body is used as the body of the HTTP request.
Any error returned from the underlying httpbakery.DoWithBody request will have an unchanged error cause.
func (*Client) Get ¶
Get makes a GET request to the given path in the charm store (not including the host name or version prefix but including a leading /), parsing the result as JSON into the given result value, which should be a pointer to the expected data, but may be nil if no result is desired.
func (*Client) GetArchive ¶
func (c *Client) GetArchive(id *charm.URL) (r io.ReadCloser, eid *charm.URL, hash string, size int64, err error)
GetArchive retrieves the archive for the given charm or bundle, returning a reader its data can be read from, the fully qualified id of the corresponding entity, the hex-encoded SHA384 hash of the data and its size.
func (*Client) GetResource ¶
func (c *Client) GetResource(id *charm.URL, name string, revision int) (result ResourceData, err error)
GetResource retrieves byes of the resource with the given name and revision for the given charm, returning a reader its data can be read from, the SHA384 hash of the data and its size.
Note that the result must be closed after use.
func (*Client) Latest ¶
func (cs *Client) Latest(curls []*charm.URL) ([]params.CharmRevision, error)
Latest returns the most current revision for each of the identified charms. The revision in the provided charm URLs is ignored.
func (*Client) ListResources ¶
ListResources retrieves the metadata about resources for the given charms. It returns a slice with an element for each of the given ids, holding the resources for the respective id.
func (*Client) Log ¶
func (cs *Client) Log(typ params.LogType, level params.LogLevel, message string, urls ...*charm.URL) error
Log sends a log message to the charmstore's log database.
func (*Client) Login ¶
Login explicitly obtains authorization credentials for the charm store and stores them in the client's cookie jar. If there was an error perfoming a login interaction then the error will have a cause of type *httpbakery.InteractionError.
func (*Client) Meta ¶
Meta fetches metadata on the charm or bundle with the given id. The result value provides a value to be filled in with the result, which must be a pointer to a struct containing members corresponding to possible metadata include parameters (see https://github.com/juju/charmstore/blob/v4/docs/API.md#get-idmeta).
It returns the fully qualified id of the entity.
The name of the struct member is translated to a lower case hyphen-separated form; for example, ArchiveSize becomes "archive-size", and BundleMachineCount becomes "bundle-machine-count", but may also be specified in the field's tag
This example will fill in the result structure with information about the given id, including information on its archive size (include archive-size), upload time (include archive-upload-time) and digest (include extra-info/digest).
var result struct { ArchiveSize params.ArchiveSizeResponse ArchiveUploadTime params.ArchiveUploadTimeResponse Digest string `csclient:"extra-info/digest"` } id, err := client.Meta(id, &result)
func (*Client) Publish ¶
Publish tells the charmstore to mark the given charm as published with the given resource revisions to the given channels.
func (*Client) Put ¶
Put makes a PUT request to the given path in the charm store (not including the host name or version prefix, but including a leading /), marshaling the given value as JSON to use as the request body.
func (*Client) PutCommonInfo ¶
PutCommonInfo puts common-info data for the given id. Each entry in the info map causes a value in common-info with that key to be set to the associated value. Entries not set in the map will be unchanged.
func (*Client) PutExtraInfo ¶
PutExtraInfo puts extra-info data for the given id. Each entry in the info map causes a value in extra-info with that key to be set to the associated value. Entries not set in the map will be unchanged.
func (*Client) PutWithResponse ¶
PutWithResponse makes a PUT request to the given path in the charm store (not including the host name or version prefix, but including a leading /), marshaling the given value as JSON to use as the request body. Additionally, this method parses the result as JSON into the given result value, which should be a pointer to the expected data, but may be nil if no result is desired.
func (*Client) ResourceMeta ¶
ResourceMeta returns the metadata for the resource on charm id with the given name and revision. If the revision is negative, the latest version of the resource will be returned.
func (*Client) SetHTTPHeader ¶
SetHTTPHeader sets custom HTTP headers that will be sent to the charm store on each request.
func (*Client) StatsUpdate ¶
func (c *Client) StatsUpdate(req params.StatsUpdateRequest) error
StatsUpdate updates the download stats for the given id and specific time.
func (*Client) UploadBundle ¶
UploadBundle uploads the given charm to the charm store with the given id, which must not specify a revision. The accepted bundle implementations are charm.BundleDir and charm.BundleArchive.
UploadBundle returns the id that the bundle has been given in the store - this will be the same as id except the revision.
func (*Client) UploadBundleWithRevision ¶
func (c *Client) UploadBundleWithRevision(id *charm.URL, b charm.Bundle, promulgatedRevision int) error
UploadBundleWithRevision uploads the given bundle to the given id in the charm store, which must contain a revision. If promulgatedRevision is not -1, it specifies that the charm should be marked as promulgated with that revision.
This method is provided only for testing and should not generally be used otherwise.
func (*Client) UploadCharm ¶
UploadCharm uploads the given charm to the charm store with the given id, which must not specify a revision. The accepted charm implementations are charm.CharmDir and charm.CharmArchive.
UploadCharm returns the id that the charm has been given in the store - this will be the same as id except the revision.
func (*Client) UploadCharmWithRevision ¶
func (c *Client) UploadCharmWithRevision(id *charm.URL, ch charm.Charm, promulgatedRevision int) error
UploadCharmWithRevision uploads the given charm to the given id in the charm store, which must contain a revision. If promulgatedRevision is not -1, it specifies that the charm should be marked as promulgated with that revision.
This method is provided only for testing and should not generally be used otherwise.
func (*Client) UploadResource ¶
func (c *Client) UploadResource(id *charm.URL, name, path string, file io.ReadSeeker) (revision int, err error)
UploadResource uploads the bytes for a resource.
type Params ¶
type Params struct { // URL holds the root endpoint URL of the charmstore, // with no trailing slash, not including the version. // For example https://api.jujucharms.com/charmstore // If empty, the default charm store client location is used. URL string // User holds the name to authenticate as for the client. If User is empty, // no credentials will be sent. User string // Password holds the password for the given user, for authenticating the // client. Password string // BakeryClient holds the bakery client to use when making // requests to the store. This is used in preference to // HTTPClient. BakeryClient *httpbakery.Client // HTTPClient holds the HTTP client to use when making // requests to the store. If nil, httpbakery.NewHTTPClient will // be used. HTTPClient *http.Client // VisitWebPage is called when authorization requires that // the user visits a web page to authenticate themselves. // If nil, no interaction will be allowed. This field // is ignored if BakeryClient is provided. VisitWebPage func(url *url.URL) error // Auth holds a list of macaroons that will be added to the cookie jar of // the HTTP Client that is used by this client. Auth macaroon.Slice }
Params holds parameters for creating a new charm store client.
type ReadSeekCloser ¶
type ReadSeekCloser interface { io.ReadSeeker io.Closer }
ReadSeekCloser implements io.ReadSeeker and io.Closer.
type ResourceData ¶
type ResourceData struct { io.ReadCloser Hash string Size int64 }
ResourceData holds information about a resource. It must be closed after use.
Directories ¶
Path | Synopsis |
---|---|
The params package holds types that are a part of the charm store's external contract - they will be marshalled (or unmarshalled) as JSON and delivered through the HTTP API.
|
The params package holds types that are a part of the charm store's external contract - they will be marshalled (or unmarshalled) as JSON and delivered through the HTTP API. |