import "github.com/snapcore/snapd/client"
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
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.
var ErrDangerousNotApplicable = fmt.Errorf("dangerous option only meaningful when installing from a local file")
ErrNoNames is returned by Start, Stop, or Restart, when the given list of things on which to operate is empty.
IsTwoFactorError returns whether the given error is due to problems in two-factor authentication.
MockDoRetry mocks the delays used by the do retry loop.
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 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.
IsService returns true if the application is a background daemon.
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 struct {
// contains filtered or unexported fields
}func (e AuthorizationError) Error() string
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.
Get unmarshals into value the kind-specific data with the provided key.
const (
ChangesInProgress ChangeSelector = 1 << iota
ChangesReady
ChangesAll = ChangesReady | ChangesInProgress
)func (c ChangeSelector) String() string
type ChangesOptions struct {
SnapName string // if empty, no filtering by name is done
Selector ChangeSelector
}type Client struct {
// contains filtered or unexported fields
}A Client knows how to talk to the snappy daemon.
New returns a new instance of Client
Abort attempts to abort a change that is in not yet ready.
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.
Alias sets up a manual alias from alias to app in snapName.
Aliases returns a map snap -> alias -> AliasStatus for all snaps and aliases in the system.
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).
AssertionTypes returns a list of assertion type names.
Change fetches information about a Change given its ID
func (client *Client) Changes(opts *ChangesOptions) ([]*Change, error)
func (client *Client) Conf(snapName string, keys []string) (configuration map[string]interface{}, err error)
Conf asks for a snap's current configuration.
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 *Client) Connections() (Connections, error)
Connections returns all plugs, slots and their connections.
func (client *Client) CreateUser(options *CreateUserOptions) (*CreateUserResult, error)
CreateUser creates a local system user. See CreateUserOptions for details.
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.
Debug is only useful when writing test code, it will trigger an internal action with the given parameters.
// DisableAllAliases disables all aliases of a snap, removing all manual ones.
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 *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
Icon returns the Icon belonging to an installed snap
Install adds the snap with the given name from the given channel (or the system default channel if not).
func (client *Client) InstallMany(names []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 *Client) Interfaces(opts *InterfaceOptions) ([]*Interface, error)
func (client *Client) Known(assertTypeName string, headers map[string]string) ([]asserts.Assertion, error)
Known queries assertions with type assertTypeName and matching assertion headers.
List returns the list of all snaps installed on the system with names in the given list; if the list is empty, all snaps.
LoggedInUser returns the logged in User or nil
Login logs user in.
Logout logs the user out.
Logs asks for the logs of a series of services, by name.
Prefer enables all aliases of a snap in preference to conflicting aliases of other snaps whose aliases will be disabled (removed for manual ones).
Refresh refreshes the snap with the given name (switching it to track the given channel if given).
func (client *Client) RefreshMany(names []string, options *SnapOptions) (changeID string, err error)
Remove removes the snap with the given name.
RemoveManualAlias removes a manual alias.
func (client *Client) RemoveMany(names []string, options *SnapOptions) (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.
Revert rolls the snap back to the previous on-disk state
func (client *Client) RunSnapctl(options *SnapCtlOptions) (stdout, stderr []byte, err error)
RunSnapctl requests a snapctl run for the given options.
Sections returns the list of existing snap sections in the store
func (client *Client) ServerVersion() (*ServerVersion, error)
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.
Snap returns the most recently published revision of the snap with the provided name.
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.
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.
Switch moves the snap to a different channel without a refresh
SysInfo gets system information from the REST API.
Try
Unalias tears down a manual alias or disables all aliases of a snap (removing all manual ones)
Users returns the local users.
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 struct {
// contains filtered or unexported fields
}func (e ConnectionError) Error() string
Connections contains information about all plugs, slots and their connections
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 struct {
Username string `json:"username"`
SSHKeys []string `json:"ssh-keys"`
}CreateUserResult holds the result of a user creation.
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.
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
Icon represents the icon of an installed snap
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 struct {
Action string `json:"action"`
Plugs []Plug `json:"plugs,omitempty"`
Slots []Slot `json:"slots,omitempty"`
}InterfaceAction represents an action performed on the interface system.
InterfaceOptions represents opt-in elements include in responses.
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
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.
OSRelease contains information about the system extracted from /etc/os-release.
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.
PlugRef is a reference to a plug.
type RefreshInfo struct {
Schedule string `json:"schedule"`
Last string `json:"last,omitempty"`
Next string `json:"next,omitempty"`
}type RequestError struct {
// contains filtered or unexported fields
}func (e RequestError) Error() string
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 Screenshot struct {
URL string `json:"url"`
Width int64 `json:"width,omitempty"`
Height int64 `json:"height,omitempty"`
}type ServerVersion struct {
Version string
Series string
OSID string
OSVersionID string
OnClassic bool
KernelVersion string
}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.
SlotRef is a reference to a slot.
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.
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 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 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 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 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 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 struct {
Label string `json:"label"`
Done int `json:"done"`
Total int `json:"total"`
}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.