protocol

package
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeHello          = "hello"           // Agent → Dockhand: Initial connection
	TypeWelcome        = "welcome"         // Dockhand → Agent: Connection accepted
	TypeRequest        = "request"         // Dockhand → Agent: Docker API request
	TypeResponse       = "response"        // Agent → Dockhand: Docker API response
	TypeStream         = "stream"          // Bidirectional: Streaming data (logs, exec)
	TypeStreamEnd      = "stream_end"      // End of stream
	TypeMetrics        = "metrics"         // Agent → Dockhand: Host metrics
	TypeContainerEvent = "container_event" // Agent → Dockhand: Docker container event
	TypePing           = "ping"            // Keepalive request
	TypePong           = "pong"            // Keepalive response
	TypeError          = "error"           // Error message

	// Exec-specific message types for bidirectional terminal
	TypeExecStart  = "exec_start"  // Dockhand → Agent: Start exec session
	TypeExecReady  = "exec_ready"  // Agent → Dockhand: Exec session ready
	TypeExecInput  = "exec_input"  // Dockhand → Agent: Terminal input from user
	TypeExecOutput = "exec_output" // Agent → Dockhand: Terminal output to user
	TypeExecResize = "exec_resize" // Dockhand → Agent: Terminal resize
	TypeExecEnd    = "exec_end"    // Bidirectional: End exec session
)

Message types

View Source
const (
	CapabilityCompose = "compose" // Docker Compose support
	CapabilityExec    = "exec"    // Interactive exec support
	CapabilityMetrics = "metrics" // Host metrics collection
	CapabilityEvents  = "events"  // Docker event streaming
)

Agent capabilities

View Source
const ProtocolVersion = "1.0"

Protocol version

Variables

This section is empty.

Functions

func ParseMessageType

func ParseMessageType(data []byte) (string, error)

ParseMessageType extracts the message type from raw JSON

Types

type BaseMessage

type BaseMessage struct {
	Type string `json:"type"`
}

BaseMessage is the common structure for all messages

type ContainerEvent added in v0.2.0

type ContainerEvent struct {
	ContainerID     string            `json:"containerId"`
	ContainerName   string            `json:"containerName,omitempty"`
	Image           string            `json:"image,omitempty"`
	Action          string            `json:"action"`
	ActorAttributes map[string]string `json:"actorAttributes,omitempty"`
	Timestamp       string            `json:"timestamp"` // ISO 8601 format
}

ContainerEvent contains container event details

type ContainerEventMessage added in v0.2.0

type ContainerEventMessage struct {
	Type  string         `json:"type"`
	Event ContainerEvent `json:"event"`
}

ContainerEventMessage contains a Docker container event

func NewContainerEventMessage added in v0.2.0

func NewContainerEventMessage(event ContainerEvent) *ContainerEventMessage

NewContainerEventMessage creates a new container event message

type ErrorMessage

type ErrorMessage struct {
	Type      string `json:"type"`
	RequestID string `json:"requestId,omitempty"`
	Error     string `json:"error"`
	Code      string `json:"code,omitempty"`
}

ErrorMessage is an error response

func NewErrorMessage

func NewErrorMessage(requestID, errorMsg, code string) *ErrorMessage

NewErrorMessage creates a new error message

type ExecEndMessage added in v0.1.0

type ExecEndMessage struct {
	Type   string `json:"type"`
	ExecID string `json:"execId"`
	Reason string `json:"reason,omitempty"` // "user_closed", "container_exit", "error"
}

ExecEndMessage ends an exec session

func NewExecEndMessage added in v0.1.0

func NewExecEndMessage(execID string, reason string) *ExecEndMessage

NewExecEndMessage creates a new exec end message

type ExecInputMessage added in v0.1.0

type ExecInputMessage struct {
	Type   string `json:"type"`
	ExecID string `json:"execId"`
	Data   string `json:"data"` // Base64-encoded input data
}

ExecInputMessage sends terminal input to the exec session

type ExecOutputMessage added in v0.1.0

type ExecOutputMessage struct {
	Type   string `json:"type"`
	ExecID string `json:"execId"`
	Data   string `json:"data"` // Base64-encoded output data
}

ExecOutputMessage sends terminal output from the exec session

func NewExecOutputMessage added in v0.1.0

func NewExecOutputMessage(execID string, data []byte) *ExecOutputMessage

NewExecOutputMessage creates a new exec output message

type ExecReadyMessage added in v0.1.0

type ExecReadyMessage struct {
	Type   string `json:"type"`
	ExecID string `json:"execId"`
}

ExecReadyMessage confirms exec session is ready

func NewExecReadyMessage added in v0.1.0

func NewExecReadyMessage(execID string) *ExecReadyMessage

NewExecReadyMessage creates a new exec ready message

type ExecResizeMessage added in v0.1.0

type ExecResizeMessage struct {
	Type   string `json:"type"`
	ExecID string `json:"execId"`
	Cols   int    `json:"cols"`
	Rows   int    `json:"rows"`
}

ExecResizeMessage resizes the exec terminal

type ExecStartMessage added in v0.1.0

type ExecStartMessage struct {
	Type        string `json:"type"`
	ExecID      string `json:"execId"`      // Unique ID for this exec session
	ContainerID string `json:"containerId"` // Container to exec into
	Cmd         string `json:"cmd"`         // Command to run (e.g., "/bin/sh")
	User        string `json:"user"`        // User to run as
	Cols        int    `json:"cols"`        // Initial terminal columns
	Rows        int    `json:"rows"`        // Initial terminal rows
}

