Documentation
¶
Index ¶
- Constants
- func APIError(err error) (transport.APIError, error)
- func APIErrors(err error) (transport.APIErrors, error)
- func DefaultHTTPTransport() *http.Client
- func ExtractConfigInstanceKey(cfg RefreshConfig) string
- func IsAPIError(err error) bool
- func IsAPIErrors(err error) bool
- type APIRequester
- type Action
- type Client
- func (c *Client) Download(ctx context.Context, resourceURL *url.URL, archivePath string, ...) error
- func (c *Client) DownloadAndRead(ctx context.Context, resourceURL *url.URL, archivePath string, ...) (*charm.CharmArchive, error)
- func (c *Client) DownloadAndReadBundle(ctx context.Context, resourceURL *url.URL, archivePath string, ...) (charm.Bundle, error)
- func (c *Client) DownloadResource(ctx context.Context, resourceURL *url.URL) (r io.ReadCloser, err error)
- func (c *Client) Find(ctx context.Context, name string, options ...FindOption) ([]transport.FindResponse, error)
- func (c *Client) Info(ctx context.Context, name string, options ...InfoOption) (transport.InfoResponse, error)
- func (c *Client) ListResourceRevisions(ctx context.Context, charm, resource string) ([]transport.ResourceRevision, error)
- func (c *Client) Refresh(ctx context.Context, config RefreshConfig) ([]transport.RefreshResponse, error)
- func (c *Client) URL() string
- type Config
- type DownloadClient
- func (c *DownloadClient) Download(ctx context.Context, resourceURL *url.URL, archivePath string, ...) error
- func (c *DownloadClient) DownloadAndRead(ctx context.Context, resourceURL *url.URL, archivePath string, ...) (*charm.CharmArchive, error)
- func (c *DownloadClient) DownloadAndReadBundle(ctx context.Context, resourceURL *url.URL, archivePath string, ...) (*charm.BundleArchive, error)
- func (c *DownloadClient) DownloadResource(ctx context.Context, resourceURL *url.URL) (r io.ReadCloser, err error)
- type DownloadKey
- type DownloadOption
- type FileSystem
- type FindClient
- type FindOption
- func WithFindCategory(category string) FindOption
- func WithFindChannel(channel string) FindOption
- func WithFindPlatforms(platforms string) FindOption
- func WithFindPublisher(publisher string) FindOption
- func WithFindRelationProvides(relationProvides string) FindOption
- func WithFindRelationRequires(relationRequires string) FindOption
- func WithFindType(charmType string) FindOption
- type HTTPRESTClient
- type Headers
- type InfoClient
- type InfoOption
- type Logger
- type Option
- type ProgressBar
- type RESTClient
- type RESTResponse
- type RefreshClient
- type RefreshConfig
- func DownloadOne(id string, revision int, channel string, platform RefreshPlatform) (RefreshConfig, error)
- func DownloadOneFromChannel(id string, channel string, platform RefreshPlatform) (RefreshConfig, error)
- func DownloadOneFromRevision(id string, revision int, platform RefreshPlatform) (RefreshConfig, error)
- func InstallOneFromChannel(name string, channel string, platform RefreshPlatform) (RefreshConfig, error)
- func InstallOneFromRevision(name string, revision int, platform RefreshPlatform) (RefreshConfig, error)
- func RefreshMany(configs ...RefreshConfig) RefreshConfig
- func RefreshOne(id string, revision int, channel string, platform RefreshPlatform) (RefreshConfig, error)
- type RefreshPlatform
- type ResourcesClient
- type Transport
Constants ¶
const ( CharmHubServerURL = "https://api.charmhub.io" CharmHubServerVersion = "v2" CharmHubServerEntity = "charms" MetadataHeader = "X-Juju-Metadata" RefreshTimeout = 10 * time.Second )
ServerURL holds the default location of the global charm hub. An alternate location can be configured by changing the URL field in the Params struct.
const ( // NotAvailable is used a placeholder for OS and Release for a refresh // platform request, if the OS and Release is not known. NotAvailable = "NA" )
Variables ¶
This section is empty.
Functions ¶
func DefaultHTTPTransport ¶
DefaultHTTPTransport creates a new HTTPTransport.
func ExtractConfigInstanceKey ¶
func ExtractConfigInstanceKey(cfg RefreshConfig) string
ExtractConfigInstanceKey is used to get the instance key from a refresh config.
func IsAPIError ¶
IsAPIError checks to see if the error is a valid API error.
func IsAPIErrors ¶
IsAPIErrors checks to see if the error is a valid series of API errors.
Types ¶
type APIRequester ¶
type APIRequester struct {
// contains filtered or unexported fields
}
APIRequester creates a wrapper around the transport to allow for better error handling.
func NewAPIRequester ¶
func NewAPIRequester(transport Transport, logger Logger) *APIRequester
NewAPIRequester creates a new http.Client for making requests to a server.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents the client side of a charm store.
func NewClientWithFileSystem ¶
func NewClientWithFileSystem(config Config, fileSystem FileSystem) (*Client, error)
NewClientWithFileSystem creates a new charmHub client from the supplied configuration and a file system.
func (*Client) Download ¶
func (c *Client) Download(ctx context.Context, resourceURL *url.URL, archivePath string, options ...DownloadOption) error
Download defines a client for downloading charms directly.
func (*Client) DownloadAndRead ¶
func (c *Client) DownloadAndRead(ctx context.Context, resourceURL *url.URL, archivePath string, options ...DownloadOption) (*charm.CharmArchive, error)
DownloadAndRead defines a client for downloading charms directly.
func (*Client) DownloadAndReadBundle ¶
func (c *Client) DownloadAndReadBundle(ctx context.Context, resourceURL *url.URL, archivePath string, options ...DownloadOption) (charm.Bundle, error)
DownloadAndReadBundle defines a client for downloading bundles directly.
func (*Client) DownloadResource ¶
func (c *Client) DownloadResource(ctx context.Context, resourceURL *url.URL) (r io.ReadCloser, err error)
DownloadResource returns an io.ReadCloser to read the Resource from.
func (*Client) Find ¶
func (c *Client) Find(ctx context.Context, name string, options ...FindOption) ([]transport.FindResponse, error)
Find searches for a given charm for a given name from CharmHub API.
func (*Client) Info ¶
func (c *Client) Info(ctx context.Context, name string, options ...InfoOption) (transport.InfoResponse, error)
Info returns charm info on the provided charm name from CharmHub API.
func (*Client) ListResourceRevisions ¶
func (c *Client) ListResourceRevisions(ctx context.Context, charm, resource string) ([]transport.ResourceRevision, error)
ListResourceRevisions returns resource revisions for the provided charm and resource.
func (*Client) Refresh ¶
func (c *Client) Refresh(ctx context.Context, config RefreshConfig) ([]transport.RefreshResponse, error)
Refresh defines a client for making refresh API calls, that allow for updating a series of charms to the latest version.
type Config ¶
type Config struct { // URL holds the base endpoint URL of the charmHub, // with no trailing slash, not including the version. // For example https://api.charmhub.io/v2/charms/ URL string // Version holds the version attribute of the charmHub we're requesting. Version string // Entity holds the entity to target when querying the API (charm or snaps). Entity string // Headers allow the defining of a set of default headers when sending the // requests. These headers augment the headers required for sending requests // and allow overriding existing headers. Headers http.Header Logger Logger }
Config holds configuration for creating a new charm hub client.
func CharmHubConfig ¶
CharmHubConfig defines a charmHub client configuration for targeting the charmhub API.
func CharmHubConfigFromURL ¶
CharmHubConfigFromURL defines a charmHub client configuration with a given URL for targeting the API.
type DownloadClient ¶
type DownloadClient struct {
// contains filtered or unexported fields
}
DownloadClient represents a client for downloading charm resources directly.
func NewDownloadClient ¶
func NewDownloadClient(transport Transport, fileSystem FileSystem, logger Logger) *DownloadClient
NewDownloadClient creates a DownloadClient for requesting
func (*DownloadClient) Download ¶
func (c *DownloadClient) Download(ctx context.Context, resourceURL *url.URL, archivePath string, options ...DownloadOption) error
Download returns the raw charm zip file, which is retrieved from the given URL. It is expected that the archive path doesn't already exist and if it does, it will error out. It is expected that the callee handles the clean up of the archivePath. TODO (stickupkid): We should either create and remove, or take a file and let the callee remove. The fact that the operations are asymmetrical can lead to unexpected expectations; namely leaking of files.
func (*DownloadClient) DownloadAndRead ¶
func (c *DownloadClient) DownloadAndRead(ctx context.Context, resourceURL *url.URL, archivePath string, options ...DownloadOption) (*charm.CharmArchive, error)
DownloadAndRead returns a charm archive retrieved from the given URL.
func (*DownloadClient) DownloadAndReadBundle ¶
func (c *DownloadClient) DownloadAndReadBundle(ctx context.Context, resourceURL *url.URL, archivePath string, options ...DownloadOption) (*charm.BundleArchive, error)
DownloadAndReadBundle returns a bundle archive retrieved from the given URL.
func (*DownloadClient) DownloadResource ¶
func (c *DownloadClient) DownloadResource(ctx context.Context, resourceURL *url.URL) (r io.ReadCloser, err error)
DownloadResource returns an io.ReadCloser to read the Resource from.
type DownloadKey ¶
type DownloadKey string
DownloadKey represents a key for accessing the context value.
const ( // DownloadNameKey defines a name of a download, so the progress bar can // show it. DownloadNameKey DownloadKey = "download-name-key" )
type DownloadOption ¶
type DownloadOption func(*downloadOptions)
DownloadOption to be passed to Info to customize the resulting request.
func WithProgressBar ¶
func WithProgressBar(pb ProgressBar) DownloadOption
WithProgressBar sets the channel on the option.
type FileSystem ¶
type FileSystem interface { // Create creates or truncates the named file. If the file already exists, // it is truncated. Create(string) (*os.File, error) }
FileSystem defines a file system for modifying files on a users system.
func DefaultFileSystem ¶
func DefaultFileSystem() FileSystem
DefaultFileSystem is the file system used for most download requests.
type FindClient ¶
type FindClient struct {
// contains filtered or unexported fields
}
FindClient defines a client for querying information about a given charm or bundle for a given CharmHub store.
func NewFindClient ¶
func NewFindClient(path path.Path, client RESTClient, logger Logger) *FindClient
NewFindClient creates a FindClient for querying charm or bundle information.
func (*FindClient) Find ¶
func (c *FindClient) Find(ctx context.Context, query string, options ...FindOption) ([]transport.FindResponse, error)
Find searches Charm Hub and provides results matching a string.
type FindOption ¶
type FindOption func(*findOptions)
FindOption to be passed to Find to customize the resulting request.
func WithFindCategory ¶
func WithFindCategory(category string) FindOption
WithFindCategory sets the category on the option.
func WithFindChannel ¶
func WithFindChannel(channel string) FindOption
WithFindChannel sets the channel on the option.
func WithFindPlatforms ¶
func WithFindPlatforms(platforms string) FindOption
WithFindPlatforms sets the charmPlatforms on the option.
func WithFindPublisher ¶
func WithFindPublisher(publisher string) FindOption
WithFindPublisher sets the publisher on the option.
func WithFindRelationProvides ¶
func WithFindRelationProvides(relationProvides string) FindOption
WithFindRelationProvides sets the relationProvides on the option.
func WithFindRelationRequires ¶
func WithFindRelationRequires(relationRequires string) FindOption
WithFindRelationRequires sets the relationRequires on the option.
func WithFindType ¶
func WithFindType(charmType string) FindOption
WithFindType sets the charmType on the option.
type HTTPRESTClient ¶
type HTTPRESTClient struct {
// contains filtered or unexported fields
}
HTTPRESTClient represents a RESTClient that expects to interact with a HTTP transport.
func NewHTTPRESTClient ¶
func NewHTTPRESTClient(transport Transport, headers http.Header) *HTTPRESTClient
NewHTTPRESTClient creates a new HTTPRESTClient
func (*HTTPRESTClient) Get ¶
func (c *HTTPRESTClient) Get(ctx context.Context, path path.Path, result interface{}) (RESTResponse, error)
Get makes a GET request to the given path in the CharmHub (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 (*HTTPRESTClient) Post ¶
func (c *HTTPRESTClient) Post(ctx context.Context, path path.Path, headers http.Header, body, result interface{}) (RESTResponse, error)
Post makes a POST request to the given path in the CharmHub (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.
type InfoClient ¶
type InfoClient struct {
// contains filtered or unexported fields
}
InfoClient defines a client for info requests.
func NewInfoClient ¶
func NewInfoClient(path path.Path, client RESTClient, logger Logger) *InfoClient
NewInfoClient creates a InfoClient for requesting
func (*InfoClient) Info ¶
func (c *InfoClient) Info(ctx context.Context, name string, options ...InfoOption) (transport.InfoResponse, error)
Info requests the information of a given charm. If that charm doesn't exist an error stating that fact will be returned.
type InfoOption ¶
type InfoOption func(*infoOptions)
InfoOption to be passed to Info to customize the resulting request.
func WithInfoChannel ¶
func WithInfoChannel(ch string) InfoOption
WithInfoChannel sets the channel on the option.
type Logger ¶
type Logger interface { IsTraceEnabled() bool Errorf(string, ...interface{}) Debugf(string, ...interface{}) Tracef(string, ...interface{}) }
Logger is a in place interface to represent a logger for consuming.
type Option ¶
type Option func(*options)
Option to be passed into charmhub construction to customize the client.
func WithMetadataHeaders ¶
WithMetadataHeaders sets the headers on the option.
type ProgressBar ¶
type ProgressBar interface { io.Writer // Start progress with max "total" steps. Start(label string, total float64) // Finished the progress display Finished() }
ProgressBar defines a progress bar type for giving feedback to the user about the state of the download.
type RESTClient ¶
type RESTClient interface { // Get performs GET requests to a given Path. Get(context.Context, path.Path, interface{}) (RESTResponse, error) // Post performs POST requests to a given Path. Post(context.Context, path.Path, http.Header, interface{}, interface{}) (RESTResponse, error) }
RESTClient defines a type for making requests to a server.
type RESTResponse ¶
type RESTResponse struct {
StatusCode int
}
RESTResponse abstracts away the underlying response from the implementation.
type RefreshClient ¶
type RefreshClient struct {
// contains filtered or unexported fields
}
RefreshClient defines a client for refresh requests.
func NewRefreshClient ¶
func NewRefreshClient(path path.Path, client RESTClient, logger Logger) *RefreshClient
NewRefreshClient creates a RefreshClient for requesting
func (*RefreshClient) Refresh ¶
func (c *RefreshClient) Refresh(ctx context.Context, config RefreshConfig) ([]transport.RefreshResponse, error)
Refresh is used to refresh installed charms to a more suitable revision.
type RefreshConfig ¶
type RefreshConfig interface { // Build a refresh request for sending to the API. Build() (transport.RefreshRequest, Headers, error) // Ensure that the request back contains the information we requested. Ensure([]transport.RefreshResponse) error // String describes the underlying refresh config. String() string }
RefreshConfig defines a type for building refresh requests.
func DownloadOne ¶
func DownloadOne(id string, revision int, channel string, platform RefreshPlatform) (RefreshConfig, error)
DownloadOne creates a request config for requesting only one charm.
func DownloadOneFromChannel ¶
func DownloadOneFromChannel(id string, channel string, platform RefreshPlatform) (RefreshConfig, error)
DownloadOneFromChannel creates a request config using the channel and not the revision for requesting only one charm.
func DownloadOneFromRevision ¶
func DownloadOneFromRevision(id string, revision int, platform RefreshPlatform) (RefreshConfig, error)
DownloadOneFromRevision creates a request config using the revision and not the channel for requesting only one charm.
func InstallOneFromChannel ¶
func InstallOneFromChannel(name string, channel string, platform RefreshPlatform) (RefreshConfig, error)
InstallOneFromChannel creates a request config using the channel and not the revision for requesting only one charm.
func InstallOneFromRevision ¶
func InstallOneFromRevision(name string, revision int, platform RefreshPlatform) (RefreshConfig, error)
InstallOneFromRevision creates a request config using the revision and not the channel for requesting only one charm.
func RefreshMany ¶
func RefreshMany(configs ...RefreshConfig) RefreshConfig
RefreshMany will compose many refresh configs.
func RefreshOne ¶
func RefreshOne(id string, revision int, channel string, platform RefreshPlatform) (RefreshConfig, error)
RefreshOne creates a request config for requesting only one charm.
type RefreshPlatform ¶
RefreshPlatform defines a platform for selecting a specific charm.
func (RefreshPlatform) String ¶
func (p RefreshPlatform) String() string
type ResourcesClient ¶
type ResourcesClient struct {
// contains filtered or unexported fields
}
ResourcesClient defines a client for resources requests.
func NewResourcesClient ¶
func NewResourcesClient(path path.Path, client RESTClient, logger Logger) *ResourcesClient
NewResourcesClient creates a ResourcesClient for requesting
func (*ResourcesClient) ListResourceRevisions ¶
func (c *ResourcesClient) ListResourceRevisions(ctx context.Context, charm, resource string) ([]transport.ResourceRevision, error)
ListResourceRevisions returns a slice of resource revisions for the provided resource of the given charm.