clientutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

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