daemon

package
v0.0.0-...-9e584df Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: GPL-3.0 Imports: 77 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Unauthorized     = makeErrorResponder(401)
	NotFound         = makeErrorResponder(404)
	BadRequest       = makeErrorResponder(400)
	MethodNotAllowed = makeErrorResponder(405)
	InternalError    = makeErrorResponder(500)
	NotImplemented   = makeErrorResponder(501)
	Forbidden        = makeErrorResponder(403)
	Conflict         = makeErrorResponder(409)
)

standard error responses

View Source
var ErrRestartSocket = fmt.Errorf("daemon stop requested to wait for socket activation")

Functions

func AppNotFound

func AppNotFound(format string, v ...interface{}) *apiError

AppNotFound is an error responder used when an operation is requested on a app that doesn't exist.

func AuthCancelled

func AuthCancelled(format string, v ...interface{}) *apiError

AuthCancelled is an error responder used when a user cancelled the auth process.

func BadQuery

func BadQuery() *apiError

BadQuery is an error responder used when a bad query was provided to the store.

func InsufficientSpace

func InsufficientSpace(dserr *snapstate.InsufficientSpaceError) *apiError

InsufficientSpace is an error responder used when an operation cannot be performed due to low disk space.

func InterfacesUnchanged

func InterfacesUnchanged(format string, v ...interface{}) *apiError

InterfacesUnchanged is an error responder used when an operation that would normally change interfaces finds it has nothing to do

func QuotaChangeConflict

func QuotaChangeConflict(qce *servicestate.QuotaChangeConflictError) *apiError

QuotaChangeConflict is an error responder used when an operation would conflict with another ongoing change.

func SnapChangeConflict

func SnapChangeConflict(cce *snapstate.ChangeConflictError) *apiError

SnapChangeConflict is an error responder used when an operation would conflict with another ongoing change.

func SnapNotFound

func SnapNotFound(snapName string, err error) *apiError

SnapNotFound is an error responder used when an operation is requested on a snap that doesn't exist.

func SnapRevisionNotAvailable

func SnapRevisionNotAvailable(snapName string, rnaErr *store.RevisionNotAvailableError) *apiError

SnapRevisionNotAvailable is an error responder used when an operation is requested for which no revivision can be found in the given context (e.g. request an install from a stable channel when this channel is empty).

Types

type Command

type Command struct {
	Path       string
	PathPrefix string
	//
	GET  ResponseFunc
	PUT  ResponseFunc
	POST ResponseFunc

	// Access control.
	ReadAccess  accessChecker
	WriteAccess accessChecker
	// contains filtered or unexported fields
}

A Command routes a request to an individual per-verb ResponseFUnc

func (*Command) ServeHTTP

func (c *Command) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Daemon

type Daemon struct {
	Version string
	// contains filtered or unexported fields
}

A Daemon listens for requests and routes them to the right command

func New

func New() (*Daemon, error)

New Daemon

func (*Daemon) Dying

func (d *Daemon) Dying() <-chan struct{}

Dying is a tomb-ish thing

func (*Daemon) HandleRestart

func (d *Daemon) HandleRestart(t state.RestartType)

HandleRestart implements overlord.RestartBehavior.

func (*Daemon) Init

func (d *Daemon) Init() error

Init sets up the Daemon's internal workings. Don't call more than once.

func (*Daemon) RebootAsExpected

func (d *Daemon) RebootAsExpected(st *state.State) error

RebootAsExpected implements part of overlord.RestartBehavior.

func (*Daemon) RebootDidNotHappen

func (d *Daemon) RebootDidNotHappen(st *state.State) error

RebootDidNotHappen implements part of overlord.RestartBehavior.

func (*Daemon) SetDegradedMode

func (d *Daemon) SetDegradedMode(err error)

SetDegradedMode puts the daemon into an degraded mode which will the error given in the "err" argument for commands that are not marked as readonlyOK.

This is useful to report errors to the client when the daemon cannot work because e.g. a sanity check failed or the system is out of diskspace.

When the system is fine again calling "DegradedMode(nil)" is enough to put the daemon into full operation again.

func (*Daemon) Start

func (d *Daemon) Start() error

Start the Daemon

func (*Daemon) Stop

func (d *Daemon) Stop(sigCh chan<- os.Signal) error

Stop shuts down the Daemon

type Response

type Response interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Response knows how to serve itself.

func AssertResponse

func AssertResponse(asserts []asserts.Assertion, bundle bool) Response

AssertResponse builds a response whose ServerHTTP method serves one or a bundle of assertions.

func AsyncResponse

func AsyncResponse(result map[string]interface{}, change string) Response

AsyncResponse builds an "async" response for a created change

func SyncResponse

func SyncResponse(result interface{}) Response

SyncResponse builds a "sync" response from the given result.

type ResponseFunc

type ResponseFunc func(*Command, *http.Request, *auth.UserState) Response

A ResponseFunc handles one of the individual verbs for a method

type ResponseType

type ResponseType string

ResponseType is the response type

const (
	ResponseTypeSync  ResponseType = "sync"
	ResponseTypeAsync ResponseType = "async"
	ResponseTypeError ResponseType = "error"
)

"there are three standard return types: Standard return value, Background operation, Error", each returning a JSON object with the following "type" field:

type StructuredResponse

type StructuredResponse interface {
	Response

	JSON() *respJSON
}

A StructuredResponse serializes itself to our standard JSON response format.

Jump to

Keyboard shortcuts

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