Documentation
¶
Index ¶
- Variables
- func ContainsValidDir(path string) bool
- func CreateSFTPHandler(fs SimplifiedFS, accessLogger logger.AccessLogger, info logger.ConnectionInfo, ...) gosftp.Handlers
- type CombinedFS
- func (c CombinedFS) Extract(path string) (string, SimplifiedFS, error)
- func (c CombinedFS) Link(src, dst string) error
- func (c CombinedFS) List(path string) (func([]os.FileInfo, int64) (int, error), error)
- func (c CombinedFS) Lstat(path string) (os.FileInfo, error)
- func (c CombinedFS) Mkdir(path string) error
- func (c CombinedFS) Read(path string) (io.ReaderAt, error)
- func (c CombinedFS) ReadLink(path string) (os.FileInfo, error)
- func (c CombinedFS) Rename(src, dst string) error
- func (c CombinedFS) Rm(path string) error
- func (c CombinedFS) Rmdir(path string) error
- func (c CombinedFS) SetStat(path string, flags gosftp.FileAttrFlags, attributes *gosftp.FileStat) error
- func (c CombinedFS) Stat(path string) (os.FileInfo, error)
- func (c CombinedFS) Symlink(src, dst string) error
- func (c CombinedFS) Write(path string) (io.WriterAt, error)
- type DirFs
- func (d DirFs) CanRead(_ string) bool
- func (d DirFs) CanWrite(_ string) bool
- func (d DirFs) IntoAbsPath(path string) (string, error)
- func (d DirFs) Link(src, dst string) error
- func (d DirFs) List(path string) (func([]os.FileInfo, int64) (int, error), error)
- func (d DirFs) Lstat(path string) (os.FileInfo, error)
- func (d DirFs) Mkdir(path string) error
- func (d DirFs) Read(path string) (io.ReaderAt, error)
- func (d DirFs) ReadLink(path string) (os.FileInfo, error)
- func (d DirFs) Rename(src, dst string) error
- func (d DirFs) Rm(path string) error
- func (d DirFs) Rmdir(path string) error
- func (d DirFs) SetStat(path string, flags gosftp.FileAttrFlags, attributes *gosftp.FileStat) error
- func (d DirFs) Stat(path string) (os.FileInfo, error)
- func (d DirFs) Symlink(src, dst string) error
- func (d DirFs) Write(path string) (io.WriterAt, error)
- type EmptyFS
- func (e EmptyFS) Link(_, _ string) error
- func (e EmptyFS) List(_ string) (func([]os.FileInfo, int64) (int, error), error)
- func (e EmptyFS) Lstat(path string) (os.FileInfo, error)
- func (e EmptyFS) Mkdir(_ string) error
- func (e EmptyFS) Read(_ string) (io.ReaderAt, error)
- func (e EmptyFS) ReadLink(path string) (os.FileInfo, error)
- func (e EmptyFS) Rename(_, _ string) error
- func (e EmptyFS) Rm(_ string) error
- func (e EmptyFS) Rmdir(_ string) error
- func (e EmptyFS) SetStat(_ string, _ gosftp.FileAttrFlags, _ *gosftp.FileStat) error
- func (e EmptyFS) Stat(path string) (os.FileInfo, error)
- func (e EmptyFS) Symlink(_, _ string) error
- func (e EmptyFS) Write(_ string) (io.WriterAt, error)
- type OsDirFS
- type PermWrapperFS
- func (p PermWrapperFS) CanRead(path string) bool
- func (p PermWrapperFS) CanWrite(path string) bool
- func (p PermWrapperFS) Link(src, dst string) error
- func (p PermWrapperFS) List(path string) (func([]os.FileInfo, int64) (int, error), error)
- func (p PermWrapperFS) Lstat(path string) (os.FileInfo, error)
- func (p PermWrapperFS) Mkdir(path string) error
- func (p PermWrapperFS) Read(path string) (io.ReaderAt, error)
- func (p PermWrapperFS) ReadLink(path string) (os.FileInfo, error)
- func (p PermWrapperFS) Rename(src, dst string) error
- func (p PermWrapperFS) Rm(path string) error
- func (p PermWrapperFS) Rmdir(path string) error
- func (p PermWrapperFS) SetStat(path string, flags gosftp.FileAttrFlags, attributes *gosftp.FileStat) error
- func (p PermWrapperFS) ShouldHide(path string) bool
- func (p PermWrapperFS) Stat(path string) (os.FileInfo, error)
- func (p PermWrapperFS) Symlink(src, dst string) error
- func (p PermWrapperFS) Write(path string) (io.WriterAt, error)
- type SimplifiedFS
Constants ¶
This section is empty.
Variables ¶
var ErrForbidden = fmt.Errorf("forbidden")
Functions ¶
func ContainsValidDir ¶
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 (CombinedFS) Link ¶
func (c CombinedFS) Link(src, dst string) error
func (CombinedFS) Mkdir ¶
func (c CombinedFS) Mkdir(path string) 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) Symlink ¶
func (c CombinedFS) Symlink(src, dst string) 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.
type EmptyFS ¶
type EmptyFS struct{}
EmptyFS is a sftp.SimplifiedFS that has no content at all.
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 (PermWrapperFS) Link ¶
func (p PermWrapperFS) Link(src, dst string) error
func (PermWrapperFS) Mkdir ¶
func (p PermWrapperFS) Mkdir(path string) 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) Symlink ¶
func (p PermWrapperFS) Symlink(src, dst string) 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.