Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultRuntimeName(key string) string
- func NewKey() (string, error)
- func ValidateKeyFormat(key string) error
- type Connection
- type ConnectionCommitGuard
- type CreateRuntimeRequest
- type DirectPipe
- type HandshakeInfo
- type Hub
- type Pipe
- type Runtime
- type RuntimeInfo
- type Service
- func (s *Service) ActivateConnection(ctx context.Context, key, runtimeID string, info HandshakeInfo, ...) error
- func (s *Service) AuthenticateKey(ctx context.Context, key string) (Runtime, error)
- func (s *Service) Connection(runtimeID string) (*Connection, bool)
- func (s *Service) CreateRuntime(ctx context.Context, userID string, req CreateRuntimeRequest) (Runtime, error)
- func (s *Service) DeactivateConnection(runtimeID string, connection *Connection, reason string)
- func (s *Service) ListRuntimes(ctx context.Context, userID string) ([]Runtime, error)
- func (s *Service) RevokeRuntime(ctx context.Context, userID, runtimeID string) error
Constants ¶
const ( RuntimeMetadataHeader = "X-Memoh-Runtime-Metadata" CapabilityFS = "fs" CapabilityExec = "exec" CapabilityHostFS = "host_fs" )
const (
KeyPrefix = "mrk_"
)
const RuntimeGRPCMessageLimit = 16 << 20
Variables ¶
var ( ErrPipeNotConfigured = errors.New("runtime pipe is not configured") ErrInvalidPipeConnection = errors.New("invalid runtime pipe connection") ErrPipeConnectionUsed = errors.New("runtime pipe connection already consumed") ErrPipeHandshake = errors.New("runtime pipe handshake failed") )
var ( ErrInvalidInput = errors.New("invalid runtime input") ErrRuntimeConnectionNotReady = errors.New("runtime connection is no longer ready") )
var ErrInvalidKey = errors.New("invalid runtime key")
var (
ErrInvalidMetadata = errors.New("invalid runtime metadata")
)
var ErrRuntimeHubClosed = errors.New("runtime hub is closed")
Functions ¶
func DefaultRuntimeName ¶
DefaultRuntimeName is the placeholder assigned at credential creation when the caller does not pick a name. It is derived from the credential key (not user input), so the first handshake can safely replace it with the machine's hostname without ever touching a user-chosen name.
func ValidateKeyFormat ¶
Types ¶
type Connection ¶
type Connection struct {
RuntimeID string
ConnectionID string
Info RuntimeInfo
Client *bridge.Client
Close func(reason string)
// contains filtered or unexported fields
}
Connection is one immutable, ready generation of a registered Runtime. RuntimeID is stable; ConnectionID changes on every successful reconnect.
type ConnectionCommitGuard ¶
type ConnectionCommitGuard func() error
type CreateRuntimeRequest ¶
type CreateRuntimeRequest struct {
Name string `json:"name"`
}
type DirectPipe ¶
type DirectPipe struct{}
DirectPipe runs a single gRPC h2c client connection directly over the byte stream supplied by the Runtime WebSocket. ClientConn takes ownership of conn on every path, including validation and handshake failures.
A Runtime reconnect is a new WebSocket and therefore a new DirectPipe call. The dialer below deliberately cannot return the byte stream more than once, so grpc-go cannot transparently attach this ClientConn to a new transport after the WebSocket is lost.
func NewDirectPipe ¶
func NewDirectPipe() *DirectPipe
func (*DirectPipe) ClientConn ¶
func (*DirectPipe) ClientConn(ctx context.Context, conn net.Conn) (*grpc.ClientConn, error)
type HandshakeInfo ¶
type HandshakeInfo struct {
Version int `json:"version"`
Hostname string `json:"hostname"`
OS string `json:"os"`
Arch string `json:"arch"`
ClientVersion string `json:"client_version"`
WorkspaceBase string `json:"workspace_base"`
Capabilities []string `json:"capabilities"`
}
func ParseHandshakeMetadata ¶
func ParseHandshakeMetadata(encoded string) (HandshakeInfo, error)
type Runtime ¶
type Runtime struct {
ID string `json:"id"`
TeamID string `json:"team_id"`
Name string `json:"name"`
Key string `json:"key"`
CreatedAt time.Time `json:"created_at"`
Online bool `json:"online"`
WorkspaceBase string `json:"workspace_base,omitempty"`
Hostname string `json:"hostname,omitempty"`
OS string `json:"os,omitempty"`
Arch string `json:"arch,omitempty"`
ClientVersion string `json:"client_version,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
}
Runtime is one registered client. Machine details only exist while its reverse-RPC connection is online; they are not persisted.
type RuntimeInfo ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service owns the persistent pending/activated credential registry and the in-memory reverse-RPC connections. Bot/session routing belongs outside this package.
func NewService ¶
func NewService(store dbstore.UserRuntimeStore, hub *Hub) *Service
func (*Service) ActivateConnection ¶
func (s *Service) ActivateConnection(ctx context.Context, key, runtimeID string, info HandshakeInfo, connection *Connection, guard ConnectionCommitGuard) error
ActivateConnection rechecks the credential and transport readiness before consuming the pending state, then checks readiness again at the publication boundary. The lifecycle lock prevents a concurrent revoke from publishing a replacement connection after it returns.
func (*Service) AuthenticateKey ¶
func (*Service) Connection ¶
func (s *Service) Connection(runtimeID string) (*Connection, bool)
func (*Service) CreateRuntime ¶
func (*Service) DeactivateConnection ¶
func (s *Service) DeactivateConnection(runtimeID string, connection *Connection, reason string)