Documentation ¶
Overview ¶
Package store has support to use the Ubuntu Store for querying and downloading of snaps, and the related services.
Index ¶
- Constants
- Variables
- func ClientUserAgent(ctx context.Context) string
- func WithClientUserAgent(parent context.Context, req *http.Request) context.Context
- type CacheManager
- type Config
- type CurrentSnap
- type DeviceAndAuthContext
- type DeviceSessionRequestParams
- type DownloadError
- type DownloadOptions
- type HashError
- type InvalidAuthDataError
- type PasswordPolicyError
- type RefreshOptions
- type RevisionNotAvailableError
- type Search
- type SnapAction
- type SnapActionError
- type SnapActionFlags
- type SnapAdder
- type SnapSpec
- type Store
- func (s *Store) Assertion(assertType *asserts.AssertionType, primaryKey []string, user *auth.UserState) (asserts.Assertion, error)
- func (s *Store) Buy(options *client.BuyOptions, user *auth.UserState) (*client.BuyResult, error)
- func (s *Store) CacheDownloads() int
- func (s *Store) ConnectivityCheck() (status map[string]bool, err error)
- func (s *Store) CreateCohorts(ctx context.Context, snaps []string) (map[string]string, error)
- func (s *Store) Download(ctx context.Context, name string, targetPath string, ...) error
- func (s *Store) DownloadStream(ctx context.Context, name string, downloadInfo *snap.DownloadInfo, ...) (io.ReadCloser, error)
- func (s *Store) EnsureDeviceSession() (*auth.DeviceState, error)
- func (s *Store) Find(ctx context.Context, search *Search, user *auth.UserState) ([]*snap.Info, error)
- func (s *Store) LoginUser(username, password, otp string) (string, string, error)
- func (s *Store) ReadyToBuy(user *auth.UserState) error
- func (s *Store) Sections(ctx context.Context, user *auth.UserState) ([]string, error)
- func (s *Store) SetCacheDownloads(fileCount int)
- func (s *Store) SnapAction(ctx context.Context, currentSnaps []*CurrentSnap, actions []*SnapAction, ...) ([]*snap.Info, error)
- func (s *Store) SnapInfo(ctx context.Context, snapSpec SnapSpec, user *auth.UserState) (*snap.Info, error)
- func (s *Store) SuggestedCurrency() string
- func (s *Store) UserInfo(email string) (userinfo *User, err error)
- func (s *Store) WriteCatalogs(ctx context.Context, names io.Writer, adder SnapAdder) error
- type User
Constants ¶
const ( // UbuntuCoreWireProtocol is the protocol level we support when // communicating with the store. History: // - "1": client supports squashfs snaps UbuntuCoreWireProtocol = "1" )
Variables ¶
var ( // macaroonACLAPI points to Developer API endpoint to get an ACL macaroon MacaroonACLAPI = developerAPIBase + "dev/api/acl/" // UbuntuoneLocation is the Ubuntuone location as defined in the store macaroon UbuntuoneLocation = authLocation() // UbuntuoneDischargeAPI points to SSO endpoint to discharge a macaroon UbuntuoneDischargeAPI = ubuntuoneAPIBase + "/tokens/discharge" // UbuntuoneRefreshDischargeAPI points to SSO endpoint to refresh a discharge macaroon UbuntuoneRefreshDischargeAPI = ubuntuoneAPIBase + "/tokens/refresh" )
var ( // ErrBadQuery is returned from Find when the query has special characters in strange places. ErrBadQuery = errors.New("bad query") // ErrSnapNotFound is returned when a snap can not be found ErrSnapNotFound = errors.New("snap not found") // ErrUnauthenticated is returned when authentication is needed to complete the query ErrUnauthenticated = errors.New("you need to log in first") // ErrAuthenticationNeeds2fa is returned if the authentication needs 2factor ErrAuthenticationNeeds2fa = errors.New("two factor authentication required") // Err2faFailed is returned when 2fa failed (e.g., a bad token was given) Err2faFailed = errors.New("two factor authentication failed") // ErrInvalidCredentials is returned on login error // It can also be returned when refreshing the discharge // macaroon if the user has changed their password. ErrInvalidCredentials = errors.New("invalid credentials") // ErrTOSNotAccepted is returned when the user has not accepted the store's terms of service. ErrTOSNotAccepted = errors.New("terms of service not accepted") // ErrNoPaymentMethods is returned when the user has no valid payment methods associated with their account. ErrNoPaymentMethods = errors.New("no payment methods") // ErrPaymentDeclined is returned when the user's payment method was declined by the upstream payment provider. ErrPaymentDeclined = errors.New("payment declined") // ErrLocalSnap is returned when an operation that only applies to snaps that come from a store was attempted on a local snap. ErrLocalSnap = errors.New("cannot perform operation on local snap") // ErrNoUpdateAvailable is returned when an update is attempetd for a snap that has no update available. ErrNoUpdateAvailable = errors.New("snap has no updates available") )
var ( // ErrNoSerial indicates that a device serial is not set yet. ErrNoSerial = errors.New("no device serial yet") )
var ErrTooManyRequests = errors.New("too many requests")
Functions ¶
func ClientUserAgent ¶
ClientUserAgent returns the user agent of the client that talks to snapd
Types ¶
type CacheManager ¶
type CacheManager struct {
// contains filtered or unexported fields
}
cacheManager implements a downloadCache via content based hard linking
func NewCacheManager ¶
func NewCacheManager(cacheDir string, maxItems int) *CacheManager
NewCacheManager returns a new CacheManager with the given cacheDir and the given maximum amount of items. The idea behind it is the following algorithm:
- When starting a download, check if it exists in $cacheDir
- If found, update its mtime, hardlink into target location, and return success
- If not found, download the snap
- On success, hardlink into $cacheDir/<digest>
- If cache dir has more than maxItems entries, remove oldest mtimes until it has maxItems
The caching part is done here, the downloading happens in the store.go code.
func (*CacheManager) Get ¶
func (cm *CacheManager) Get(cacheKey, targetPath string) error
Get gets the given cacheKey content and puts it into targetPath
func (*CacheManager) GetPath ¶
func (cm *CacheManager) GetPath(cacheKey string) string
GetPath returns the full path of the given content in the cache or empty string
func (*CacheManager) Put ¶
func (cm *CacheManager) Put(cacheKey, sourcePath string) error
Put adds a new file to the cache with the given cacheKey
type Config ¶
type Config struct { // Store API base URLs. The assertions url is only separate because it can // be overridden by its own env var. StoreBaseURL *url.URL AssertionsBaseURL *url.URL // StoreID is the store id used if we can't get one through the DeviceAndAuthContext. StoreID string Architecture string Series string DetailFields []string InfoFields []string DeltaFormat string // CacheDownloads is the number of downloads that should be cached CacheDownloads int // Proxy returns the HTTP proxy to use when talking to the store Proxy func(*http.Request) (*url.URL, error) }
Config represents the configuration to access the snap store
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a copy of the default configuration ready to be adapted.
type CurrentSnap ¶
type DeviceAndAuthContext ¶
type DeviceAndAuthContext interface { Device() (*auth.DeviceState, error) UpdateDeviceAuth(device *auth.DeviceState, sessionMacaroon string) (actual *auth.DeviceState, err error) UpdateUserAuth(user *auth.UserState, discharges []string) (actual *auth.UserState, err error) StoreID(fallback string) (string, error) DeviceSessionRequestParams(nonce string) (*DeviceSessionRequestParams, error) ProxyStoreParams(defaultURL *url.URL) (proxyStoreID string, proxySroreURL *url.URL, err error) CloudInfo() (*auth.CloudInfo, error) }
A DeviceAndAuthContext mediates access to device and auth information for the store.
type DeviceSessionRequestParams ¶
type DeviceSessionRequestParams struct { Request *asserts.DeviceSessionRequest Serial *asserts.Serial Model *asserts.Model }
DeviceSessionRequestParams gathers the assertions and information to be sent to request a device session.
func (*DeviceSessionRequestParams) EncodedModel ¶
func (p *DeviceSessionRequestParams) EncodedModel() string
func (*DeviceSessionRequestParams) EncodedRequest ¶
func (p *DeviceSessionRequestParams) EncodedRequest() string
func (*DeviceSessionRequestParams) EncodedSerial ¶
func (p *DeviceSessionRequestParams) EncodedSerial() string
type DownloadError ¶
DownloadError represents a download error
func (*DownloadError) Error ¶
func (e *DownloadError) Error() string
type DownloadOptions ¶
type InvalidAuthDataError ¶
type InvalidAuthDataError map[string]stringList
InvalidAuthDataError signals that the authentication data didn't pass validation.
func (InvalidAuthDataError) Error ¶
func (e InvalidAuthDataError) Error() string
type PasswordPolicyError ¶
type PasswordPolicyError map[string]stringList
PasswordPolicyError is returned in a few corner cases, most notably when the password has been force-reset.
func (PasswordPolicyError) Error ¶
func (e PasswordPolicyError) Error() string
type RefreshOptions ¶
type RevisionNotAvailableError ¶
RevisionNotAvailableError is returned when an install is attempted for a snap but the/a revision is not available (given install constraints).
func (*RevisionNotAvailableError) Error ¶
func (e *RevisionNotAvailableError) Error() string
type Search ¶
type Search struct { // Query is a term to search by or a prefix (if Prefix is true) Query string Prefix bool CommonID string Section string Private bool Scope string }
A Search is what you do in order to Find something
type SnapAction ¶
type SnapActionError ¶
type SnapActionError struct { // NoResults is set if the there were no results in the response NoResults bool // Refresh errors by snap name. Refresh map[string]error // Install errors by snap name. Install map[string]error // Download errors by snap name. Download map[string]error // Other errors. Other []error }
SnapActionError conveys errors that were reported on otherwise overall successful snap action (install/refresh) request.
func (SnapActionError) Error ¶
func (e SnapActionError) Error() string
type SnapActionFlags ¶
type SnapActionFlags int
const ( SnapActionIgnoreValidation SnapActionFlags = 1 << iota SnapActionEnforceValidation )
type SnapSpec ¶
type SnapSpec struct {
Name string
}
A SnapSpec describes a single snap wanted from SnapInfo
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store represents the ubuntu snap store
func New ¶
func New(cfg *Config, dauthCtx DeviceAndAuthContext) *Store
New creates a new Store with the given access configuration and for given the store id.
func (*Store) Assertion ¶
func (s *Store) Assertion(assertType *asserts.AssertionType, primaryKey []string, user *auth.UserState) (asserts.Assertion, error)
Assertion retrivies the assertion for the given type and primary key.
func (*Store) Buy ¶
Buy sends a buy request for the specified snap. Returns the state of the order: Complete, Cancelled.
func (*Store) CacheDownloads ¶
func (*Store) ConnectivityCheck ¶
func (*Store) CreateCohorts ¶
func (*Store) Download ¶
func (s *Store) Download(ctx context.Context, name string, targetPath string, downloadInfo *snap.DownloadInfo, pbar progress.Meter, user *auth.UserState, dlOpts *DownloadOptions) error
Download downloads the snap addressed by download info and returns its filename. The file is saved in temporary storage, and should be removed after use to prevent the disk from running out of space.
func (*Store) DownloadStream ¶
func (s *Store) DownloadStream(ctx context.Context, name string, downloadInfo *snap.DownloadInfo, user *auth.UserState) (io.ReadCloser, error)
DownloadStream will copy the snap from the request to the io.Reader
func (*Store) EnsureDeviceSession ¶
func (s *Store) EnsureDeviceSession() (*auth.DeviceState, error)
EnsureDeviceSession makes sure the store has a device session available. Expects the store to have an AuthContext.
func (*Store) Find ¶
func (s *Store) Find(ctx context.Context, search *Search, user *auth.UserState) ([]*snap.Info, error)
Find finds (installable) snaps from the store, matching the given Search.
func (*Store) LoginUser ¶
LoginUser logs user in the store and returns the authentication macaroons.
func (*Store) ReadyToBuy ¶
ReadyToBuy returns nil if the user's account has accepted T&Cs and has a payment method registered, and an error otherwise
func (*Store) SetCacheDownloads ¶
func (*Store) SnapAction ¶
func (s *Store) SnapAction(ctx context.Context, currentSnaps []*CurrentSnap, actions []*SnapAction, user *auth.UserState, opts *RefreshOptions) ([]*snap.Info, error)
SnapAction queries the store for snap information for the given install/refresh actions, given the context information about current installed snaps in currentSnaps. If the request was overall successul (200) but there were reported errors it will return both the snap infos and an SnapActionError.
func (*Store) SnapInfo ¶
func (s *Store) SnapInfo(ctx context.Context, snapSpec SnapSpec, user *auth.UserState) (*snap.Info, error)
SnapInfo returns the snap.Info for the store-hosted snap matching the given spec, or an error.
func (*Store) SuggestedCurrency ¶
SuggestedCurrency retrieves the cached value for the store's suggested currency