csclient

package
v0.0.0-...-ab85226 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2015 License: LGPL-3.0 Imports: 17 Imported by: 1

Documentation

Overview

The csclient package provides access to the charm store API.

Index

Constants

This section is empty.

Variables

View Source
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 New

func New(p Params) *Client

New returns a new charm store client.

func (*Client) DisableStats

func (c *Client) DisableStats()

DisableStats disables incrementing download stats when retrieving archives from the charm store.

func (*Client) Do

func (c *Client) Do(req *http.Request, path string) (*http.Response, error)

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

func (c *Client) Get(path string, result interface{}) error

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

func (cs *Client) Login() error

Login explicitly obtains authorization credentials for the charm store and stores them in the client's cookie jar.

func (*Client) Meta

func (c *Client) Meta(id *charm.Reference, result interface{}) (*charm.Reference, error)

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

func (c *Client) Put(path string, val interface{}) error

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

func (c *Client) PutExtraInfo(id *charm.Reference, info map[string]interface{}) error

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) ServerURL

func (c *Client) ServerURL() string

ServerURL returns the charm store URL used by the client.

func (*Client) SetHTTPHeader

func (c *Client) SetHTTPHeader(header http.Header)

SetHTTPHeader sets custom HTTP headers that will be sent to the charm store on each request.

func (*Client) UploadBundle

func (c *Client) UploadBundle(id *charm.Reference, b charm.Bundle) (*charm.Reference, error)

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

func (c *Client) UploadCharm(id *charm.Reference, ch charm.Charm) (*charm.Reference, error)

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.

func (*Client) WhoAmI

func (cs *Client) WhoAmI() (*params.WhoAmIResponse, error)

WhoAmI returns the user and list of groups associated with the macaroon used to authenticate.

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, no interaction will be allowed.
	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.

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.

Jump to

Keyboard shortcuts

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