snapd: github.com/snapcore/snapd/client Index | Files

package client

import "github.com/snapcore/snapd/client"

Index

Package Files

aliases.go apps.go asserts.go buy.go change.go client.go conf.go icons.go interfaces.go login.go packages.go snap_op.go snapctl.go

Constants

const (
    ErrorKindTwoFactorRequired = "two-factor-required"
    ErrorKindTwoFactorFailed   = "two-factor-failed"
    ErrorKindLoginRequired     = "login-required"
    ErrorKindTermsNotAccepted  = "terms-not-accepted"
    ErrorKindNoPaymentMethods  = "no-payment-methods"
    ErrorKindPaymentDeclined   = "payment-declined"
    ErrorKindPasswordPolicy    = "password-policy"

    ErrorKindSnapAlreadyInstalled   = "snap-already-installed"
    ErrorKindSnapNotInstalled       = "snap-not-installed"
    ErrorKindSnapNotFound           = "snap-not-found"
    ErrorKindSnapLocal              = "snap-local"
    ErrorKindSnapNeedsDevMode       = "snap-needs-devmode"
    ErrorKindSnapNeedsClassic       = "snap-needs-classic"
    ErrorKindSnapNeedsClassicSystem = "snap-needs-classic-system"
    ErrorKindNoUpdateAvailable      = "snap-no-update-available"

    ErrorKindNotSnap = "snap-not-a-snap"

    ErrorKindNetworkTimeout = "network-timeout"
)
const (
    StatusAvailable = "available"
    StatusInstalled = "installed"
    StatusActive    = "active"
    StatusRemoved   = "removed"
    StatusPriced    = "priced"

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

    StrictConfinement  = "strict"
    DevModeConfinement = "devmode"
    ClassicConfinement = "classic"
)

Statuses and types a snap may have.

const AllowInteractionHeader = "X-Allow-Interaction"

AllowInteractionHeader is the HTTP request header used to indicate that the client is willing to allow interaction.

Variables

var ErrDangerousNotApplicable = fmt.Errorf("dangerous option only meaningful when installing from a local file")
var ErrNoData = fmt.Errorf("data entry not found")
var ErrNoNames = errors.New(`"names" must not be empty`)

ErrNoNames is returned by Start, Stop, or Restart, when the given list of things on which to operate is empty.

var ErrNoSnapsInstalled = errors.New("no snaps installed")

func IsTwoFactorError Uses

func IsTwoFactorError(err error) bool

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

func MockDoRetry Uses

func MockDoRetry(retry, timeout time.Duration) (restore func())

MockDoRetry mocks the delays used by the do retry loop.

type AliasStatus Uses

type AliasStatus struct {
    Command string `json:"command"`
    Status  string `json:"status"`
    Manual  string `json:"manual,omitempty"`
    Auto    string `json:"auto,omitempty"`
}

AliasStatus represents the status of an alias.

type AppInfo Uses

type AppInfo struct {
    Snap        string `json:"snap,omitempty"`
    Name        string `json:"name"`
    DesktopFile string `json:"desktop-file,omitempty"`
    Daemon      string `json:"daemon,omitempty"`
    Enabled     bool   `json:"enabled,omitempty"`
    Active      bool   `json:"active,omitempty"`
}

AppInfo describes a single snap application.

func (*AppInfo) IsService Uses

func (a *AppInfo) IsService() bool

IsService returns true if the application is a background daemon.

type AppOptions Uses

type AppOptions struct {
    // If Service is true, only return apps that are services
    // (app.IsService() is true); otherwise, return all.
    Service bool
}

AppOptions represent the options of the Apps call.

type AuthorizationError Uses

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

func (AuthorizationError) Error Uses

func (e AuthorizationError) Error() string

type Change Uses

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 Uses

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

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

type ChangeSelector Uses

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

func (ChangeSelector) String Uses

func (c ChangeSelector) String() string

type ChangesOptions Uses

type ChangesOptions struct {
    SnapName string // if empty, no filtering by name is done
    Selector ChangeSelector
}

type Client Uses

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

A Client knows how to talk to the snappy daemon.

func New Uses

func New(config *Config) *Client

New returns a new instance of Client

func (*Client) Abort Uses

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

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

func (*Client) Ack Uses

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) Alias Uses

func (client *Client) Alias(snapName, app, alias string) (changeID string, err error)

Alias sets up a manual alias from alias to app in snapName.

func (*Client) Aliases Uses

func (client *Client) Aliases() (allStatuses map[string]map[string]AliasStatus, err error)

Aliases returns a map snap -> alias -> AliasStatus for all snaps and aliases in the system.

func (*Client) Apps Uses

func (client *Client) Apps(names []string, opts AppOptions) ([]*AppInfo, error)

Apps returns information about all matching apps. Each name can be either a snap or a snap.app. If names is empty, list all (that satisfy opts).

