models

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package models - application data models

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildStdinInputFromCommands

func BuildStdinInputFromCommands(cmds []SessionInputCommand) ([]byte, error)

BuildStdinInputFromCommands build bytes slice to feed into STDIN from sequence of commands.

Commands are processed in order so callers can interleave text, control characters, and carriage returns (e.g. type a command then press ENTER). Each command is validated via IsValid; the returned error identifies the offending command index.

func InstallDefaultServerConfigValues

func InstallDefaultServerConfigValues()

InstallDefaultServerConfigValues setup default server configs

func ParseIPCMessage

func ParseIPCMessage(validator *validator.Validate, msg []byte) (interface{}, error)

ParseIPCMessage parse the IPC message based on type

func RegisterWithValidator

func RegisterWithValidator(v *validator.Validate) error

RegisterWithValidator register with the validator this custom validation support

@param v *validator.Validate - the validator to register against
@return whether successful

Types

type APIConfig

type APIConfig struct {
	// Endpoint sets API endpoint related parameters
	Endpoint EndpointConfig `mapstructure:"endPoint" json:"endPoint" validate:"required"`
	// RequestLogging sets API request logging parameters
	RequestLogging HTTPRequestLogging `mapstructure:"requestLogging" json:"requestLogging" validate:"required"`
	// EnableMCP enable the MCP endpoint
	EnableMCP bool `mapstructure:"enableMCP" json:"enableMCP"`
}

APIConfig defines API settings for a submodule

type APIServerConfig

type APIServerConfig struct {
	// Server defines HTTP server parameters
	Server HTTPServerConfig `mapstructure:"service" json:"service" validate:"required"`
	// APIs defines API settings for a submodule
	APIs APIConfig `mapstructure:"apis" json:"apis" validate:"required"`
}

APIServerConfig defines HTTP API / server parameters

type ApplicationConfig

type ApplicationConfig struct {
	// Metrics metrics framework configuration
	Metrics MetricsConfig `mapstructure:"metrics" json:"metrics" validate:"required"`

	// API server config
	API APIServerConfig `mapstructure:"api" json:"api" validate:"required"`

	// SQLite persistence config
	SQLite SQLiteConfig `mapstructure:"sqlite" json:"sqlite" validate:"required"`

	// Redis connection parameter
	Redis RedisConnectionConfig `mapstructure:"redis" json:"redis" validate:"required"`
}

ApplicationConfig application config

type BaseIPCMessage

type BaseIPCMessage struct {
	// RequestID the ID of the request
	RequestID string `json:"req_id" validate:"required"`
	// Type message type
	Type IPCMessageTypeEnumType `json:"type" validate:"required,ipc_msg_type"`
	// Sender name of the sending entity
	Sender string `json:"sender" validate:"required"`
	// Timestamp message timestamp
	Timestamp time.Time `json:"timestamp"`
}

BaseIPCMessage base IPC message object

type BootStrapError

type BootStrapError struct{ goutils.BaseError }

BootStrapError application boot strap error

func NewBootStrapError

func NewBootStrapError(message string, core error, getCallStack bool) BootStrapError

NewBootStrapError builds a BootStrapError, optionally capturing the call stack.

type EndpointConfig

type EndpointConfig struct {
	// PathPrefix is the end-point path prefix for the APIs
	PathPrefix string `mapstructure:"pathPrefix" json:"pathPrefix" validate:"required"`
}

EndpointConfig defines API endpoint config

type HTTPRequestLogging

type HTTPRequestLogging struct {
	// LogLevel output request logs at this level
	LogLevel goutils.HTTPRequestLogLevel `mapstructure:"logLevel" json:"logLevel" validate:"oneof=warn info debug"`
	// HealthLogLevel output health check logs at this level
	HealthLogLevel goutils.HTTPRequestLogLevel `mapstructure:"healthLogLevel" json:"healthLogLevel" validate:"oneof=warn info debug"`
	// RequestIDHeader is the HTTP header containing the API request ID
	RequestIDHeader string `mapstructure:"requestIDHeader" json:"requestIDHeader"`
	// DoNotLogHeaders is the list of headers to not include in logging metadata
	DoNotLogHeaders []string `mapstructure:"skipHeaders" json:"skipHeaders"`
	// LogRequestPayload whether to log request payload
	LogRequestPayload bool `mapstructure:"logRequestPayload" json:"logRequestPayload"`
}

