Give the Sidecar Host API one authoritative catalog in pkg/pluginproto: every host/* method's status, required permissions, handshake feature and request and result shapes. The host, pkg/pluginsdk and plugins share those types, so a field can no longer exist on one side only, and permissions come from the catalog instead of from each handler. Tests gate that every served method is catalogued, every stable catalogued method is served, and every catalogued permission is one the host recognizes. Open the interface up instead of adding consent gates. Typing a secret setting is no longer reserved for reims.agent: any plugin that holds qmp:write and that the user authorized for the VM can have the host type the plugin's own setting, which the plugin never reads back. Restoring a snapshot works on any authorized VM, a plugin names its own clones, a held key may carry modifiers, and a screenshot width outside the supported range is brought into range rather than refused. Deleting a VM stays limited to the temporary VMs a plugin created. Record the keys and pointer buttons each plugin holds per VM and lift them when the plugin's process exits, its scope is disposed, the VM stops or it stops calling, so a guest never stays stuck with a modifier down. Requests from plugins that declare pluginApi 1.3 or newer are decoded strictly and answer an undefined field with JSON-RPC -32602, while older plugins keep tolerant decoding. Add typed VM and console methods to pkg/pluginsdk so a plugin no longer needs its own JSON-RPC client. A method the contract does not catalog, or one the host did not advertise in the handshake, is refused before it is sent, and the host's JSON-RPC error code reaches the caller.
327 lines
11 KiB
Go
327 lines
11 KiB
Go
package pluginproto
|
|
|
|
// The wire types of every host/* method. Both the host handlers and
|
|
// pkg/pluginsdk decode and encode these, so a field cannot exist on one side
|
|
// only.
|
|
|
|
// VMRef identifies a VM by owning driver and name. Two drivers may own VMs
|
|
// with the same name, so a caller that knows the driver always sends the ref.
|
|
type VMRef struct {
|
|
DriverID string `json:"driver_id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
// VMEndpoint is one way to reach a guest. Kind is one of "ssh", "wsl", "rdp",
|
|
// "vmconnect" and "adb".
|
|
type VMEndpoint struct {
|
|
Kind string `json:"kind"`
|
|
Host string `json:"host,omitempty"`
|
|
Port int `json:"port,omitempty"`
|
|
User string `json:"user,omitempty"`
|
|
Distro string `json:"distro,omitempty"`
|
|
VM string `json:"vm,omitempty"`
|
|
Serial string `json:"serial,omitempty"`
|
|
Ready bool `json:"ready"`
|
|
}
|
|
|
|
// GuestOSInfo describes the guest operating system. Family is one of "macos",
|
|
// "linux", "windows" and "android".
|
|
type GuestOSInfo struct {
|
|
Family string `json:"family,omitempty"`
|
|
Distro string `json:"distro,omitempty"`
|
|
Version string `json:"version,omitempty"`
|
|
Arch string `json:"arch,omitempty"`
|
|
}
|
|
|
|
// ReportedVMState is the payload of host/vm.reportState.
|
|
type ReportedVMState struct {
|
|
Ref VMRef `json:"ref"`
|
|
State string `json:"state"`
|
|
Ready *bool `json:"ready,omitempty"`
|
|
Phase string `json:"phase,omitempty"`
|
|
Endpoints []VMEndpoint `json:"endpoints,omitempty"`
|
|
GuestOS *GuestOSInfo `json:"guest_os,omitempty"`
|
|
}
|
|
|
|
// OKResult is the result of the methods that only report success.
|
|
type OKResult struct {
|
|
OK bool `json:"ok"`
|
|
}
|
|
|
|
// NotifyParams is the payload of host/notify.
|
|
type NotifyParams struct {
|
|
Title string `json:"title"`
|
|
Body string `json:"body"`
|
|
}
|
|
|
|
// AuditParams is the payload of host/audit.
|
|
type AuditParams struct {
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// SpawnParams is the payload of host/vm.spawn. Ref wins over vm_name when both
|
|
// are set.
|
|
type SpawnParams struct {
|
|
VMName string `json:"vm_name,omitempty"`
|
|
Ref *VMRef `json:"ref,omitempty"`
|
|
ExePath string `json:"exe_path"`
|
|
Args []string `json:"args,omitempty"`
|
|
WorkDir string `json:"work_dir,omitempty"`
|
|
Env []string `json:"env,omitempty"`
|
|
}
|
|
|
|
// SpawnResult is the result of host/vm.spawn.
|
|
type SpawnResult struct {
|
|
PID int `json:"pid"`
|
|
}
|
|
|
|
// ProcessParams addresses a process by pid or by the VM ref whose job object
|
|
// holds it. It is the payload of host/vm.stop and host/vm.isRunning.
|
|
type ProcessParams struct {
|
|
PID int `json:"pid,omitempty"`
|
|
Ref *VMRef `json:"ref,omitempty"`
|
|
}
|
|
|
|
// IsRunningResult is the result of host/vm.isRunning.
|
|
type IsRunningResult struct {
|
|
Running bool `json:"running"`
|
|
}
|
|
|
|
// DownloadParams is the payload of host/download.start. SHA256 or SHA256URL
|
|
// (with SHA256Name selecting a line) is required; the host verifies the file.
|
|
type DownloadParams struct {
|
|
URL string `json:"url"`
|
|
SHA256 string `json:"sha256,omitempty"`
|
|
SHA256URL string `json:"sha256_url,omitempty"`
|
|
SHA256Name string `json:"sha256_name,omitempty"`
|
|
Dest string `json:"dest"`
|
|
Size int64 `json:"size,omitempty"`
|
|
Label string `json:"label,omitempty"`
|
|
}
|
|
|
|
// DownloadResult is the result of host/download.start.
|
|
type DownloadResult struct {
|
|
ID string `json:"id"`
|
|
TaskID string `json:"task_id"`
|
|
}
|
|
|
|
// DownloadCancelParams is the payload of host/download.cancel.
|
|
type DownloadCancelParams struct {
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
// SecretMaterializeParams is the payload of host/secret.materialize. Template
|
|
// must hold {{secret}}; Format is "raw" (default), "xml" or "base64-utf16le".
|
|
type SecretMaterializeParams struct {
|
|
Setting string `json:"setting"`
|
|
Ref VMRef `json:"ref"`
|
|
Template string `json:"template"`
|
|
Dest string `json:"dest"`
|
|
Format string `json:"format,omitempty"`
|
|
}
|
|
|
|
// SecretMaterializeResult is the result of host/secret.materialize.
|
|
type SecretMaterializeResult struct {
|
|
Path string `json:"path"`
|
|
}
|
|
|
|
// SecretDiscardParams is the payload of host/secret.discard. An empty Path
|
|
// discards every file the host materialized for Ref.
|
|
type SecretDiscardParams struct {
|
|
Ref VMRef `json:"ref"`
|
|
Path string `json:"path,omitempty"`
|
|
}
|
|
|
|
// SecretDiscardResult is the result of host/secret.discard.
|
|
type SecretDiscardResult struct {
|
|
Removed int `json:"removed"`
|
|
}
|
|
|
|
// ElevateParams is the payload of host/elevate.request.
|
|
type ElevateParams struct {
|
|
Action string `json:"action"`
|
|
}
|
|
|
|
// ElevateResult is the result of host/elevate.request, after the user
|
|
// confirmed both the host dialog and the Windows UAC prompt.
|
|
type ElevateResult struct {
|
|
OK bool `json:"ok"`
|
|
Action string `json:"action"`
|
|
ExitCode int `json:"exit_code,omitempty"`
|
|
RebootRequired bool `json:"reboot_required,omitempty"`
|
|
LogoffRequired bool `json:"logoff_required,omitempty"`
|
|
}
|
|
|
|
// VMParams addresses one VM by name or by canonical driverID:name reference.
|
|
type VMParams struct {
|
|
VM string `json:"vm"`
|
|
}
|
|
|
|
// VMShutdownParams is the payload of host/vm.shutdown. Force stops a VM that
|
|
// does not shut down on request.
|
|
type VMShutdownParams struct {
|
|
VM string `json:"vm"`
|
|
Force bool `json:"force,omitempty"`
|
|
}
|
|
|
|
// VMView is what host/vm.list and host/vm.get report about one VM. Fields
|
|
// that need the user's per-VM consent are present only when it was granted.
|
|
type VMView struct {
|
|
VM string `json:"vm"`
|
|
Name string `json:"name"`
|
|
DriverID string `json:"driver_id"`
|
|
State string `json:"state"`
|
|
Authorized bool `json:"authorized"`
|
|
Phase string `json:"phase"`
|
|
Owned bool `json:"owned"`
|
|
CPUs int `json:"cpus,omitempty"`
|
|
Memory string `json:"memory,omitempty"`
|
|
DiskSummary string `json:"disk_summary,omitempty"`
|
|
SSHPort int `json:"ssh_port,omitempty"`
|
|
Capabilities []string `json:"capabilities,omitempty"`
|
|
SSHUsername string `json:"ssh_username,omitempty"`
|
|
}
|
|
|
|
// VMListResult is the result of host/vm.list.
|
|
type VMListResult struct {
|
|
VMs []VMView `json:"vms"`
|
|
}
|
|
|
|
// VMCloneParams is the payload of host/vm.clone. The host registers the clone
|
|
// as this plugin's temporary VM, so a plugin may name it freely; the name only
|
|
// has to be free on the source VM's driver.
|
|
type VMCloneParams struct {
|
|
VM string `json:"vm"`
|
|
CloneName string `json:"clone_name"`
|
|
}
|
|
|
|
// VMCloneResult is the result of host/vm.clone.
|
|
type VMCloneResult struct {
|
|
VM string `json:"vm"`
|
|
Name string `json:"name"`
|
|
DriverID string `json:"driver_id"`
|
|
State string `json:"state"`
|
|
Owned bool `json:"owned"`
|
|
}
|
|
|
|
// SnapshotNameParams is the payload of host/vm.snapshot.create and
|
|
// host/vm.snapshot.restore.
|
|
type SnapshotNameParams struct {
|
|
VM string `json:"vm"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
// Snapshot describes one restore point.
|
|
type Snapshot struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
VMStateBytes int64 `json:"vm_state_bytes"`
|
|
}
|
|
|
|
// SnapshotListResult is the result of host/vm.snapshot.list.
|
|
type SnapshotListResult struct {
|
|
Snapshots []Snapshot `json:"snapshots"`
|
|
}
|
|
|
|
// SnapshotResult is the result of host/vm.snapshot.create and
|
|
// host/vm.snapshot.restore.
|
|
type SnapshotResult struct {
|
|
OK bool `json:"ok"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
// Region is a rectangle. In a screenshot request it is expressed in the
|
|
// coordinate space of the reference frame the caller sends as Width and
|
|
// Height; in a screenshot result it is the source-pixel rectangle that was
|
|
// captured.
|
|
type Region struct {
|
|
X int `json:"x"`
|
|
Y int `json:"y"`
|
|
Width int `json:"width"`
|
|
Height int `json:"height"`
|
|
}
|
|
|
|
// ScreenshotParams is the payload of host/console.screenshot. MaxWidth caps
|
|
// the width of the returned image; a value outside the supported range is
|
|
// brought into it rather than refused. Region selects a part of the screen:
|
|
// Width and Height name the image the region was measured in, and without them
|
|
// the region is in source pixels.
|
|
type ScreenshotParams struct {
|
|
VM string `json:"vm"`
|
|
MaxWidth int `json:"max_width,omitempty"`
|
|
Region *Region `json:"region,omitempty"`
|
|
Width int `json:"width,omitempty"`
|
|
Height int `json:"height,omitempty"`
|
|
}
|
|
|
|
// ScreenshotResult is the result of host/console.screenshot. Blank marks a
|
|
// frame that is one flat color, which is a normal state during boot, login and
|
|
// display switches rather than a failure.
|
|
type ScreenshotResult struct {
|
|
MIMEType string `json:"mime_type"`
|
|
Width int `json:"width"`
|
|
Height int `json:"height"`
|
|
SourceWidth int `json:"source_width"`
|
|
SourceHeight int `json:"source_height"`
|
|
Blank bool `json:"blank"`
|
|
Data string `json:"data"`
|
|
Region *Region `json:"region,omitempty"`
|
|
}
|
|
|
|
// PointerParams is the payload of host/console.pointer. Action is one of
|
|
// "move", "button", "click" and "scroll". Move and button down/up leave the
|
|
// guest holding what was pressed until a later call releases it.
|
|
type PointerParams struct {
|
|
VM string `json:"vm"`
|
|
Action string `json:"action"`
|
|
X int `json:"x,omitempty"`
|
|
Y int `json:"y,omitempty"`
|
|
Width int `json:"width,omitempty"`
|
|
Height int `json:"height,omitempty"`
|
|
Button string `json:"button,omitempty"`
|
|
Down *bool `json:"down,omitempty"`
|
|
Delta int `json:"delta,omitempty"`
|
|
Horizontal bool `json:"horizontal,omitempty"`
|
|
}
|
|
|
|
// KeyParams is the payload of host/console.key. Without Down the host presses
|
|
// and releases Key with Modifiers held. With Down set the host sends key
|
|
// transitions for Key and every modifier and the guest keeps them held until a
|
|
// later call releases them, so the caller must pair it or call
|
|
// host/console.release.
|
|
type KeyParams struct {
|
|
VM string `json:"vm"`
|
|
Key string `json:"key"`
|
|
Modifiers []string `json:"modifiers,omitempty"`
|
|
Down *bool `json:"down,omitempty"`
|
|
}
|
|
|
|
// TypeParams is the payload of host/console.type.
|
|
type TypeParams struct {
|
|
VM string `json:"vm"`
|
|
Text string `json:"text"`
|
|
}
|
|
|
|
// TypeSecretParams is the payload of host/console.typeSecret. Setting names one
|
|
// of the calling plugin's own settings; the host never returns its value, so a
|
|
// plugin can use a secret it stored without ever reading it.
|
|
type TypeSecretParams struct {
|
|
VM string `json:"vm"`
|
|
Setting string `json:"setting"`
|
|
}
|
|
|
|
// ReleaseParams is the payload of host/console.release. It lifts the keys and
|
|
// pointer buttons the caller still holds in the guest.
|
|
type ReleaseParams struct {
|
|
VM string `json:"vm"`
|
|
Keys []string `json:"keys,omitempty"`
|
|
Buttons []string `json:"buttons,omitempty"`
|
|
}
|
|
|
|
// CharactersResult is the result of host/console.type and
|
|
// host/console.typeSecret.
|
|
type CharactersResult struct {
|
|
Characters int `json:"characters"`
|
|
}
|