Documentation ¶
Overview ¶
Package command facilitates calling commands within the guest-agent.
Index ¶
Constants ¶
const DefaultPipePath = "/run/google-guest-agent/commands.sock"
DefaultPipePath is the default unix socket path for linux.
Variables ¶
var ( // CmdNotFoundError is return when there is no handler for the request command CmdNotFoundError = Response{ Status: 101, StatusMessage: "Could not find a handler for the requested command", } // BadRequestError is returned for invalid or unparseable JSON BadRequestError = Response{ Status: 102, StatusMessage: "Could not parse valid JSON from request", } // ConnError is returned for errors from the underlying communication protocol ConnError = Response{ Status: 103, StatusMessage: "Connection error", } // TimeoutError is returned when the timeout period elapses before valid JSON is receieved TimeoutError = Response{ Status: 104, StatusMessage: "Connection timeout before reading valid request", } // HandlerError is returned when the handler function returns an non-nil error. The status message will be replaced with the returnd error string. HandlerError = Response{ Status: 105, StatusMessage: "The command handler encountered an error processing your request", } // InternalErrorCode is the error code for internal command server errors. Returned when failing to marshal a response. InternalErrorCode = 106 )
Functions ¶
func Close ¶
func Close() error
Close will close the internally managed command server, if it was initialized.
func Init ¶
Init starts an internally managed command server. The agent configuration will decide the server options. Returns a reference to the internally managed command monitor which the caller can Close() when appropriate.
func SendCmdPipe ¶
SendCmdPipe sends a command request over a specific pipe. Most callers should use SendCommand() instead.
Types ¶
type Handler ¶
Handler functions are the business logic of commands. They must process json encoded as a byte slice which contains a Command field and optional arbitrary data, and return json which contains a Status, StatusMessage, and optional arbitrary data (again encoded as a byte slice). Returned errors will be passed onto the command requester.
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor is the structure which handles command registration and deregistration.
func Get ¶
func Get() *Monitor
Get returns the current command monitor which can be used to register command handlers.
func (*Monitor) RegisterHandler ¶
RegisterHandler registers f as the handler for cmd. If a command.Server has been initialized, it will be signalled to start listening for commands.
func (*Monitor) UnregisterHandler ¶
UnregisterHandler clears the handlers for cmd. If a command.Server has been intialized and there are no more handlers registered, the server will be signalled to stop listening for commands.
type Request ¶
type Request struct {
Command string
}
Request is the basic request structure. Command determines which handler the request is routed to. Callers may set additional arbitrary fields.
type Response ¶
type Response struct { // Status code for the request. Meaning is defined by the caller, but // conventially zero is success. Status int // StatusMessage is an optional message defined by the caller. Should generally // help a human understand what happened. StatusMessage string }
Response is the basic response structure. Handlers may set additional arbitrary fields.