ssh

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

internal/ssh/manager.go

Index

Constants

View Source
const (
	DefaultSSHBasePort       = 2223           // Starting port for SSH proxy allocation
	DefaultSSHMaxPort        = 2322           // Maximum port (allows 100 concurrent sessions)
	DefaultSSHCleanupTick    = time.Minute    // Cleanup interval for expired sessions
	DefaultSSHSessionTimeout = time.Hour      // Default session duration if not specified
	MaxSSHSessionDuration    = 24 * time.Hour // Maximum allowed session duration
)

Configuration constants for SSH proxy service

Variables

This section is empty.

Functions

This section is empty.

Types

type SSHManager

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

SSHManager handles SSH session creation, management, and cleanup

func NewSSHManager

func NewSSHManager(basePort, maxPort int, cleanupTick, defaultDuration time.Duration) *SSHManager

NewSSHManager creates a new SSH manager with the given configuration

func (*SSHManager) CreateSession

func (m *SSHManager) CreateSession(apiUsername, labName, nodeName, sshUsername string,
	containerIP string, containerPort int, duration time.Duration) (*SSHSession, error)

CreateSession creates a new SSH proxy session for the specified lab node

func (*SSHManager) GetSession

func (m *SSHManager) GetSession(port int) (*SSHSession, bool)

GetSession retrieves a session by port

func (*SSHManager) ListSessions

func (m *SSHManager) ListSessions(username string, isSuperuser bool) []models.SSHSessionInfo

ListSessions returns all sessions for the specified user If isSuperuser is true, all sessions are returned

func (*SSHManager) Shutdown

func (m *SSHManager) Shutdown()

Shutdown terminates all sessions and stops the manager

func (*SSHManager) TerminateSession

func (m *SSHManager) TerminateSession(port int) error

TerminateSession terminates a specific SSH session

type SSHSession

type SSHSession struct {
	Port        int       // Allocated port on API server
	LabName     string    // Name of the lab
	NodeName    string    // Name of the node within the lab
	Username    string    // SSH username to use
	ApiUsername string    // API user who created this session
	Expiration  time.Time // When this session expires
	Created     time.Time // When this session was created
	// contains filtered or unexported fields
}

SSHSession represents an active SSH proxy session

Jump to

Keyboard shortcuts

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