client

package
v0.0.0-...-1400bc0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2016 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorKindTwoFactorRequired = "two-factor-required"
	ErrorKindTwoFactorFailed   = "two-factor-failed"
	ErrorKindLoginRequired     = "login-required"
)
View Source
const (
	StatusAvailable = "available"
	StatusInstalled = "installed"
	StatusActive    = "active"
	StatusRemoved   = "removed"

	TypeApp    = "app"
	TypeKernel = "kernel"
	TypeGadget = "gadget"
	TypeOS     = "os"
)

Statuses and types a snap may have.

Variables

View Source
var ErrNoData = fmt.Errorf("data entry not found")

Functions

func IsTwoFactorError

func IsTwoFactorError(err error) bool

IsTwoFactorError returns whether the given error is due to problems in two-factor authentication.

Types

type Change

type Change struct {
	ID      string  `json:"id"`
	Kind    string  `json:"kind"`
	Summary string  `json:"summary"`
	Status  string  `json:"status"`
	Tasks   []*Task `json:"tasks,omitempty"`
	Ready   bool    `json:"ready"`
	Err     string  `json:"err,omitempty"`

	SpawnTime time.Time `json:"spawn-time,omitempty"`
	ReadyTime time.Time `json:"ready-time,omitempty"`
	// contains filtered or unexported fields
}

A Change is a modification to the system state.

func (*Change) Get

func (c *Change) Get(key string, value interface{}) error

Get unmarshals into value the kind-specific data with the provided key.

type ChangeSelector

type ChangeSelector uint8
const (
	ChangesInProgress ChangeSelector = 1 << iota
	ChangesReady
	ChangesAll = ChangesReady | ChangesInProgress
)

func (ChangeSelector) String

func (c ChangeSelector) String() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

A Client knows how to talk to the snappy daemon.

func New

func New(config *Config) *Client

New returns a new instance of Client

func (*Client) Abort

func (client *Client) Abort(id string) (*Change, error)

Abort attempts to abort a change that is in not yet ready.

func (*Client) Ack

func (client *Client) Ack(b []byte) error

Ack tries to add an assertion to the system assertion database. To succeed the assertion must be valid, its signature verified with a known public key and the assertion consistent with and its prerequisite in the database.

func (*Client) Change

func (client *Client) Change(id string) (*Change, error)

Change fetches information about a Change given its ID

func (*Client) Changes

func (client *Client) Changes(which ChangeSelector) ([]*Change, error)

func (*Client) Connect

func (client *Client) Connect(plugSnapName, plugName, slotSnapName, slotName string) (changeID string, err error)

Connect establishes a connection between a plug and a slot. The plug and the slot must have the same interface.

func (*Client) Disconnect

func (client *Client) Disconnect(plugSnapName, plugName, slotSnapName, slotName string) (changeID string, err error)

Disconnect breaks the connection between a plug and a slot.

func (*Client) FindSnaps

func (client *Client) FindSnaps(query string) ([]*Snap, *ResultInfo, error)

FindSnaps returns a list of snaps available for install from the store for this system and that match the query

func (*Client) Icon

func (c *Client) Icon(pkgID string) (*Icon, error)

Icon returns the Icon belonging to an installed snap

func (*Client) Install

func (client *Client) Install(name string, options *SnapOptions) (changeID string, err error)

Install adds the snap with the given name from the given channel (or the system default channel if not).

func (*Client) InstallPath

func (client *Client) InstallPath(path string, options *SnapOptions) (changeID string, err error)

InstallPath sideloads the snap with the given path, returning the UUID of the background operation upon success.

func (*Client) Interfaces

func (client *Client) Interfaces() (interfaces Interfaces, err error)

Interfaces returns all plugs, slots and their connections.

func (*Client) Known

func (client *Client) Known(assertTypeName string, headers map[string]string) ([]asserts.Assertion, error)

Known queries assertions with type assertTypeName and matching assertion headers.

func (*Client) ListSnaps

func (client *Client) ListSnaps(names []string) ([]*Snap, error)

ListSnaps returns the list of all snaps installed on the system with names in the given list; if the list is empty, all snaps.

func (*Client) LoggedIn

func (client *Client) LoggedIn() bool

LoggedIn returns whether the client has authentication data available.

func (*Client) Login

func (client *Client) Login(username, password, otp string) (*User, error)

Login logs user in.

func (*Client) Logout

func (client *Client) Logout() error

Logout logs the user out.

func (*Client) Refresh

func (client *Client) Refresh(name string, options *SnapOptions) (changeID string, err error)

Refresh refreshes the snap with the given name (switching it to track the given channel if given).

func (*Client) Remove

