Documentation ¶
Overview ¶
The csclient package provides access to the charm store API.
Index ¶
- Variables
- type Client
- 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, getBody httpbakery.BodyGetter) (*http.Response, error)
- func (c *Client) Get(path string, result interface{}) error
- func (c *Client) GetArchive(id *charm.Reference) (r io.ReadCloser, eid *charm.Reference, hash string, size int64, err error)
- func (cs *Client) Log(typ params.LogType, level params.LogLevel, message string, ...) error
- func (cs *Client) Login() error
- func (c *Client) Meta(id *charm.Reference, result interface{}) (*charm.Reference, error)
- func (c *Client) Put(path string, val interface{}) error
- func (c *Client) PutExtraInfo(id *charm.Reference, info map[string]interface{}) error
- func (c *Client) ServerURL() string
- func (c *Client) SetHTTPHeader(header http.Header)
- func (c *Client) UploadBundle(id *charm.Reference, b charm.Bundle) (*charm.Reference, error)
- func (c *Client) UploadBundleWithRevision(id *charm.Reference, b charm.Bundle, promulgatedRevision int) error
- func (c *Client) UploadCharm(id *charm.Reference, ch charm.Charm) (*charm.Reference, error)
- func (c *Client) UploadCharmWithRevision(id *charm.Reference, ch charm.Charm, promulgatedRevision int) error
- type Params
- type ReadSeekCloser
Constants ¶
This section is empty.
Variables ¶
var ErrNoInteraction = errgo.New("interaction required but no web browser configured")
ErrNoInteraction is the error cause returned by the default Params.VisitWebPage value when it is nil.
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 ¶
This section is empty.
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, getBody httpbakery.BodyGetter) (*http.Response, error)
DoWithBody is like Do except that the given getBody function is called to obtain the body for the HTTP request. Any body returned by getBody will be closed before DoWithBody returns.
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.Reference) (r io.ReadCloser, eid *charm.Reference, 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 SHA384 hash of the data and its size.
func (*Client) Log ¶
func (cs *Client) Log(typ params.LogType, level params.LogLevel, message string, urls ...*charm.Reference) 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.
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) 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) 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) SetHTTPHeader ¶
SetHTTPHeader sets custom HTTP headers that will be sent to the charm store on each request.
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.Reference, 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.Reference, 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.
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 and Password hold the authentication credentials // for the client. If User is empty, no credentials will be // sent. User string Password string // 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, a default function that returns ErrNoInteraction will be used. VisitWebPage func(url *url.URL) error }
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.