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 DischargeAuthCaveat(caveat, username, password, otp string) (string, error)
- func LoginCaveatID(m *macaroon.Macaroon) (string, error)
- func MacaroonDeserialize(serializedMacaroon string) (*macaroon.Macaroon, error)
- func MacaroonSerialize(m *macaroon.Macaroon) (string, error)
- func RefreshDischargeMacaroon(discharge string) (string, error)
- func RequestStoreMacaroon() (string, error)
- func SetUserAgentFromVersion(version string)
- type BuyOptions
- type BuyResult
- type Config
- type ErrDownload
- type LoggedTransport
- type PaymentInformation
- type PaymentMethod
- type RefreshCandidate
- type Store
- func (s *Store) Assertion(assertType *asserts.AssertionType, primaryKey []string, user *auth.UserState) (asserts.Assertion, error)
- func (s *Store) Buy(options *BuyOptions) (*BuyResult, error)
- func (s *Store) Download(name string, downloadInfo *snap.DownloadInfo, pbar progress.Meter, ...) (path string, err error)
- func (s *Store) Find(searchTerm string, channel string, 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) Snap(name, channel string, devmode bool, user *auth.UserState) (*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/" // 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") // ErrBadPrefix is returned form Find when the query has an unknown prefix. ErrBadPrefix = errors.New("bad prefix") // ErrSnapNotFound is returned when a snap can not be found ErrSnapNotFound = errors.New("snap not found") // ErrAssertionNotFound is returned when an assertion can not be found ErrAssertionNotFound = errors.New("assertion not found") // 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") )
Functions ¶
func DischargeAuthCaveat ¶
DischargeAuthCaveat returns a macaroon with the store auth caveat discharged.
func LoginCaveatID ¶
LoginCaveatID returns the 3rd party caveat from the macaroon to be discharged by Ubuntuone
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 RefreshDischargeMacaroon ¶
RefreshDischargeMacaroon returns a soft-refreshed discharge macaroon.
func RequestStoreMacaroon ¶
RequestStoreMacaroon requests a macaroon for accessing package data from the ubuntu store.
func SetUserAgentFromVersion ¶
func SetUserAgentFromVersion(version string)
Types ¶
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 User *auth.UserState `json:"-"` // 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 ¶
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 PaymentMethodsURI *url.URL DetailFields []string }
Config represents the configuration to access the snap store
type ErrDownload ¶
ErrDownload represents a download error
func (*ErrDownload) Error ¶
func (e *ErrDownload) 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, storeID string, 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 ¶
func (s *Store) Buy(options *BuyOptions) (*BuyResult, error)
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
func (*Store) Snap ¶
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