Help us shape the future of Go! Take the 2026 Go Developer Survey

source

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package source fetches one object by its exact key from S3 (or an S3-compatible store), SFTP or a local directory. There is no listing: the agent must name the key. Errors from the libraries are kept for the audit; what leaves Fetch towards the agent is only "fetch_failed".

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyOutsidePrefix = errors.New("key_outside_prefix")

ErrKeyOutsidePrefix refuses a key that is not plainly under the profile prefix. Its text is the agent code.

View Source
var ErrSource = errors.New("source error")

ErrSource wraps every error a source library or the OS returned.

Functions

func CheckKey

func CheckKey(prefix, key string) (string, error)

CheckKey percent-decodes key once and returns it cleaned, or ErrKeyOutsidePrefix when it is empty, absolute, has a ".." segment, a backslash or a control character, or is not under prefix (a directory: "invoices" means "invoices/").

func Fetch

Fetch copies key from s into a new workspace handle, refusing objects above max both from Stat and while streaming.

Types

type FetchError

type FetchError struct{ Cause error }

FetchError is any failure of Fetch. Its text is the agent code; Cause is for the audit only.

func (*FetchError) Error

func (e *FetchError) Error() string

func (*FetchError) Unwrap

func (e *FetchError) Unwrap() error

type ObjectInfo

type ObjectInfo struct{ Size int64 }

ObjectInfo is audit-only.

type S3Config

type S3Config struct {
	Bucket   string
	Region   string
	Endpoint string // S3-compatible store when set (path-style addressing)
	Prefix   string
}

type S3Creds

type S3Creds struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
}

type SFTPConfig

type SFTPConfig struct {
	Host       string
	Port       int
	User       string
	BaseDir    string
	KnownHosts string // path; strict, an unknown host key is refused
}

type SFTPCreds

type SFTPCreds struct {
	Password   string
	PrivateKey []byte
	// Passphrase decrypts PrivateKey when it is encrypted.
	Passphrase []byte
}

type Source

type Source interface {
	Stat(ctx context.Context, key string) (ObjectInfo, error)
	Open(ctx context.Context, key string) (io.ReadCloser, error)
}

Source reads single objects by key. Implementations check the key themselves (CheckKey) and return ErrKeyOutsidePrefix for one that escapes.

func NewLocal

func NewLocal(root string) (Source, error)

NewLocal serves files under root. os.Root refuses any path, symlinks included, that resolves outside it.

func NewS3

func NewS3(cfg S3Config, creds S3Creds) (Source, error)

NewS3 serves objects of one bucket under cfg.Prefix.

func NewSFTP

func NewSFTP(cfg SFTPConfig, creds SFTPCreds) (Source, error)

NewSFTP serves files under cfg.BaseDir of an SFTP server whose host key must be in cfg.KnownHosts.

Jump to

Keyboard shortcuts

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