HTTPRequestLogging defines HTTP request logging parameters

type HTTPServerConfig

type HTTPServerConfig struct {
	// ListenOn is the interface the HTTP server will listen on
	ListenOn string `mapstructure:"listenOn" json:"listenOn" validate:"required,ip"`
	// Port is the port the HTTP server will listen on
	Port uint16 `mapstructure:"appPort" json:"appPort" validate:"required,gt=0,lt=65536"`
	// Timeouts sets the HTTP timeout settings
	Timeouts HTTPServerTimeoutConfig `mapstructure:"timeoutSecs" json:"timeoutSecs" validate:"required"`
}

HTTPServerConfig defines the HTTP server parameters

type HTTPServerTimeoutConfig

type HTTPServerTimeoutConfig struct {
	// ReadTimeout is the maximum duration for reading the entire
	// request, including the body in seconds. A zero or negative
	// value means there will be no timeout.
	ReadTimeout int `mapstructure:"read" json:"read" validate:"gte=0"`
	// WriteTimeout is the maximum duration before timing out
	// writes of the response in seconds. A zero or negative value
	// means there will be no timeout.
	WriteTimeout int `mapstructure:"write" json:"write" validate:"gte=0"`
	// IdleTimeout is the maximum amount of time to wait for the
	// next request when keep-alives are enabled in seconds. If
	// IdleTimeout is zero, the value of ReadTimeout is used. If
	// both are zero, there is no timeout.
	IdleTimeout int `mapstructure:"idle" json:"idle" validate:"gte=0"`
}

HTTPServerTimeoutConfig defines the timeout settings for HTTP server

type IPCMessageEnvelope

type IPCMessageEnvelope interface {
	// StringPayload return its payload as a string
	StringPayload() (string, error)
}

IPCMessageEnvelope type erased IPC message object

type IPCMessageReqRunCommands

type IPCMessageReqRunCommands struct {
	BaseIPCMessage
	// Commands the list of commands to send to the session
	Commands []SessionInputCommand `json:"commands" validate:"required,gte=1,dive"`
}

IPCMessageReqRunCommands run user commands request

func (IPCMessageReqRunCommands) StringPayload

func (m IPCMessageReqRunCommands) StringPayload() (string, error)

StringPayload return its payload as a string

type IPCMessageReqStopSession

type IPCMessageReqStopSession struct {
	BaseIPCMessage
	// Blocking whether the request is a blocking request
	Blocking bool `json:"blocking"`
}

IPCMessageReqStopSession stop a session

func (IPCMessageReqStopSession) StringPayload

func (m IPCMessageReqStopSession) StringPayload() (string, error)

StringPayload return its payload as a string

type IPCMessageRespUniversal

type IPCMessageRespUniversal struct {
	BaseIPCMessage
	// Success whether the request is processed successfully
	Success bool `json:"success"`
	// ErrorMsg in case of failure, an accompanying error message
	ErrorMsg *string `json:"error,omitempty"`
}

IPCMessageRespUniversal universal response for requests which don't need special response structs.

func (IPCMessageRespUniversal) StringPayload

func (m IPCMessageRespUniversal) StringPayload() (string, error)

StringPayload return its payload as a string

type IPCMessageTypeEnumType

type IPCMessageTypeEnumType string

IPCMessageTypeEnumType IPC message type ENUM

const (

	// IPCMsgTypeReqRunCommands user request run commands
	IPCMsgTypeReqRunCommands IPCMessageTypeEnumType = "IPC_REQ_RUN_COMMANDS"

	// IPCMsgTypeReqStopSession user request stopping a session
	IPCMsgTypeReqStopSession IPCMessageTypeEnumType = "IPC_REQ_STOP_SESSION"

	// IPCMsgTypeRespRunCommands response to run user commands
	IPCMsgTypeRespRunCommands IPCMessageTypeEnumType = "IPC_RESP_RUN_COMMANDS"

	// IPCMsgTypeRespStopSession response to session stop request
	IPCMsgTypeRespStopSession IPCMessageTypeEnumType = "IPC_RESP_STOP_SESSION"
)

func (IPCMessageTypeEnumType) Values added in v0.3.0

Values all valid IPCMessageTypeEnumType values

type MetricsConfig