func (*Client) AssertionTypes Uses

func (client *Client) AssertionTypes() ([]string, error)

AssertionTypes returns a list of assertion type names.

func (*Client) Buy Uses

func (client *Client) Buy(opts *store.BuyOptions) (*store.BuyResult, error)

func (*Client) Change Uses

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

Change fetches information about a Change given its ID

func (*Client) Changes Uses

func (client *Client) Changes(opts *ChangesOptions) ([]*Change, error)

func (*Client) Conf Uses

func (client *Client) Conf(snapName string, keys []string) (configuration map[string]interface{}, err error)

Conf asks for a snap's current configuration.

func (*Client) Connect Uses

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) Connections Uses

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

Connections returns all plugs, slots and their connections.

func (*Client) CreateUser Uses

func (client *Client) CreateUser(options *CreateUserOptions) (*CreateUserResult, error)

CreateUser creates a local system user. See CreateUserOptions for details.

func (*Client) CreateUsers Uses

func (client *Client) CreateUsers(options []*CreateUserOptions) ([]*CreateUserResult, error)

CreateUsers creates multiple local system users. See CreateUserOptions for details.

Results may be provided even if there are errors.

func (*Client) Debug Uses

func (client *Client) Debug(action string, params interface{}, result interface{}) error

Debug is only useful when writing test code, it will trigger an internal action with the given parameters.

func (*Client) Disable Uses

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

func (*Client) DisableAllAliases Uses

func (client *Client) DisableAllAliases(snapName string) (changeID string, err error)

// DisableAllAliases disables all aliases of a snap, removing all manual ones.

func (*Client) Disconnect Uses

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) Enable Uses

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

func (*Client) Find Uses

func (client *Client) Find(opts *FindOptions) ([]*Snap, *ResultInfo, error)

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

func (*Client) FindOne Uses

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

func (*Client) Icon Uses

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

Icon returns the Icon belonging to an installed snap

func (*Client) Install Uses

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) InstallMany Uses

func (client *Client) InstallMany(names []string, options *SnapOptions) (changeID string, err error)

func (*Client) InstallPath Uses

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 Uses

func (client *Client) Interfaces(opts *InterfaceOptions) ([]*Interface, error)

func (*Client) Known Uses

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) List Uses

func (client *Client) List(names []string, opts *ListOptions) ([]*Snap, error)

List 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) LoggedInUser Uses

func (client *Client) LoggedInUser() *User

LoggedInUser returns the logged in User or nil

func (*Client) Login Uses

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

Login logs user in.

func (*Client) Logout Uses

func (client *Client) Logout() error

Logout logs the user out.

func (*Client) Logs Uses

func (client *Client) Logs(names []string, opts LogOptions) (<-chan Log, error)

Logs asks for the logs of a series of services, by name.

func (*Client) Prefer Uses

func (client *Client) Prefer(snapName string) (changeID string, err error)

Prefer enables all aliases of a snap in preference to conflicting aliases of other snaps whose aliases will be disabled (removed for manual ones).

func (*Client) ReadyToBuy Uses

func (client *Client) ReadyToBuy() error

func (*Client) Refresh Uses

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) RefreshMany Uses

func (client *Client) RefreshMany(names []string, options *SnapOptions) (changeID string, err error)

func (*Client) Remove Uses

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

Remove removes the snap with the given name.

func (*Client) RemoveManualAlias Uses

func (client *Client) RemoveManualAlias(alias string) (changeID string, err error)

RemoveManualAlias removes a manual alias.

func (*Client) RemoveMany Uses

func (client *Client) RemoveMany(names []string, options *SnapOptions) (changeID string, err error)

func (*Client) Restart Uses

func (client *Client) Restart(names []string, opts RestartOptions) (changeID string, err error)

Restart services.

It takes a list of names that can be snaps, of which all their services are restarted, or snap.service which are individual services to restart; it shouldn't be empty. If the service is not running, starts it.

func (*Client) Revert Uses

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

Revert rolls the snap back to the previous on-disk state

func (*Client) RunSnapctl Uses

func (client *Client) RunSnapctl(options *SnapCtlOptions) (stdout, stderr []byte, err error)

RunSnapctl requests a snapctl run for the given options.

func (*Client) Sections Uses

func (client *Client) Sections() ([]string, error)

Sections returns the list of existing snap sections in the store

func (*Client) ServerVersion Uses

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

func (*Client) SetConf Uses

func (client *Client) SetConf(snapName string, patch map[string]interface{}) (changeID string, err error)

SetConf requests a snap to apply the provided patch to the configuration.

func (*Client) Snap Uses

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) Start Uses

func (client *Client) Start(names []string, opts StartOptions) (changeID string, err error)

Start services.

It takes a list of names that can be snaps, of which all their services are started, or snap.service which are individual services to start; it shouldn't be empty.

