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 LoginUser(username, password, otp string) (string, string, error)
- func MacaroonDeserialize(serializedMacaroon string) (*macaroon.Macaroon, error)
- func MacaroonSerialize(m *macaroon.Macaroon) (string, error)
- func SetUserAgentFromVersion(version string)
- type AssertionNotFoundError
- type BuyOptions
- type BuyResult
- type Config
- type ErrDownload
- type ErrInvalidAuthData
- type LoggedTransport
- type PaymentInformation
- type PaymentMethod
- type RefreshCandidate
- type Search
- type Store
- func (s *Store) Assertion(assertType *asserts.AssertionType, primaryKey []string, user *auth.UserState) (asserts.Assertion, error)
- func (s *Store) Buy(options *BuyOptions, user *auth.UserState) (*BuyResult, error)
- func (s *Store) Download(name string, downloadInfo *snap.DownloadInfo, pbar progress.Meter, ...) (path string, err error)
- func (s *Store) Find(search *Search, user *auth.UserState) ([]*snap.Info, error)
- func (s *Store) ListRefresh(installed []*RefreshCandidate, user *auth.UserState) (snaps []*snap.Info, err error)
- func (s *Store) PaymentMethods(user *auth.UserState) (*PaymentInformation, error)
- func (s *Store) ReadyToBuy(user *auth.UserState) error
- func (s *Store) Snap(name, channel string, devmode bool, revision snap.Revision, ...) (*snap.Info, error)
- func (s *Store) SuggestedCurrency() string
- type User
Constants ¶
const ( DebugRequest = debugflag(1 << iota) DebugResponse DebugBody )
set these via the Key environ
const ( // UbuntuCoreWireProtocol is the protocol level we support when // communicating with the store. History: // - "1": client supports squashfs snaps UbuntuCoreWireProtocol = "1" )
Variables ¶
var ( // MyAppsMacaroonACLAPI points to MyApps endpoint to get a ACL macaroon MyAppsMacaroonACLAPI = myappsAPIBase + "dev/api/acl/" // MyAppsDeviceNonceAPI points to MyApps endpoint to get a nonce MyAppsDeviceNonceAPI = myappsAPIBase + "identity/api/v1/nonces" // MyAppsDeviceSessionAPI points to MyApps endpoint to get a device session MyAppsDeviceSessionAPI = myappsAPIBase + "identity/api/v1/sessions" // 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 ( // ErrEmptyQuery is returned from Find when the query, stripped of any prefixes, is empty. ErrEmptyQuery = errors.New("empty query") // 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 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") )
Functions ¶
func MacaroonDeserialize ¶
MacaroonDeserialize returns a deserialized macaroon from a given store-compatible serialization
func MacaroonSerialize ¶
MacaroonSerialize returns a store-compatible serialized representation of the given macaroon
func SetUserAgentFromVersion ¶
func SetUserAgentFromVersion(version string)
Types ¶
type AssertionNotFoundError ¶
AssertionNotFoundError is returned when an assertion can not be found
func (*AssertionNotFoundError) Error ¶
func (e *AssertionNotFoundError) Error() string
type BuyOptions ¶
type BuyOptions struct { // Required SnapID string `json:"snap-id"` SnapName string `json:"snap-name"` Price float64 `json:"price"` Currency string `json:"currency"` // ISO 4217 code as string // Optional BackendID string `json:"backend-id"` // e.g. "credit_card", "paypal" MethodID int `json:"method-id"` // e.g. a particular credit card or paypal account }
BuyOptions specifies parameters for store purchases.
type BuyResult ¶
type BuyResult struct { State string `json:"state,omitempty"` RedirectTo string `json:"redirect-to,omitempty"` PartnerID string `json:"partner-id,omitempty"` }
BuyResult holds information required to complete the purchase when state is "InProgress", in which case it requires user interaction to complete.
type Config ¶
type Config struct { SearchURI *url.URL DetailsURI *url.URL BulkURI *url.URL AssertionsURI *url.URL PurchasesURI *url.URL CustomersMeURI *url.URL PaymentMethodsURI *url.URL // StoreID is the store id used if we can't get one through the AuthContext. StoreID string Architecture string Series string DetailFields []string DeltaFormats []string }
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 ErrDownload ¶
ErrDownload represents a download error
func (*ErrDownload) Error ¶
func (e *ErrDownload) Error() string
type ErrInvalidAuthData ¶
ErrInvalidAuthData signals that the authentication data didn't pass validation.
func (ErrInvalidAuthData) Error ¶
func (e ErrInvalidAuthData) Error() string
type LoggedTransport ¶
type LoggedTransport struct { Transport http.RoundTripper Key string }
LoggedTransport is an http.RoundTripper that can be used by http.Client to log request/response roundtrips.
type PaymentInformation ¶
type PaymentInformation struct { AllowsAutomaticPayment bool `json:"allows-automatic-payment"` Methods []*PaymentMethod `json:"methods"` }
type PaymentMethod ¶
type RefreshCandidate ¶
type RefreshCandidate struct { SnapID string Revision snap.Revision Epoch string DevMode bool Block []snap.Revision // the desired channel Channel string }
RefreshCandidate contains information for the store about the currently installed snap so that the store can decide what update we should see
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store represents the ubuntu snap store
func New ¶
func New(cfg *Config, authContext auth.AuthContext) *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 purchase request for the specified snap. Returns the state of the purchase: Complete, Cancelled, InProgress or Pending.
func (*Store) Download ¶
func (s *Store) Download(name string, downloadInfo *snap.DownloadInfo, pbar progress.Meter, user *auth.UserState) (path string, err 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) ListRefresh ¶
func (s *Store) ListRefresh(installed []*RefreshCandidate, user *auth.UserState) (snaps []*snap.Info, err error)
ListRefresh returns the available updates for a list of snap identified by fullname with channel.
func (*Store) PaymentMethods ¶
func (s *Store) PaymentMethods(user *auth.UserState) (*PaymentInformation, error)
PaymentMethods gets a list of the individual payment methods the user has registerd against their Ubuntu One account TODO Remove once the CLI is using the new /buy/ready endpoint
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) Snap ¶
func (s *Store) Snap(name, channel string, devmode bool, revision snap.Revision, user *auth.UserState) (*snap.Info, error)
Snap returns the snap.Info for the store hosted snap with the given name or an error.
func (*Store) SuggestedCurrency ¶
SuggestedCurrency retrieves the cached value for the store's suggested currency