grpc

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: AGPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppServiceServer

type AppServiceServer struct {
	k8shelldv1.UnimplementedAppServiceServer
	// contains filtered or unexported fields
}

AppServiceServer implements the gRPC server for application management.

func NewAppServiceServer

func NewAppServiceServer(appManager *apps.AppManager) *AppServiceServer

NewAppServiceServer creates a new AppServiceServer instance.

func (*AppServiceServer) GetLogs

GetLogs retrieves the logs of the specified type (install/app) for the given app name.

func (*AppServiceServer) GetLogsStream

GetLogsStream streams the logs of the specified type (install/app) for the given app name.

func (*AppServiceServer) InstallApp

InstallApp installs the specified application by name.

func (*AppServiceServer) ListApps

ListApps lists the status of all applications.

func (*AppServiceServer) StartApp

StartApp starts the specified application by name.

func (*AppServiceServer) StopApp

StopApp stops the specified application by name.

type DetachedSessionInfo

type DetachedSessionInfo struct {
	Id         string `json:"id"`
	CmdShell   string `json:"cmd_shell"`
	Pid        int    `json:"pid"`
	Created    string `json:"created"`
	DetachedAt string `json:"detached_at"`
}

DetachedSessionInfo is returned by ListDetachedSessions.

type ExecData

type ExecData struct {
	Id       string
	Command  string
	Created  time.Time
	Deleted  time.Time
	BytesIn  uint64
	BytesOut uint64
}

exec data structure

type ExecHandler

type ExecHandler struct {
	// contains filtered or unexported fields
}

ExecHandler is the service that handles the exec GRPC service server

func (*ExecHandler) Exec

Exec runs a command as `<shell> -c <command>`, like sshd, optionally attached to a PTY. The shell is the shell_binary hint if it exists in the workspace, otherwise the user's passwd login shell, otherwise /bin/sh.

func (*ExecHandler) GetExecID

func (s *ExecHandler) GetExecID(ctx context.Context) (string, error)

Get the exec ID from the gRPC metadata "exec-id"

type GRPCService

type GRPCService struct {
	Config *config.Config // The main configuration

	ExecStore        *sync.Map // The store for the exec data
	PortForwardStore *sync.Map // The store for the port forwarding data
	SessionStore     *sync.Map // The store for the session data
	UnixSocketStore  *sync.Map // The store for the unix socket data

	SessionLockStore *sync.Map // stores *sessionLock keyed by lock ID
	// contains filtered or unexported fields
}

GRPCApiService is the main service that handles the gRPC API

func NewGRPCService

func NewGRPCService(config *config.Config, blueprint *commonmodels.Blueprint, user *models.User,
	procWatcher *system.ProcessWatcher, apiClient *apiclient.Client,
	appManager *apps.AppManager, sysInfo *system.SystemInfo) (*GRPCService, error)

NewGRPCAPI creates a new GRPCApiService

func (*GRPCService) DetachShellSession

func (a *GRPCService) DetachShellSession(sessionId string, ttl *time.Duration) error

DetachShellSession triggers a detach on the currently attached client for the given session, optionally setting a per-session TTL override. The shell process and ring buffer stay alive.

func (*GRPCService) GetAllStreamData

func (a *GRPCService) GetAllStreamData() ([]StoreRecord, error)

func (*GRPCService) ListDetachedSessions

func (a *GRPCService) ListDetachedSessions() []DetachedSessionInfo

ListDetachedSessions returns sessions that are alive but have no attached client

func (*GRPCService) NumSessions

func (a *GRPCService) NumSessions() uint32

NumSessions returns the number of active sessions

func (*GRPCService) ResizeSession

func (a *GRPCService) ResizeSession(sessionId string, width, height uint32) error

ResizeSession resizes the PTY of any shell session (attached or detached).

func (*GRPCService) Serve

func (a *GRPCService) Serve(ctx context.Context) error

Serve starts the gRPC server and registers the services. It also sets up the TLS configuration and the interceptor.

func (*GRPCService) ServeRESTAttach

func (a *GRPCService) ServeRESTAttach(sessionId string, conn net.Conn) error

