sftp

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DispatcherFileOperator

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

DispatcherFileOperator routes file operations through the dispatcher to the correct worker. Used on controller/standalone nodes where SFTP needs to reach remote workers.

func NewDispatcherFileOperator

func NewDispatcherFileOperator(dispatcher *orchestrator.Dispatcher, gameserverID string) *DispatcherFileOperator

func (*DispatcherFileOperator) CreateDirectory

func (o *DispatcherFileOperator) CreateDirectory(volumeName string, path string) error

func (*DispatcherFileOperator) DeletePath

func (o *DispatcherFileOperator) DeletePath(volumeName string, path string) error

func (*DispatcherFileOperator) ListFiles

func (o *DispatcherFileOperator) ListFiles(volumeName string, path string) ([]FileEntry, error)

func (*DispatcherFileOperator) ReadFile

func (o *DispatcherFileOperator) ReadFile(volumeName string, path string) ([]byte, error)

func (*DispatcherFileOperator) RenamePath

func (o *DispatcherFileOperator) RenamePath(volumeName string, from string, to string) error

func (*DispatcherFileOperator) WriteFile

func (o *DispatcherFileOperator) WriteFile(volumeName string, path string, content []byte, perm os.FileMode) error

type FileEntry

type FileEntry struct {
	Name    string
	IsDir   bool
	Size    int64
	ModTime int64
}

FileEntry represents a file or directory in a volume.

type FileOperator

type FileOperator interface {
	ListFiles(volumeName string, path string) ([]FileEntry, error)
	ReadFile(volumeName string, path string) ([]byte, error)
	WriteFile(volumeName string, path string, content []byte, perm os.FileMode) error
	DeletePath(volumeName string, path string) error
	CreateDirectory(volumeName string, path string) error
	RenamePath(volumeName string, from string, to string) error
}

FileOperator abstracts volume-level file operations for the SFTP handler.

type FileOperatorFactory

type FileOperatorFactory func(gameserverID string) FileOperator

FileOperatorFactory creates a FileOperator for a given session. On workers, this returns the same WorkerFileOperator each time. On controllers, this creates a DispatcherFileOperator scoped to the gameserver.

type GameserverLookup

type GameserverLookup interface {
	GetGameserverBySFTPUsername(username string) (*model.Gameserver, error)
}

GameserverLookup abstracts the DB query needed for SFTP auth.

type LocalAuth

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

LocalAuth validates SFTP credentials directly against the database. Used on standalone and controller nodes.

func NewLocalAuth

func NewLocalAuth(store GameserverLookup) *LocalAuth

func (*LocalAuth) ValidateLogin

func (a *LocalAuth) ValidateLogin(username, password string) (string, string, error)

type RemoteAuth

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

RemoteAuth validates SFTP credentials by calling back to the controller via gRPC. Used on worker nodes.

func NewRemoteAuth

func NewRemoteAuth(client pb.ControllerServiceClient) *RemoteAuth

func (*RemoteAuth) ValidateLogin

func (a *RemoteAuth) ValidateLogin(username, password string) (string, string, error)

type SFTPAuth

type SFTPAuth interface {
	ValidateLogin(username, password string) (gameserverID string, volumeName string, err error)
}

SFTPAuth validates SFTP login credentials and returns the gameserver ID and volume name.

type Server

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

func NewServer

func NewServer(auth SFTPAuth, fileOpFactory FileOperatorFactory, hostKeyPath string, log *slog.Logger) (*Server, error)

func (*Server) Close

func (s *Server) Close() error

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

type WorkerFileOperator

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

WorkerFileOperator adapts a worker.Worker to the FileOperator interface. Used on worker nodes where file operations are local.

func NewWorkerFileOperator

func NewWorkerFileOperator(w worker.Worker) *WorkerFileOperator

func (*WorkerFileOperator) CreateDirectory

func (o *WorkerFileOperator) CreateDirectory(volumeName string, path string) error

func (*WorkerFileOperator) DeletePath

func (o *WorkerFileOperator) DeletePath(volumeName string, path string) error

func (*WorkerFileOperator) ListFiles

func (o *WorkerFileOperator) ListFiles(volumeName string, path string) ([]FileEntry, error)

func (*WorkerFileOperator) ReadFile

func (o *WorkerFileOperator) ReadFile(volumeName string, path string) ([]byte, error)

func (*WorkerFileOperator) RenamePath

func (o *WorkerFileOperator) RenamePath(volumeName string, from string, to string) error

func (*WorkerFileOperator) WriteFile

func (o *WorkerFileOperator) WriteFile(volumeName string, path string, content []byte, perm os.FileMode) error

Jump to

Keyboard shortcuts

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