func (*Client) Stop Uses

func (client *Client) Stop(names []string, opts StopOptions) (changeID string, err error)

Stop services.

It takes a list of names that can be snaps, of which all their services are stopped, or snap.service which are individual services to stop; it shouldn't be empty.

func (*Client) Switch Uses

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

Switch moves the snap to a different channel without a refresh

func (*Client) SysInfo Uses

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

SysInfo gets system information from the REST API.

func (*Client) Try Uses

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

Try

func (*Client) Unalias Uses

func (client *Client) Unalias(aliasOrSnap string) (changeID string, err error)

Unalias tears down a manual alias or disables all aliases of a snap (removing all manual ones)

func (*Client) Users Uses

func (client *Client) Users() ([]*User, error)

Users returns the local users.

func (*Client) WhoAmI Uses

func (client *Client) WhoAmI() (string, error)

type Config Uses

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

    // DisableAuth controls whether the client should send an
    // Authorization header from reading the auth.json data.
    DisableAuth bool

    // Interactive controls whether the client runs in interactive mode.
    // At present, this only affects whether interactive polkit
    // authorisation is requested.
    Interactive bool

    // Socket is the path to the unix socket to use
    Socket string
}

Config allows to customize client behavior.

type ConnectionError Uses

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

func (ConnectionError) Error Uses

func (e ConnectionError) Error() string

type Connections Uses

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

Connections contains information about all plugs, slots and their connections

type CreateUserOptions Uses

type CreateUserOptions struct {
    Email        string `json:"email,omitempty"`
    Sudoer       bool   `json:"sudoer,omitempty"`
    Known        bool   `json:"known,omitempty"`
    ForceManaged bool   `json:"force-managed,omitempty"`
}

CreateUserOptions holds options for creating a local system user.

If Known is false, the provided email is used to query the store for username and SSH key details.

If Known is true, the user will be created by looking through existing system-user assertions and looking for a matching email. If Email is empty then all such assertions are considered and multiple users may be created.

type CreateUserResult Uses

type CreateUserResult struct {
    Username string   `json:"username"`
    SSHKeys  []string `json:"ssh-keys"`
}

CreateUserResult holds the result of a user creation.

type Error Uses

type Error struct {
    Kind    string      `json:"kind"`
    Value   interface{} `json:"value"`
    Message string      `json:"message"`

    StatusCode int
}

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

func (*Error) Error Uses

func (e *Error) Error() string

type FindOptions Uses

type FindOptions struct {
    Refresh bool
    Private bool
    Prefix  bool
    Query   string
    Section string
}

FindOptions supports exactly one of the following options: - Refresh: only return snaps that are refreshable - Private: return snaps that are private - Query: only return snaps that match the query string

type Icon Uses

type Icon struct {
    Filename string
    Content  []byte
}

Icon represents the icon of an installed snap

type Interface Uses

type Interface struct {
    Name    string `json:"name,omitempty"`
    Summary string `json:"summary,omitempty"`
    DocURL  string `json:"doc-url,omitempty"`
    Plugs   []Plug `json:"plugs,omitempty"`
    Slots   []Slot `json:"slots,omitempty"`
}

Interface holds information about a given interface and its instances.

type InterfaceAction Uses

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 InterfaceOptions Uses

type InterfaceOptions struct {
    Names     []string
    Doc       bool
    Plugs     bool
    Slots     bool
    Connected bool
}

InterfaceOptions represents opt-in elements include in responses.

type ListOptions Uses

type ListOptions struct {
    All bool
}

type Log Uses

type Log struct {
    Timestamp time.Time `json:"timestamp"` // Timestamp of the event, in RFC3339 format to µs precision.
    Message   string    `json:"message"`   // The log message itself
    SID       string    `json:"sid"`       // The syslog identifier
    PID       string    `json:"pid"`       // The process identifier
}

A Log holds the information of a single syslog entry

func (Log) String Uses

func (l Log) String() string

type LogOptions Uses

type LogOptions struct {
    N      int  // The maximum number of log lines to retrieve initially. If <0, no limit.
    Follow bool // Whether to continue returning new lines as they appear
}

LogOptions represent the options of the Logs call.

type OSRelease Uses

type OSRelease struct {
    ID        string `json:"id"`
    VersionID string `json:"version-id,omitempty"`
}

OSRelease contains information about the system extracted from /etc/os-release.

type Plug Uses

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 Uses

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

PlugRef is a reference to a plug.

type RefreshInfo Uses

type RefreshInfo struct {
    Schedule string `json:"schedule"`
    Last     string `json:"last,omitempty"`
    Next     string `json:"next,omitempty"`
}

type RequestError Uses

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

func (RequestError) Error Uses

func (e RequestError) Error() string

type RestartOptions Uses