func (client *Client) Remove(name string, options *SnapOptions) (changeID string, err error)

Remove removes the snap with the given name.

func (*Client) Snap

func (client *Client) Snap(name string) (*Snap, *ResultInfo, error)

Snap returns the most recently published revision of the snap with the provided name.

func (*Client) SysInfo

func (client *Client) SysInfo() (*SysInfo, error)

SysInfo gets system information from the REST API.

type Config

type Config struct {
	// BaseURL contains the base URL where snappy daemon is expected to be.
	// It can be empty for a default behavior of talking over a unix socket.
	BaseURL string
}

Config allows to customize client behavior.

type Error

type Error struct {
	Kind    string `json:"kind"`
	Message string `json:"message"`

	StatusCode int
}

Error is the real value of response.Result when an error occurs.

func (*Error) Error

func (e *Error) Error() string

type Icon

type Icon struct {
	Filename string
	Content  []byte
}

Icon represents the icon of an installed snap

type InterfaceAction

type InterfaceAction struct {
	Action string `json:"action"`
	Plugs  []Plug `json:"plugs,omitempty"`
	Slots  []Slot `json:"slots,omitempty"`
}

InterfaceAction represents an action performed on the interface system.

type Interfaces

type Interfaces struct {
	Plugs []Plug `json:"plugs"`
	Slots []Slot `json:"slots"`
}

Interfaces contains information about all plugs, slots and their connections

type Plug

type Plug struct {
	Snap        string                 `json:"snap"`
	Name        string                 `json:"plug"`
	Interface   string                 `json:"interface,omitempty"`
	Attrs       map[string]interface{} `json:"attrs,omitempty"`
	Apps        []string               `json:"apps,omitempty"`
	Label       string                 `json:"label,omitempty"`
	Connections []SlotRef              `json:"connections,omitempty"`
}

Plug represents the potential of a given snap to connect to a slot.

type PlugRef

type PlugRef struct {
	Snap string `json:"snap"`
	Name string `json:"plug"`
}

PlugRef is a reference to a plug.

type ResultInfo

type ResultInfo struct {
	SuggestedCurrency string `json:"suggested-currency"`
}

type Slot

type Slot struct {
	Snap        string                 `json:"snap"`
	Name        string                 `json:"slot"`
	Interface   string                 `json:"interface,omitempty"`
	Attrs       map[string]interface{} `json:"attrs,omitempty"`
	Apps        []string               `json:"apps,omitempty"`
	Label       string                 `json:"label,omitempty"`
	Connections []PlugRef              `json:"connections,omitempty"`
}

Slot represents a capacity offered by a snap.

type SlotRef

type SlotRef struct {
	Snap string `json:"snap"`
	Name string `json:"slot"`
}

SlotRef is a reference to a slot.

type Snap

type Snap struct {
	ID            string    `json:"id"`
	Summary       string    `json:"summary"`
	Description   string    `json:"description"`
	DownloadSize  int64     `json:"download-size"`
	Icon          string    `json:"icon"`
	InstalledSize int64     `json:"installed-size"`
	InstallDate   time.Time `json:"install-date"`
	Name          string    `json:"name"`
	Developer     string    `json:"developer"`
	Status        string    `json:"status"`
	Type          string    `json:"type"`
	Version       string    `json:"version"`
	Revision      int       `json:"revision"`

	Prices map[string]float64 `json:"prices"`
}

Snap holds the data for a snap as obtained from snapd.

type SnapOptions

type SnapOptions struct {
	Channel string `json:"channel,omitempty"`
	DevMode bool   `json:"devmode,omitempty"`
}

type SysInfo

type SysInfo struct {
	Flavor           string `json:"flavor"`
	Release          string `json:"release"`
	DefaultChannel   string `json:"default-channel"`
	APICompatibility string `json:"api-compat"`
	Store            string `json:"store,omitempty"`
}

SysInfo holds system information

type Task

type Task struct {
	ID       string       `json:"id"`
	Kind     string       `json:"kind"`
	Summary  string       `json:"summary"`
	Status   string       `json:"status"`
	Log      []string     `json:"log,omitempty"`
	Progress TaskProgress `json:"progress"`

	SpawnTime time.Time `json:"spawn-time,omitempty"`
	ReadyTime time.Time `json:"ready-time,omitempty"`
}

A Task is an operation done to change the system's state.

type TaskProgress

type TaskProgress struct {
	Done  int `json:"done"`
	Total int `json:"total"`
}

type User

type User struct {
	Macaroon   string   `json:"macaroon,omitempty"`
	Discharges []string `json:"discharges,omitempty"`
}

User holds logged in user information.

Jump to

Keyboard shortcuts

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