ServeRESTAttach attaches a hijacked HTTP conn to the session: replays the ring-buffer scrollback, registers the conn as the current sender, then bridges PTY I/O until the session ends or the client calls `kbox detach`. Blocks until the session is destroyed or detached.

func (*GRPCService) SetInitTracker

func (a *GRPCService) SetInitTracker(t *models.InitTracker)

SetInitTracker wires the init script tracker into the gRPC service so that new PTY shell sessions can display init progress before handing off to the shell.

func (*GRPCService) ValidateSessionForAttach

func (a *GRPCService) ValidateSessionForAttach(sessionId string) (int, error)

ValidateSessionForAttach checks that a session exists, is a live PTY session, and has no client currently attached.

type PortForwardData

type PortForwardData struct {
	Id          string
	Destination string
	Port        uint16
	Created     time.Time
	Deleted     time.Time
	BytesIn     uint64
	BytesOut    uint64
}

Port-forward data structure

type PortForwardHandler

type PortForwardHandler struct {
	// contains filtered or unexported fields
}

PortForwardHandler is the service that handles the port-forwarding GRPC service server

func (*PortForwardHandler) GetPortForwardData

func (s *PortForwardHandler) GetPortForwardData(ctx context.Context) (*PortForwardData, error)

Get the port-forward data from the store. It uses the port-forward ID retrieved from the metadata

func (*PortForwardHandler) GetPortForwardID

func (s *PortForwardHandler) GetPortForwardID(ctx context.Context) (string, error)

Get the port-forward ID from the gRPC metadata "portforward-id"

func (*PortForwardHandler) PortForward

PortForward sets up a TCP <-> gRPC bidi bridge. First request must be Destination. Then we stream bytes both ways until client closes, TCP closes, context cancels, or an error occurs.

type RingBuffer

type RingBuffer struct {
	// contains filtered or unexported fields
}

RingBuffer is a thread-safe fixed-capacity circular byte buffer. When full, new writes overwrite the oldest data (like a terminal scrollback).

func (*RingBuffer) Mark

func (r *RingBuffer) Mark()

Mark records the current write position. A subsequent SnapshotSinceMark call will return only bytes written after this point.

func (*RingBuffer) Snapshot

func (r *RingBuffer) Snapshot() []byte

Snapshot returns a copy of all buffered data in order (oldest to newest).

func (*RingBuffer) SnapshotSinceMark

func (r *RingBuffer) SnapshotSinceMark() []byte

SnapshotSinceMark returns only the bytes written since the last Mark call. If no mark has been set, it behaves like Snapshot. If more bytes were written than the buffer capacity since the mark, all currently buffered bytes are returned (the oldest ones were overwritten).

func (*RingBuffer) Write

func (r *RingBuffer) Write(data []byte)

Write appends data to the buffer, overwriting the oldest bytes when full.

type SessionData

type SessionData struct {
	Id string

	CmdShell string
	Cmd      *exec.Cmd
	Ptmx     *os.File
	Pid      int
	Created  time.Time
	Deleted  time.Time
	BytesIn  uint64
	BytesOut uint64

	// PTY session state (nil/zero for non-PTY sessions)
	DetachedAt time.Time      // set when a client detaches from a live session
	DetachTTL  *time.Duration // per-session TTL override; nil = use server default; 0 = never expire
	// contains filtered or unexported fields
}

SessionData stores the data of a shell session.

type ShellHandler

type ShellHandler struct {
	// contains filtered or unexported fields
}

ShellHandler is the service that handles the shell GRPC service server

func (*ShellHandler) AcquireSession

AcquireSession implements SshServiceServer.AcquireSession. It validates that the requested session exists, is a live detached PTY session with no client attached and no unexpired lock, then creates and returns a lock ID

func (*ShellHandler) GetCWD

GetCWD returns the current working directory of the shell process identified by the shell_id in the request. The CWD is resolved by reading the /proc/<pid>/cwd symlink of the shell process.

func (*ShellHandler) GetSessionData

func (s *ShellHandler) GetSessionData(ctx context.Context) (*SessionData, error)

