storex

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: AGPL-3.0 Imports: 42 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package storex gives `komando storage` one interface over S3-compatible object storage (AWS S3, MinIO, R2, Wasabi, Spaces, B2), Google Cloud Storage, Azure Blob, FTP/FTPS, SFTP, WebDAV and SMB shares. Keys are relative to the conn's folder, so a conn can be limited to one folder, and no key may leave it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append added in v0.15.0

func Append(ctx context.Context, b Bucket, key string, off int64, r io.Reader) (int64, error)

Append adds r to the end of the file at key (see Appender).

func CanAppend added in v0.15.0

func CanAppend(b Bucket) bool

CanAppend says whether b can add to the end of a file (Append).

func CheckKey

func CheckKey(rel string) error

CheckKey refuses a key that is empty or leaves the conn's folder, so a dry run can say so before contacting the server.

func CtxReader added in v0.13.0

func CtxReader(ctx context.Context, r io.Reader) io.Reader

CtxReader is r that stops reading once ctx is done. When r tells its size (a local file), the reader tells it too, so an SFTP upload still sends chunks in parallel.

func CtxWriter added in v0.13.0

func CtxWriter(ctx context.Context, w io.Writer) io.Writer

CtxWriter is w that refuses to write once ctx is done. Wrap the destination, not the source, when the source is an SFTP file: its WriteTo reads chunks in parallel, which a wrapped source would hide.

func FolderNotFound

func FolderNotFound(prefix string) error

FolderNotFound is the one error for a folder that is not there, on every kind of storage.

func GetFrom added in v0.15.0

func GetFrom(ctx context.Context, b Bucket, key string, off int64, w io.Writer) (int64, error)

GetFrom writes the object at key from byte off on to w. A kind that cannot start in the middle reads from the start and drops the first off bytes, so it works with every kind, only with more to read.

func NotThere added in v0.15.0

func NotThere(rel string) error

NotThere is the error for a name with nothing at it.

func SortedReadDir added in v0.6.0

func SortedReadDir(c *sftp.Client, dir string) ([]os.FileInfo, error)

SortedReadDir is c.ReadDir sorted by name.

func SortedWalk added in v0.6.0

func SortedWalk(c *sftp.Client, root string) *krfs.Walker

SortedWalk is c.Walk with each folder sorted by name.

Types

type Appender added in v0.15.0

type Appender interface {
	Append(ctx context.Context, key string, off int64, r io.Reader) (int64, error)
}

Appender adds r to the end of the file at key, which is off bytes long now (0: a new file). It refuses a file of another length.

type Bucket

type Bucket interface {
	// List returns entries under prefix: one level, or everything with
	// recursive. more is true when limit was hit.
	List(ctx context.Context, prefix string, recursive bool, limit int) (objs []Object, more bool, err error)
	Get(ctx context.Context, key string, w io.Writer) (int64, error)
	Exists(ctx context.Context, key string) (bool, error)
	// Stat describes one object (not a folder) without reading it.
	Stat(ctx context.Context, key string) (Object, error)
	// Put stores r at key, replacing any old object; size is -1 if unknown.
	Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error
	Remove(ctx context.Context, key string) error
	// Link makes a temporary download URL; file servers have none.
	Link(ctx context.Context, key string, expires time.Duration) (*url.URL, error)
	// Lookup says what is at rel: a file (found, its size and time), a
	// folder (found, Dir, the key ending in /), or nothing.
	Lookup(ctx context.Context, rel string) (o Object, found bool, err error)
	// Mkdir makes the folder rel and any missing parents; existed is true
	// when it was there already. Object stores have no folders: there it
	// is an empty folder marker (rel/), as their consoles make.
	Mkdir(ctx context.Context, rel string) (existed bool, err error)
	// Move renames src to dst inside the conn (see MoveOpts). File servers
	// rename; object stores copy, check the copy and only then delete src.
	Move(ctx context.Context, src, dst string, o MoveOpts) (Moved, error)
	Close() error
}

Bucket is one storage conn: a bucket or a folder on a file server.

func Inner added in v0.15.0

func Inner(b Bucket) Bucket

Inner is the bucket inside a wrapper that has one (Unwrap), so the optional interfaces of the real bucket (Modes, Appender, RangeGetter) are found.

func NewSFTP

func NewSFTP(c *sftp.Client, prefix string, close func() error) Bucket

NewSFTP wraps an SFTP session; close also closes its SSH connection.

func OpenAzure added in v0.7.0

func OpenAzure(t driver.Target, secret string, dial DialFunc, timeout time.Duration) (Bucket, error)

OpenAzure prepares a client; it does not contact the container. secret is the account key (base64) or a SAS token (sv=...&sig=...).

func OpenFTP

func OpenFTP(ctx context.Context, t driver.Target, password string, dial DialFunc, timeout time.Duration) (Bucket, error)

