sftp

package
v0.0.0-...-3e76ffc Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrForbidden = fmt.Errorf("forbidden")

Functions

func ContainsValidDir

func ContainsValidDir(path string) bool

ContainsValidDir checks that the given path contains no magical characters such as ../ and is otherwise normalized (e.g. no // or ./)

func CreateSFTPHandler

func CreateSFTPHandler(fs SimplifiedFS, accessLogger logger.AccessLogger, info logger.ConnectionInfo, log logger.Logger) gosftp.Handlers

CreateSFTPHandler converts a SimplifiedFS into a sftp.Handlers object (to serve this filesystem through sftp) while logging relevant access and information using the given logger parameters for the given connection info.

Types

type CombinedFS

type CombinedFS struct {
	Dirs map[string]SimplifiedFS
	// contains filtered or unexported fields
}

CombinedFS combines different SimplifiedFS by serving it as a subdirectory to the root of this filesystem. It is not recommended nesting several CombinedFS.

func (CombinedFS) Extract

func (c CombinedFS) Extract(path string) (string, SimplifiedFS, error)

Extract gets the filesystem that handles the given path and returns subpath within this filesystem and the filesystem itself.

func (c CombinedFS) Link(src, dst string) error

func (CombinedFS) List

func (c CombinedFS) List(path string) (func([]os.FileInfo, int64) (int, error), error)

func (CombinedFS) Lstat

func (c CombinedFS) Lstat(path string) (os.FileInfo, error)

func (CombinedFS) Mkdir

func (c CombinedFS) Mkdir(path string) error

func (CombinedFS) Read

func (c CombinedFS) Read(path string) (io.ReaderAt, error)
func (c CombinedFS) ReadLink(path string) (os.FileInfo, error)

func (CombinedFS) Rename

func (c CombinedFS) Rename(src, dst string) error

func (CombinedFS) Rm

func (c CombinedFS) Rm(path string) error

func (CombinedFS) Rmdir

func (c CombinedFS) Rmdir(path string) error

func (CombinedFS) SetStat

func (c CombinedFS) SetStat(path string, flags gosftp.FileAttrFlags, attributes *gosftp.FileStat) error

func (CombinedFS) Stat

func (c CombinedFS) Stat(path string) (os.FileInfo, error)
func (c CombinedFS) Symlink(src, dst string) error

func (CombinedFS) Write

func (c CombinedFS) Write(path string) (io.WriterAt, error)

type DirFs

type DirFs struct {
	// The path of the directory which contents become this filesystem.
	Root string
	// Whether to only support read operations.
	Readonly bool
}

DirFs implements sftp.SimplifiedFS for an operating system native directory.

func (DirFs) CanRead

func (d DirFs) CanRead(_ string) bool

func (DirFs) CanWrite

func (d DirFs) CanWrite(_ string) bool

func (DirFs) IntoAbsPath

func (d DirFs) IntoAbsPath(path string) (string, error)
func (d DirFs) Link(src, dst string) error

func (DirFs) List

func (d DirFs) List(path string) (func([]os.FileInfo, int64) (int, error), error)

func (DirFs) Lstat

func (d DirFs) Lstat(path string) (os.FileInfo, error)

func (DirFs) Mkdir

func (d DirFs) Mkdir(path string) error

func (DirFs) Read

func (d DirFs) Read(path string) (io.ReaderAt, error)
func (d DirFs) ReadLink(path string) (os.FileInfo, error)

func (DirFs) Rename

func (d DirFs) Rename(src, dst string) error

func (DirFs) Rm

func (d DirFs) Rm(path string) error

func (DirFs) Rmdir

func (d DirFs) Rmdir(path string) error

func (DirFs) SetStat

func (d DirFs) SetStat(path string, flags gosftp.FileAttrFlags, attributes *gosftp.FileStat) error

func (DirFs) Stat

func (d DirFs) Stat(path string) (os.FileInfo, error)
func (d DirFs) Symlink(src, dst string) error

func (DirFs) Write

func (d DirFs) Write(path string) (io.WriterAt, error)

type EmptyFS

type EmptyFS struct{}

EmptyFS is a sftp.SimplifiedFS that has no content at all.

func (e EmptyFS) Link(_, _ string) error

func (EmptyFS) List

func (e EmptyFS) List(_ string) (func([]os.FileInfo, int64) (int, error), error)

func (EmptyFS) Lstat

func (e EmptyFS) Lstat(path string) (os.FileInfo, error)

func (EmptyFS) Mkdir

func (e EmptyFS) Mkdir(_ string) error

func (EmptyFS) Read

func (e EmptyFS) Read(_ string) (io.ReaderAt, error)
func (e EmptyFS) ReadLink(path string) (os.FileInfo, error)

func (EmptyFS) Rename

func (e EmptyFS) Rename(_, _ string) error

func (EmptyFS) Rm

func (e EmptyFS) Rm(_ string) error

func (EmptyFS) Rmdir

func (e EmptyFS) Rmdir(_ string) error

func (EmptyFS) SetStat

func (e EmptyFS) SetStat(_ string, _ gosftp.FileAttrFlags, _ *gosftp.FileStat) error

func (EmptyFS) Stat

func (e EmptyFS) Stat(path string) (os.FileInfo, error)
func (e EmptyFS) Symlink(_, _ string) error

func (EmptyFS) Write

func (e EmptyFS) Write(_ string) (io.WriterAt, error)

type OsDirFS

type OsDirFS interface {
	SimplifiedFS
	CanRead(absolutePath string) bool
	CanWrite(absolutePath string) bool
	// IntoAbsPath Converts the given path into an absolute path in the host filesystem
	IntoAbsPath(path string) (string, error)
}

OsDirFS Parent interface for every os filesystem based implementation

type PermWrapperFS

type PermWrapperFS struct {
	// The [sftp.SimplifiedFS] to wrap
	Inner SimplifiedFS
	// A list of regular expressions for files/directories that can be read.
	CanReadRegexp []*regexp.Regexp
	// A list of regular expressions for files/directories that can be written.
	CanWriteRegexp []*regexp.Regexp
	// A list of regular expressions for files/directories that should be hidden.
	ShouldHideRegexp []*regexp.Regexp
}

PermWrapperFS is a sftp.SimplifiedFS that wraps another sftp.SimplifiedFS and reject read and write operation according to the corresponding regular expression.

func (PermWrapperFS) CanRead

func (p PermWrapperFS) CanRead(path string) bool

func (PermWrapperFS) CanWrite

func (p PermWrapperFS) CanWrite(path string) bool
func (p PermWrapperFS) Link(src, dst string) error

func (PermWrapperFS) List

func (p PermWrapperFS) List(path string) (func([]os.FileInfo, int64) (int, error), error)

func (PermWrapperFS) Lstat

func (p PermWrapperFS) Lstat(path string) (os.FileInfo, error)

func (PermWrapperFS) Mkdir

func (p PermWrapperFS) Mkdir(path string) error

func (PermWrapperFS) Read

func (p PermWrapperFS) Read(path string) (io.ReaderAt, error)
func (p PermWrapperFS) ReadLink(path string) (os.FileInfo, error)

func (PermWrapperFS) Rename

func (p PermWrapperFS) Rename(src, dst string) error

func (PermWrapperFS) Rm

func (p PermWrapperFS) Rm(path string) error

func (PermWrapperFS) Rmdir

func (p PermWrapperFS) Rmdir(path string) error

func (PermWrapperFS) SetStat

func (p PermWrapperFS) SetStat(path string, flags gosftp.FileAttrFlags, attributes *gosftp.FileStat) error

func (PermWrapperFS) ShouldHide

func (p PermWrapperFS) ShouldHide(path string) bool

ShouldHide is true iff the given path should be hidden according to the user.

func (PermWrapperFS) Stat

func (p PermWrapperFS) Stat(path string) (os.FileInfo, error)
func (p PermWrapperFS) Symlink(src, dst string) error

func (PermWrapperFS) Write

func (p PermWrapperFS) Write(path string) (io.WriterAt, error)

type SimplifiedFS

type SimplifiedFS interface {
	// List returns a function that should list the entry of the given path.
	// This returned function takes an array of file info along with an offset
	// and fills this array with the files in the directory skipping the first ones (according to the offset).
	// The function then returns the number of [os.FileInfo] actually filled into the array.
	List(path string) (func([]os.FileInfo, int64) (int, error), error)
	// Lstat returns a FileInfo describing the named file. If the file is a symbolic link, the returned FileInfo
	// describes the symbolic link. Lstat makes no attempt to follow the link.
	Lstat(path string) (os.FileInfo, error)
	// Stat returns a FileInfo describing the named file.
	Stat(path string) (os.FileInfo, error)
	// ReadLink returns the destination of the named symbolic link.
	ReadLink(path string) (os.FileInfo, error)

	// Read creates a [io.ReaderAt] object for the file at the given path.
	Read(path string) (io.ReaderAt, error)
	// Write creates a [io.WriterAt] object for the file at the given path.
	Write(path string) (io.WriterAt, error)

	// SetStat sets the attributes according to the given flags for the file at the given path.
	SetStat(path string, flags gosftp.FileAttrFlags, attributes *gosftp.FileStat) error
	// Rename renames the src file into the dst one.
	Rename(src, dst string) error
	// Rmdir removes the directory at the given path.
	Rmdir(path string) error
	// Rm removes the file at the given path.
	Rm(path string) error
	// Mkdir creates a directory at the given path.
	Mkdir(path string) error
	// Link creates a hard link for the src path to the dst path.
	Link(src, dst string) error
	// Symlink creates a symbolic link for the src path to the given dst path.
	Symlink(src, dst string) error
}

SimplifiedFS is an interface that list all operation a filesystem should support. This filesystem can then be combined, wrapped, and be converted into a sftp.Handlers to serve it as sftp filesystem.

Jump to

Keyboard shortcuts

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