Get the session data from the store. It uses the session ID retrieved from the metadata

func (*ShellHandler) GetSessionID

func (s *ShellHandler) GetSessionID(ctx context.Context) (string, error)

Get the port-forward ID from the gRPC metadata "portforward-id"

func (*ShellHandler) ListSessions added in v0.16.0

ListSessions implements SshServiceServer.ListSessions. It returns the set of live PTY sessions that AcquireSession would currently accept: no client attached and no unexpired lock held, along with the OS user each session runs as.

func (*ShellHandler) ResizeTerminal

ResizeTerminal is a gRPC method that resizes the terminal of a shell session.

func (*ShellHandler) Shell

Shell is a gRPC method that starts a shell session. It is a bidirectional streaming RPC that sends the shell output to the client and receives the client input to send to the shell.

type SshServiceServer

type SshServiceServer struct {
	k8shelldv1.UnimplementedSshServiceServer
	// contains filtered or unexported fields
}

SshServiceServer implements k8shelldv1.SshServiceServer by composing the individual service implementations.

func NewSshServiceServer

func NewSshServiceServer(grpcapi *GRPCService) *SshServiceServer

NewSshServiceServer creates a new SshServiceServer.

func (*SshServiceServer) AcquireSession

func (*SshServiceServer) GetCWD

func (*SshServiceServer) ListSessions added in v0.16.0

func (*SshServiceServer) ResizeTerminal

type StoreRecord

type StoreRecord struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Created  string `json:"created"`
	Deleted  string `json:"deleted"`
	Status   string `json:"status"`
	BytesIn  uint64 `json:"bytes_in"`
	BytesOut uint64 `json:"bytes_out"`
	Params   string `json:"params"`
}

type SystemServiceServer

type SystemServiceServer struct {
	k8shelldv1.UnimplementedSystemServiceServer
	// contains filtered or unexported fields
}

SystemServiceServer is the gRPC server for the system service

func NewSystemServiceServer

func NewSystemServiceServer(grpcapi *GRPCService) *SystemServiceServer

NewSystemServiceServer creates a new SystemServiceServer

func (*SystemServiceServer) GetBlueprint added in v0.16.0

GetBlueprint returns the raw blueprint YAML content this workspace was created from.

func (*SystemServiceServer) GetLogsPage added in v0.16.0

GetLogsPage returns one page of k8shelld daemon logs strictly older than the requested BeforeId, for "load more" / infinite-scroll style backward pagination independent of GetLogsStream's live tail.

func (*SystemServiceServer) GetLogsStream added in v0.16.0

GetLogsStream streams k8shelld daemon logs (the same logs shown by `kbox logs`). With Follow=false it sends the currently buffered entries and closes the stream; with Follow=true it keeps streaming new entries as they are produced until the client cancels.

func (*SystemServiceServer) Handshake

Handshake validates version compatibility. Returns the server version and Accepted=true on success; returns a descriptive Message and Accepted=false (not a gRPC error) for version mismatches so the caller can surface a helpful message to the user.

func (*SystemServiceServer) SystemInfo

SystemInfo returns system metrics + mount usage + docker usage over gRPC. Mirrors the REST /sysinfo payload.

func (*SystemServiceServer) SystemInfoHistory added in v0.16.0

SystemInfoHistory returns historical system/mount/docker usage samples for charting. See the proto comment on SystemInfoHistoryRequest for the precedence of range vs from/to and how step coarsening works.

type UnixSocketHandler

type UnixSocketHandler struct {
	// contains filtered or unexported fields
}

UnixSocketHandler is the service that handles the shell GRPC service server

func (*UnixSocketHandler) GetUnixSocketData

func (s *UnixSocketHandler) GetUnixSocketData(ctx context.Context) (*SessionData, error)

Get the unix socket data from the store. It uses the unix socket ID retrieved from the metadata

func (*UnixSocketHandler) GetUnixSocketID

func (s *UnixSocketHandler) GetUnixSocketID(ctx context.Context) (string, error)

Get the unix socket ID from the gRPC metadata "unixsocket-id"

Jump to

Keyboard shortcuts

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