clientutil

package
v0.0.0-...-20647f5 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: GPL-3.0 Imports: 17 Imported by: 42

Documentation

Overview

Package clientutil offers utilities to turn snap.Info and related structs into client structs and to work with the latter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AvailableUserSessions

func AvailableUserSessions() ([]int, error)

AvailableUserSessions returns a list of available user-session targets for snapd, by probing the available snapd-session-agent sockets in the XDG runtime directory.

func ClientAppInfoNotes

func ClientAppInfoNotes(app *client.AppInfo) string

func ClientAppInfosFromSnapAppInfos

func ClientAppInfosFromSnapAppInfos(apps []*snap.AppInfo, decorator StatusDecorator) ([]client.AppInfo, error)

ClientAppInfosFromSnapAppInfos returns client.AppInfos derived from the given snap.AppInfos. If an optional StatusDecorator is provided it will be used to add service status information as well, this will be done only if the snap is active and when the app is a service.

func ClientSnapFromSnapInfo

func ClientSnapFromSnapInfo(snapInfo *snap.Info, decorator StatusDecorator) (*client.Snap, error)

ClientSnapFromSnapInfo returns a client.Snap derived from snap.Info. If an optional StatusDecorator is provided it will be used to add service status information.

func FmtServiceStatus

func FmtServiceStatus(svc *client.AppInfo, isGlobal bool) string

FmtServiceStatus formats a given service application into the following string <snap.app> <enabled> <active> <notes> To keep output persistent between snapctl and snap cmd.

func ParseConfigValues

func ParseConfigValues(confValues []string, opts *ParseConfigOptions) (map[string]interface{}, []string, error)

ParseConfigValues parses config values in the format of "foo=bar" or "!foo", optionally a strict strings or JSON values depending on passed options. By default, values are parsed if valid JSON and stored as-is if not. Returns a map of config keys to values to set and a slice of keys in the order they were passed in.

func PrintModelAssertion

func PrintModelAssertion(w *tabwriter.Writer, modelAssertion asserts.Model, serialAssertion *asserts.Serial, modelFormatter ModelFormatter, opts PrintModelAssertionOptions) error

PrintModelAssertion will format the provided serial or model assertion based on the parameters given in YAML format, or serialize it raw if Assertion is set. The output will be written to the provided io.Writer.

func PrintModelAssertionJSON

func PrintModelAssertionJSON(w *tabwriter.Writer, modelAssertion asserts.Model, serialAssertion *asserts.Serial, opts PrintModelAssertionOptions) error

PrintModelAssertionJSON will format the provided serial or model assertion based on the parameters given in JSON format. The output will be written to the provided io.Writer.

func PrintSerialAssertionYAML

func PrintSerialAssertionYAML(w *tabwriter.Writer, serialAssertion asserts.Serial, modelFormatter ModelFormatter, opts PrintModelAssertionOptions) error

PrintModelAssertionYAML will format the provided serial or model assertion based on the parameters given in YAML format. The output will be written to the provided io.Writer.

Types

type ModelAssertJSON

type ModelAssertJSON struct {
	Headers map[string]interface{} `json:"headers,omitempty"`
	Body    string                 `json:"body,omitempty"`
}

ModelAssertJSON is used to represent a model assertion as-is in JSON.

type ModelFormatter

type ModelFormatter interface {
	// LongPublisher returns the publisher as a nicely formatted string.
	LongPublisher(storeAccountID string) string
	// GetEscapedDash returns either a double dash which is YAML safe, or the
	// special unicode dash character.
	GetEscapedDash() string
}

ModelFormatter is a helper interface to format special model elements like the publisher, which needs additional formatting. The formatting varies based on where this code needs to be used, which is why this interface is defined.

type ParseConfigOptions

type ParseConfigOptions struct {
	// String is enabled when values should be stored as-is w/o parsing being parsed.
	String bool
	// Typed is enabled when values should be stored parsed as JSON. If String is
	// enabled, this value is ignored.
	Typed bool
}

ParseConfigOptions controls how config values should be parsed.

type PrintModelAssertionOptions

type PrintModelAssertionOptions struct {
	// TermWidth is the width of the terminal for the output. This is used to format
	// the device keys in a more readable way.
	TermWidth int
	// AbsTime determines how the timestamps are formatted, if set the timestamp
	// will be formatted as RFC3339, otherwise as a human readable time.
	AbsTime bool
	// Verbose prints additional information about the provided assertion,
	// which includes most of the assertion headers. This is implicitly always
	// true when printing in JSON.
	Verbose bool
	// Assertion controls whether the provided assertion will be serialized
	// without any prior processing, which means if set, it will serialize
	// the entire assertion as-is.
	Assertion bool
}

type ServiceScopeOptions

type ServiceScopeOptions struct {
	System    bool   `long:"system"`
	User      bool   `long:"user"`
	Usernames string `long:"users"`
}

ServiceScopeOptions represents shared options between service operations that change the scope of services affected.

func (*ServiceScopeOptions) Scope

func (*ServiceScopeOptions) Users

func (*ServiceScopeOptions) Validate

func (us *ServiceScopeOptions) Validate() error

type StatusDecorator

type StatusDecorator interface {
	DecorateWithStatus(appInfo *client.AppInfo, snapApp *snap.AppInfo) error
}

A StatusDecorator is able to decorate client.AppInfos with service status.

Jump to

Keyboard shortcuts

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