type MetricsConfig struct {
	// Server defines HTTP server parameters
	Server HTTPServerConfig `mapstructure:"service" json:"service" validate:"required"`
	// MetricsEndpoint path to host the Prometheus metrics endpoint
	MetricsEndpoint string `mapstructure:"metricsEndpoint" json:"metricsEndpoint" validate:"required"`
	// MaxRequests max number of metrics requests in parallel to support
	MaxRequests int `mapstructure:"maxRequests" json:"maxRequests" validate:"gte=1"`
	// Features metrics framework features to enable
	Features MetricsFeatureConfig `mapstructure:"features" json:"features" validate:"required"`
}

MetricsConfig application metrics config

type MetricsFeatureConfig

type MetricsFeatureConfig struct {
	// EnableAppMetrics whether to enable Golang application metrics
	EnableAppMetrics bool `mapstructure:"enableAppMetrics" json:"enableAppMetrics"`
	// EnableHTTPMetrics whether to enable HTTP request tracking metrics
	EnableHTTPMetrics bool `mapstructure:"enableHTTPMetrics" json:"enableHTTPMetrics"`
}

MetricsFeatureConfig metrics framework features config

type PTYError

type PTYError struct{ goutils.BaseError }

PTYError PTY specific error

func NewPTYError

func NewPTYError(message string, core error, getCallStack bool) PTYError

NewPTYError builds a PTYError, optionally capturing the call stack.

type PersistenceError

type PersistenceError struct{ goutils.BaseError }

PersistenceError error encountered with persistence

func NewPersistenceError

func NewPersistenceError(message string, core error, getCallStack bool) PersistenceError

NewPersistenceError builds a PersistenceError, optionally capturing the call stack.

type RedisConnectionConfig

type RedisConnectionConfig struct {
	// Host of the server
	Host string `mapstructure:"host" json:"host" validate:"required"`
	// Port of the server
	Port uint16 `mapstructure:"port" json:"port"`
	// DBNumber number of the REDIS database
	DBNumber uint32 `mapstructure:"dbNumber" json:"dbNumber" validate:"lte=15"`
}

RedisConnectionConfig connection parameter to Redis server

type SQLiteConfig

type SQLiteConfig struct {
	// DBFile the SQLite DB file path
	DBFile string `mapstructure:"file" json:"file" validate:"required"`
}

SQLiteConfig SQLite persistence config

type Session

type Session struct {
	// ID PTY session ID
	ID string `json:"id" gorm:"column:id;primaryKey;unique" validate:"required"`

	// Name for the session, can only contain alphanumeric characters and -
	Name string `` /* 166-byte string literal not displayed */

	// Description an optional description for the session
	Description *string `json:"description" gorm:"column:description;default:null" jsonschema:"an optional description for the session"`

	// Command being executed by the session
	Command SessionCommand `json:"command" gorm:"column:command;not null" validate:"required" jsonschema:"command being executed by the session"`

	// State of the session
	State SessionStateENUMType `` /* 128-byte string literal not displayed */

	// DriverType indicate which driver the session uses
	DriverType SessionDriverTypeENUMType `` /* 135-byte string literal not displayed */

	// DriverMetadata metadata relating to the session driver
	DriverMetadata datatypes.JSON `json:"driver_metadata,omitempty" gorm:"column:driver_metadata;default:null" swaggertype:"string"`

	// OutputBufferCapacity buffering capacity for holding command output history
	OutputBufferCapacity int64 `` /* 148-byte string literal not displayed */

	// SessionRunnerModeTypeENUMType session runner operating mode
	RunnerMode SessionRunnerModeTypeENUMType `` /* 141-byte string literal not displayed */

	// CreatedAt entry creation timestamp
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt entry update timestamp
	UpdatedAt time.Time `json:"updated_at"`
}

Session one PTY session running a command with arguments

func (Session) ParseDriverMetadata

func (s Session) ParseDriverMetadata(validator *validator.Validate) (interface{}, error)

ParseDriverMetadata parse driver metadata based on driver type

func (Session) ValidNextState

func (s Session) ValidNextState(newState SessionStateENUMType) error

ValidNextState verify the session can transition to new state

type SessionCommand

type SessionCommand struct {
	// Command the command being run
	Command string `json:"cmd" validate:"required" jsonschema:"the command being run"`
	// Arguments the arguments passed to the command
	Arguments []string `json:"args" jsonschema:"the arguments passed to the command"`
}

SessionCommand the command being executed by the session

func (*SessionCommand) Scan