ExecStartMessage requests starting an exec session

type HelloMessage

type HelloMessage struct {
	Type          string   `json:"type"`
	Version       string   `json:"version"`  // Hawser agent version
	Protocol      string   `json:"protocol"` // Protocol version for compatibility
	AgentID       string   `json:"agentId"`
	AgentName     string   `json:"agentName"`
	Token         string   `json:"token"`
	DockerVersion string   `json:"dockerVersion"`
	Hostname      string   `json:"hostname"`
	Capabilities  []string `json:"capabilities"`
}

HelloMessage is sent by agent on connect

func NewHelloMessage

func NewHelloMessage(agentID, agentName, token, dockerVersion, hostname, hawserVersion string, capabilities []string) *HelloMessage

NewHelloMessage creates a new hello message

type HostMetrics

type HostMetrics struct {
	CPUUsage       float64 `json:"cpuUsage"`       // Percentage (0-100)
	CPUCores       int     `json:"cpuCores"`       // Number of cores
	MemoryTotal    uint64  `json:"memoryTotal"`    // Bytes
	MemoryUsed     uint64  `json:"memoryUsed"`     // Bytes
	MemoryFree     uint64  `json:"memoryFree"`     // Bytes
	DiskTotal      uint64  `json:"diskTotal"`      // Bytes (Docker data-root)
	DiskUsed       uint64  `json:"diskUsed"`       // Bytes
	DiskFree       uint64  `json:"diskFree"`       // Bytes
	NetworkRxBytes uint64  `json:"networkRxBytes"` // Total received bytes
	NetworkTxBytes uint64  `json:"networkTxBytes"` // Total transmitted bytes
	Uptime         uint64  `json:"uptime"`         // Host uptime in seconds
}

HostMetrics contains CPU, memory, and disk statistics

type MetricsMessage

type MetricsMessage struct {
	Type      string      `json:"type"`
	Timestamp int64       `json:"timestamp"`
	Metrics   HostMetrics `json:"metrics"`
}

MetricsMessage contains host metrics

func NewMetricsMessage

func NewMetricsMessage(timestamp int64, metrics HostMetrics) *MetricsMessage

NewMetricsMessage creates a new metrics message

type PingMessage

type PingMessage struct {
	Type      string `json:"type"`
	Timestamp int64  `json:"timestamp"`
}

PingMessage is a keepalive request

func NewPingMessage

func NewPingMessage(timestamp int64) *PingMessage

NewPingMessage creates a new ping message

type PongMessage

type PongMessage struct {
	Type      string `json:"type"`
	Timestamp int64  `json:"timestamp"`
}

PongMessage is a keepalive response

func NewPongMessage

func NewPongMessage(timestamp int64) *PongMessage

NewPongMessage creates a new pong message

type RequestMessage

type RequestMessage struct {
	Type      string            `json:"type"`
	RequestID string            `json:"requestId"` // UUID for matching response
	Method    string            `json:"method"`    // HTTP method
	Path      string            `json:"path"`      // Docker API path
	Headers   map[string]string `json:"headers,omitempty"`
	Body      json.RawMessage   `json:"body,omitempty"`
	Streaming bool              `json:"streaming"` // true for logs, exec, etc.
}

RequestMessage is a Docker API request from Dockhand

type ResponseMessage

type ResponseMessage struct {
	Type       string            `json:"type"`
	RequestID  string            `json:"requestId"`
	StatusCode int               `json:"statusCode"`
	Headers    map[string]string `json:"headers,omitempty"`
	Body       string            `json:"body,omitempty"`     // Base64-encoded for binary, plain string for JSON
	IsBinary   bool              `json:"isBinary,omitempty"` // True if Body is base64-encoded binary data
}

ResponseMessage is a Docker API response to Dockhand

func NewResponseMessage

func NewResponseMessage(requestID string, statusCode int, headers map[string]string, body []byte) *ResponseMessage

NewResponseMessage creates a new response message For JSON responses, body is sent as-is For binary responses (logs, tar, etc.), body is base64-encoded and IsBinary is set to true

type StreamEndMessage

type StreamEndMessage struct {
	Type      string `json:"type"`
	RequestID string `json:"requestId"`
	Reason    string `json:"reason,omitempty"`
}

StreamEndMessage marks end of stream

func NewStreamEndMessage

func NewStreamEndMessage(requestID string, reason string) *StreamEndMessage

NewStreamEndMessage creates a new stream end message

type StreamMessage

type StreamMessage struct {
	Type      string `json:"type"`
	RequestID string `json:"requestId"`
	Data      []byte `json:"data"`
	Stream    string `json:"stream,omitempty"` // "stdout", "stderr", or empty
}

StreamMessage is for streaming responses (logs, exec, events)

func NewStreamMessage

func NewStreamMessage(requestID string, data []byte, stream string) *StreamMessage

NewStreamMessage creates a new stream message

type WelcomeMessage

type WelcomeMessage struct {
	Type          string `json:"type"`
	EnvironmentID int    `json:"environmentId"`
	Message       string `json:"message,omitempty"`
}

WelcomeMessage is sent by Dockhand on successful auth

Jump to

Keyboard shortcuts

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