store

package
v0.0.0-...-7cedb2b Latest Latest
Warning

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

Go to latest
Published: Jul 16, 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/"

	// 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")

	// 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

func DischargeAuthCaveat(caveat, username, password, otp string) (string, error)

DischargeAuthCaveat returns a macaroon with the store auth caveat discharged.

func LoginCaveatID

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

LoginCaveatID returns the 3rd party caveat from the macaroon to be discharged by Ubuntuone

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 RefreshDischargeMacaroon

func RefreshDischargeMacaroon(discharge string) (string, error)

RefreshDischargeMacaroon returns a soft-refreshed discharge macaroon.

func RequestStoreMacaroon

func RequestStoreMacaroon() (string, error)

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

type BuyResult struct {
	State      string
	RedirectTo string
	PartnerID  string
}

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

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

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.

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 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) Find

func (s *Store) Find(searchTerm string, channel string, user *auth.UserState) ([]*snap.Info, error)

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

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

func (s *Store) Snap(name, channel string, devmode bool, 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