func (c *SessionCommand) Scan(value interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (SessionCommand) Value

func (c SessionCommand) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type SessionDriverDockerParams

type SessionDriverDockerParams struct {
	goutilsRuntime.DockerRuntimeParams
}

SessionDriverDockerParams parameters for docker-container session drivers.

The container is run interactively with a TTY (mirroring the PTY driver), hardened by default (read-only rootfs, all capabilities dropped, no-new-privileges) and isolated from the network. Sessions that need to accept inbound connections must select a routable NetworkMode and declare PublishPorts.

type SessionDriverPTYParams

type SessionDriverPTYParams struct {
	// DisplayRows PTY number of rows (in cells).
	DisplayRows uint16 `json:"display_rows" validate:"gte=30" jsonschema:"PTY number of rows (in cells)"`

	// DisplayCol PTY number of columns (in cells).
	DisplayCols uint16 `json:"display_cols" validate:"gte=80" jsonschema:"PTY number of columns (in cells)"`
}

SessionDriverPTYParams parameters for PTY session drivers

type SessionDriverTypeENUMType

type SessionDriverTypeENUMType string

SessionDriverTypeENUMType session driver type ENUM type

const (
	// SessionDriverTypePTY using PTY as session driver
	SessionDriverTypePTY SessionDriverTypeENUMType = "PTY"

	// SessionDriverTypeDocker using a docker container as session driver
	SessionDriverTypeDocker SessionDriverTypeENUMType = "DOCKER"
)

func (SessionDriverTypeENUMType) Values added in v0.2.0

Values all valid SessionDriverTypeENUMType values

type SessionInputCommand

type SessionInputCommand struct {
	// Type session input command type
	Type SessionInputCommandTypeENUMType `` /* 857-byte string literal not displayed */

	/*
		Content command content if needed

		For `TEXT` type, the content is the text to write to STDIN.

		For `CTRL` type, the content is the control character (e.g. C for CTRL+C, etc.).

		For `ENTRY` type, the content is ignored

		For `RAW` type, the content is the raw input byte slice (direct capture of
		keyboard presses, including ANSI characters, escape sequences, and control
		characters) in Base64 encoding.
	*/
	Content *string `` /* 603-byte string literal not displayed */
}

SessionInputCommand session input command object

func (SessionInputCommand) IsValid

func (c SessionInputCommand) IsValid() error

IsValid validates the command's Content against its Type, returning a BadInputError describing the first problem found or nil when well formed.

It is the single source of truth for command validity: it is invoked by the struct-level validator registered against SessionInputCommand, and used as a defensive guard by BuildStdinInputFromCommands.

type SessionInputCommandTypeENUMType

type SessionInputCommandTypeENUMType string

SessionInputCommandTypeENUMType session input command type ENUM

const (
	// SessionInputCommandTypeText text input to STDIN
	SessionInputCommandTypeText SessionInputCommandTypeENUMType = "TEXT"

	// SessionInputCommandTypeCTRL CTRL character input to STDIN
	SessionInputCommandTypeCTRL SessionInputCommandTypeENUMType = "CTRL"

	// SessionInputCommandTypeCR carriage return input to STDIN
	SessionInputCommandTypeCR SessionInputCommandTypeENUMType = "ENTER"

	// SessionInputCommandTypeRaw raw input data to STDIN. The content is a
	// Base64-encoded byte slice capturing keyboard presses verbatim, including
	// ANSI characters, escape sequences, and control characters.
	SessionInputCommandTypeRaw SessionInputCommandTypeENUMType = "RAW"
)

func (SessionInputCommandTypeENUMType) Values added in v0.2.0

Values all valid SessionInputCommandTypeENUMType values

type SessionManagerChangeOutputBufferCapError

type SessionManagerChangeOutputBufferCapError struct{ goutils.BaseError }

SessionManagerChangeOutputBufferCapError error session manager change session output buffer capacity

func NewSessionManagerChangeOutputBufferCapError

func NewSessionManagerChangeOutputBufferCapError(
	message string, core error, getCallStack bool,
) SessionManagerChangeOutputBufferCapError

NewSessionManagerChangeOutputBufferCapError builds a SessionManagerChangeOutputBufferCapError, optionally capturing the call stack.

type SessionManagerStartSessionError

type SessionManagerStartSessionError struct{ goutils.BaseError }

SessionManagerStartSessionError error session manager start session runner

func NewSessionManagerStartSessionError

func NewSessionManagerStartSessionError(
	message string, core error, getCallStack bool,
) SessionManagerStartSessionError

NewSessionManagerStartSessionError builds a SessionManagerStartSessionError, optionally capturing the call stack.

type SessionManagerStopAllSessionsError

type SessionManagerStopAllSessionsError struct{ goutils.BaseError }

SessionManagerStopAllSessionsError error session manager bulk stop session runners

func NewSessionManagerStopAllSessionsError

func NewSessionManagerStopAllSessionsError(
	message string, core error, getCallStack bool,
) SessionManagerStopAllSessionsError

NewSessionManagerStopAllSessionsError builds a SessionManagerStopAllSessionsError, optionally capturing the call stack.

type SessionManagerStopSessionError

type SessionManagerStopSessionError struct{ goutils.BaseError }

SessionManagerStopSessionError error session manager stop session runner

func NewSessionManagerStopSessionError

func NewSessionManagerStopSessionError(
	message string, core error, getCallStack bool,
) SessionManagerStopSessionError

NewSessionManagerStopSessionError builds a SessionManagerStopSessionError, optionally capturing the call stack.

type SessionRunnerIPCProcessError

type SessionRunnerIPCProcessError struct{ goutils.BaseError }

SessionRunnerIPCProcessError error session runner encountered processing IPC messages

func NewSessionRunnerIPCProcessError

func NewSessionRunnerIPCProcessError(
	message string, core error, getCallStack bool,
) SessionRunnerIPCProcessError

NewSessionRunnerIPCProcessError builds a SessionRunnerIPCProcessError, optionally capturing the call stack.

type SessionRunnerModeTypeENUMType

type SessionRunnerModeTypeENUMType string

SessionRunnerModeTypeENUMType session runner operating mode type ENUM

const (
	// SessionRunnerModeTypeCommanded session runner operates by taking commands from user
	// and feeding it to the session under control.
	SessionRunnerModeTypeCommanded SessionRunnerModeTypeENUMType = "COMMANDED"

	// SessionRunnerModeTypeByPassed session runner will ignore commands from user
	// and allow user to directly interact with the session under control
	SessionRunnerModeTypeByPassed SessionRunnerModeTypeENUMType = "BY_PASSED"
)

func (SessionRunnerModeTypeENUMType) Values added in v0.2.0

Values all valid SessionRunnerModeTypeENUMType values

type SessionRunnerShutdownError

type SessionRunnerShutdownError struct{ goutils.BaseError }

SessionRunnerShutdownError error during session runner `StopSession`

func NewSessionRunnerShutdownError

func NewSessionRunnerShutdownError(
	message string, core error, getCallStack bool,
) SessionRunnerShutdownError

NewSessionRunnerShutdownError builds a SessionRunnerShutdownError, optionally capturing the call stack.

type SessionRunnerStartUpError

type SessionRunnerStartUpError struct{ goutils.BaseError }

SessionRunnerStartUpError error during session runner `StartSession`

func NewSessionRunnerStartUpError

func NewSessionRunnerStartUpError(
	message string, core error, getCallStack bool,
) SessionRunnerStartUpError

NewSessionRunnerStartUpError builds a SessionRunnerStartUpError, optionally capturing the call stack.

type SessionRunnerSubmitCommandError

type SessionRunnerSubmitCommandError struct{ goutils.BaseError }

SessionRunnerSubmitCommandError error when session runner submit commands to driver

func NewSessionRunnerSubmitCommandError

func NewSessionRunnerSubmitCommandError(
	message string, core error, getCallStack bool,
) SessionRunnerSubmitCommandError

NewSessionRunnerSubmitCommandError builds a SessionRunnerSubmitCommandError, optionally capturing the call stack.

type SessionStateENUMType

type SessionStateENUMType string

SessionStateENUMType session state ENUM value type

const (
	// SessionStateIdle session is idle
	SessionStateIdle SessionStateENUMType = "IDLE"

	// SessionStateReady session is running and ready to accept input
	SessionStateReady SessionStateENUMType = "READY"
)

func (SessionStateENUMType) Values added in v0.2.0

Values all valid SessionStateENUMType values

type ShutdownError

type ShutdownError struct{ goutils.BaseError }

ShutdownError application shutdown error

func NewShutdownError

func NewShutdownError(message string, core error, getCallStack bool) ShutdownError

NewShutdownError builds a ShutdownError, optionally capturing the call stack.

Jump to

Keyboard shortcuts

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