type RestartOptions struct {
    // Reload the services, if possible (i.e. if the App has a
    // ReloadCommand, invoque it), instead of restarting.
    Reload bool `json:"reload,omitempty"`
}

RestartOptions represent the different options of the Restart call.

type ResultInfo Uses

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

type Screenshot Uses

type Screenshot struct {
    URL    string `json:"url"`
    Width  int64  `json:"width,omitempty"`
    Height int64  `json:"height,omitempty"`
}

type ServerVersion Uses

type ServerVersion struct {
    Version     string
    Series      string
    OSID        string
    OSVersionID string
    OnClassic   bool

    KernelVersion string
}

type Slot Uses

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 Uses

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

SlotRef is a reference to a slot.

type Snap Uses

type Snap struct {
    ID               string        `json:"id"`
    Title            string        `json:"title,omitempty"`
    Summary          string        `json:"summary"`
    Description      string        `json:"description"`
    DownloadSize     int64         `json:"download-size,omitempty"`
    Icon             string        `json:"icon,omitempty"`
    InstalledSize    int64         `json:"installed-size,omitempty"`
    InstallDate      time.Time     `json:"install-date,omitempty"`
    Name             string        `json:"name"`
    Developer        string        `json:"developer"`
    Status           string        `json:"status"`
    Type             string        `json:"type"`
    Version          string        `json:"version"`
    Channel          string        `json:"channel"`
    TrackingChannel  string        `json:"tracking-channel,omitempty"`
    IgnoreValidation bool          `json:"ignore-validation"`
    Revision         snap.Revision `json:"revision"`
    Confinement      string        `json:"confinement"`
    Private          bool          `json:"private"`
    DevMode          bool          `json:"devmode"`
    JailMode         bool          `json:"jailmode"`
    TryMode          bool          `json:"trymode,omitempty"`
    Apps             []AppInfo     `json:"apps,omitempty"`
    Broken           string        `json:"broken,omitempty"`
    Contact          string        `json:"contact"`
    License          string        `json:"license,omitempty"`

    Prices      map[string]float64 `json:"prices,omitempty"`
    Screenshots []Screenshot       `json:"screenshots,omitempty"`

    // The flattended channel map with $track/$risk
    Channels map[string]*snap.ChannelSnapInfo `json:"channels,omitempty"`

    // The ordered list of tracks that contains channels
    Tracks []string `json:"tracks,omitempty"`
}

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

func (*Snap) MarshalJSON Uses

func (s *Snap) MarshalJSON() ([]byte, error)

type SnapCtlOptions Uses

type SnapCtlOptions struct {
    // ContextID is a string used to determine the context of this call (e.g.
    // which context and handler should be used, etc.)
    ContextID string `json:"context-id"`

    // Args contains a list of parameters to use for this invocation.
    Args []string `json:"args"`
}

SnapCtlOptions holds the various options with which snapctl is invoked.

type SnapOptions Uses

type SnapOptions struct {
    Channel          string `json:"channel,omitempty"`
    Revision         string `json:"revision,omitempty"`
    DevMode          bool   `json:"devmode,omitempty"`
    JailMode         bool   `json:"jailmode,omitempty"`
    Classic          bool   `json:"classic,omitempty"`
    Dangerous        bool   `json:"dangerous,omitempty"`
    IgnoreValidation bool   `json:"ignore-validation,omitempty"`
    Unaliased        bool   `json:"unaliased,omitempty"`
}

type StartOptions Uses

type StartOptions struct {
    // Enable, as well as starting, the listed services. A
    // disabled service does not start on boot.
    Enable bool `json:"enable,omitempty"`
}

StartOptions represent the different options of the Start call.

type StopOptions Uses

type StopOptions struct {
    // Disable, as well as stopping, the listed services. A
    // service that is not disabled starts on boot.
    Disable bool `json:"disable,omitempty"`
}

StopOptions represent the different options of the Stop call.

type SysInfo Uses

type SysInfo struct {
    Series    string    `json:"series,omitempty"`
    Version   string    `json:"version,omitempty"`
    OSRelease OSRelease `json:"os-release"`
    OnClassic bool      `json:"on-classic"`
    Managed   bool      `json:"managed"`

    KernelVersion string `json:"kernel-version,omitempty"`

    Refresh     RefreshInfo `json:"refresh,omitempty"`
    Confinement string      `json:"confinement"`
}

SysInfo holds system information

type Task Uses

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 Uses

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

type User Uses

type User struct {
    ID       int    `json:"id,omitempty"`
    Username string `json:"username,omitempty"`
    Email    string `json:"email,omitempty"`

    Macaroon   string   `json:"macaroon,omitempty"`
    Discharges []string `json:"discharges,omitempty"`
}

User holds logged in user information.

Package client imports 24 packages (graph) and is imported by 29 packages. Updated 2018-01-10. Refresh now. Tools for package owners.