store

package
v0.0.0-...-677ed08 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2016 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package store has support to use the Ubuntu Store for querying and downloading of snaps, and the related services.

Index

Constants

View Source
const (
	DebugRequest = debugflag(1 << iota)
	DebugResponse
	DebugBody
)

set these via the Key environ

View Source
const (

	// UbuntuCoreWireProtocol is the protocol level we support when
	// communicating with the store. History:
	//  - "1": client supports squashfs snaps
	UbuntuCoreWireProtocol = "1"
)

Variables

View Source
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"
)
View Source
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 LoginUser

func LoginUser(username, password, otp string) (string, string, error)

LoginUser logs user in the store and returns the authentication macaroons.

func MacaroonDeserialize

func MacaroonDeserialize(serializedMacaroon string) (*macaroon.Macaroon, error)

MacaroonDeserialize returns a deserialized macaroon from a given store-compatible serialization

func MacaroonSerialize

func MacaroonSerialize(m *macaroon.Macaroon) (string, error)

MacaroonSerialize returns a store-compatible serialized representation of the given macaroon

func SetUserAgentFromVersion

func SetUserAgentFromVersion(version string)

Types

type AssertionNotFoundError

type AssertionNotFoundError struct {
	Ref *asserts.Ref
}

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

type ErrDownload struct {
	Code int
	URL  *url.URL
}

ErrDownload represents a download error

func (*ErrDownload) Error

func (e *ErrDownload) Error() string

type ErrInvalidAuthData

type ErrInvalidAuthData map[string][]string

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.

func (*LoggedTransport) RoundTrip

func (tr *LoggedTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip is from the http.RoundTripper interface.

type PaymentInformation

type PaymentInformation struct {
	AllowsAutomaticPayment bool             `json:"allows-automatic-payment"`
	Methods                []*PaymentMethod `json:"methods"`
}

type PaymentMethod

type PaymentMethod struct {
	BackendID           string   `json:"backend-id"`
	Currencies          []string `json:"currencies"`
	Description         string   `json:"description"`
	ID                  int      `json:"id"`
	Preferred           bool     `json:"preferred"`
	RequiresInteraction bool     `json:"requires-interaction"`
}

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 Search struct {
	Query   string
	Private bool
	Prefix  bool
}

A Search is what you do in order to Find something

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

func (s *Store) Buy(options *BuyOptions, user *auth.UserState) (*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) Find

func (s *Store) Find(search *Search, user *auth.UserState) ([]*snap.Info, error)

Find finds (installable) snaps from the store, matching the given Search.

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

func (s *Store) ReadyToBuy(user *auth.UserState) error

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

func (s *Store) SuggestedCurrency() string

SuggestedCurrency retrieves the cached value for the store's suggested currency

type User

type User struct {
	Username         string
	SSHKeys          []string
	OpenIDIdentifier string
}

func UserInfo

func UserInfo(email string) (userinfo *User, err error)

Jump to

Keyboard shortcuts

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