OpenFTP logs in to an ftp:// or ftps:// conn. dial is nil for a direct connection; through --via, the control and data connections both use it. When the server drops a connection in the middle of an operation, the returned Bucket logs in again once and repeats it (see ftpReconnect).

func OpenGCS added in v0.7.0

func OpenGCS(_ context.Context, t driver.Target, key string, dial DialFunc, timeout time.Duration) (Bucket, error)

OpenGCS prepares a client; it does not contact the bucket. key is a service account key (JSON) from the vault, or "" for gcloud's login.

func OpenS3

func OpenS3(t driver.Target, secret string, dial DialFunc, timeout time.Duration) (Bucket, error)

OpenS3 prepares a client; it does not contact the server.

func OpenS3Creds

func OpenS3Creds(t driver.Target, accessKey, secret, sessionToken string, dial DialFunc, timeout time.Duration) (Bucket, error)

OpenS3Creds is OpenS3 with explicit credentials, including the session token of temporary ones (SSO, an assumed role).

func OpenSMB added in v0.9.0

func OpenSMB(ctx context.Context, t driver.Target, password string, dial DialFunc, timeout time.Duration) (Bucket, error)

OpenSMB logs in to an smb:// conn and mounts its share. dial is nil for a direct connection. Every message is signed (the session key comes from the password, so a server that does not know it cannot answer), and the server encrypts the session or the share when it is set up to (SMB 3). A guest login cannot sign and is refused.

func OpenWebDAV added in v0.7.0

func OpenWebDAV(t driver.Target, password string, dial DialFunc, timeout time.Duration) (Bucket, error)

OpenWebDAV prepares a client; it does not contact the server.

type BucketInfo added in v0.3.0

type BucketInfo struct{ Name, Region string }

BucketInfo is one bucket an account can see, and where it lives.

func ListBuckets added in v0.3.0

func ListBuckets(ctx context.Context, endpoint, accessKey, secret, sessionToken, region string) ([]BucketInfo, error)

ListBuckets lists the buckets the keys can see at endpoint (a URL, "" for AWS), each with its region.

type DialFunc

type DialFunc func(ctx context.Context, network, addr string) (net.Conn, error)

DialFunc opens a TCP connection, possibly through an SSH host.

type Modes added in v0.15.0

type Modes interface {
	Mode(ctx context.Context, rel string) (fs.FileMode, error)
	Chmod(ctx context.Context, rel string, mode fs.FileMode) error
}

Modes is a store whose files have Unix modes: SFTP. Other kinds have none (an object store controls access per bucket, not per file).

type MoveOpts added in v0.15.0

type MoveOpts struct {
	// Overwrite replaces a file at dst. A folder is never replaced, and a
	// folder never replaces a file.
	Overwrite bool
	// DryRun only checks, changes nothing and says what would happen.
	DryRun bool
}

MoveOpts says how Move goes.

type Moved added in v0.15.0

type Moved struct {
	Folder   bool  // src is a folder (file servers only)
	Replaced bool  // a file at dst was (or would be) replaced
	Size     int64 // src's size; 0 for a folder
	Copied   bool  // an object store: copied, checked, then src deleted (or would be)
}

Moved is what Move did, or in a dry run would do.

type Object

type Object struct {
	Key      string    `json:"key"`
	Size     int64     `json:"size"`
	Modified time.Time `json:"modified,omitempty"`
	Dir      bool      `json:"dir,omitempty"`
}

Object is one listed object (or, with Dir, a folder).

type ObjectVersion added in v0.14.0

type ObjectVersion struct {
	Key          string    `json:"key"`
	VersionID    string    `json:"version_id"`
	Size         int64     `json:"size"`
	Modified     time.Time `json:"modified,omitempty"`
	Latest       bool      `json:"latest,omitempty"`
	DeleteMarker bool      `json:"delete_marker,omitempty"`
}

ObjectVersion is one version of an object in a bucket that keeps versions (S3 versioning): every overwrite and delete leaves the old content (or a delete marker) behind, which a plain list never shows.

type RangeGetter added in v0.15.0

type RangeGetter interface {
	GetFrom(ctx context.Context, key string, off int64, w io.Writer) (int64, error)
}

RangeGetter reads an object from an offset on without reading what is before it (an S3 ranged GET, an SFTP seek).

type Versioned added in v0.14.0

type Versioned interface {
	Versions(ctx context.Context, prefix string, limit int) (vs []ObjectVersion, more bool, err error)
	RemoveVersion(ctx context.Context, key, versionID string) error
}

Versioned is a bucket whose old versions komando can list and remove (S3 and S3-compatible stores; others keep no versions komando can see).

Directories

Path Synopsis
Package ftptest is an FTP and FTPS server for tests: one file, obj.txt, in /, or set listings by folder.
Package ftptest is an FTP and FTPS server for tests: one file, obj.txt, in /, or set listings by folder.

Jump to

Keyboard shortcuts

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