storage

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanAgentPath added in v0.4.0

func CleanAgentPath(p string) (string, error)

CleanAgentPath validates and canonicalizes a tenant-relative storage path. Returns the cleaned slash-normalized form on success.

Rejects:

  • empty paths
  • NUL bytes (S3 key delimiter / shell injection vector)
  • absolute paths (leading "/")
  • traversal segments ("..", anything that path.Clean reduces to "." or escapes the prefix)
  • empty path segments ("//")
  • backslashes (Windows-style; we operate exclusively in forward-slash space)

The returned path is suitable for concatenation under an "agents/{id}/" prefix without further escaping.

func SpacePrefix

func SpacePrefix(tenantID, spaceID uuid.UUID) string

SpacePrefix returns the S3 prefix for a space's shared files.

Types

type ObjectInfo

type ObjectInfo struct {
	Key          string
	Size         int64
	LastModified time.Time
	Metadata     map[string]string // user-defined S3 metadata (X-Amz-Meta-*)
}

ObjectInfo describes an object in S3.

type S3Client

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

S3Client provides S3/MinIO file storage for spaces.

func NewS3Client

func NewS3Client(cfg *config.Config) *S3Client

NewS3Client creates an S3Client from config. Panics if S3URL is empty.

func NewS3ClientFromParams

func NewS3ClientFromParams(endpoint, accessKey, secretKey, bucket, region string) *S3Client

NewS3ClientFromParams creates an S3Client from explicit parameters (for non-airlock binaries like Anchor).

func (*S3Client) CopyObject

func (c *S3Client) CopyObject(ctx context.Context, srcKey, dstKey string) error

CopyObject performs a server-side copy from srcKey to dstKey within the same bucket.

CopySource rides as the `x-amz-copy-source` HTTP header, which is ASCII-only — a raw key with non-Latin codepoints (e.g. "tmp/файл.png") makes the SDK or upstream reject the request and the caller gets a 500 ("failed to copy file"). Percent-encode the key per segment with `/` preserved so non-Latin filenames round-trip cleanly. dstKey doesn't need this — the SDK URL-encodes path segments itself when building the PUT URL.

func (*S3Client) DeleteObject

func (c *S3Client) DeleteObject(ctx context.Context, key string) error

DeleteObject deletes the object at the given key.

func (*S3Client) DeleteObjects added in v0.4.0

func (c *S3Client) DeleteObjects(ctx context.Context, keys ...string) (int, error)

DeleteObjects deletes listed keys.

func (*S3Client) DeletePrefix

func (c *S3Client) DeletePrefix(ctx context.Context, prefix string) error

DeletePrefix deletes all objects under the given prefix.

func (*S3Client) EnsureBucket

func (c *S3Client) EnsureBucket(ctx context.Context) error

func (*S3Client) GetObject

func (c *S3Client) GetObject(ctx context.Context, key string) (io.ReadCloser, error)

GetObject returns a reader for the object at the given key. Caller must close the reader.

func (*S3Client) GetObjectRange added in v0.4.0

func (c *S3Client) GetObjectRange(ctx context.Context, key string, start, end int64) (io.ReadCloser, error)

GetObjectRange returns a reader for the inclusive byte range [start, end] (HTTP Range semantics) of the object at key. Caller must close the reader.

func (*S3Client) HeadObject

func (c *S3Client) HeadObject(ctx context.Context, key string) (ObjectInfo, string, error)

HeadObject returns metadata for the object at the given key.

func (*S3Client) ListObjects

func (c *S3Client) ListObjects(ctx context.Context, prefix string) ([]ObjectInfo, error)

ListObjects lists objects under the given prefix.

func (*S3Client) Ping

func (c *S3Client) Ping(ctx context.Context) error

EnsureBucket creates the bucket if it doesn't exist. Ping is a read-only liveness check: HeadBucket on the configured bucket. Returns nil if S3/MinIO is reachable and the bucket exists.

func (*S3Client) PresignGetURL

func (c *S3Client) PresignGetURL(ctx context.Context, key string, expiry time.Duration) (string, error)

PresignGetURL returns a presigned GET URL for downloading a file.

func (*S3Client) PresignPutURL

func (c *S3Client) PresignPutURL(ctx context.Context, key string, expiry time.Duration) (string, error)

PresignPutURL returns a presigned PUT URL for uploading a file.

func (*S3Client) PublicPresignGetURL

func (c *S3Client) PublicPresignGetURL(ctx context.Context, key string, expiry time.Duration) (string, error)

PublicPresignGetURL returns a presigned GET URL signed for the public endpoint. If S3_URL_PUBLIC is not configured, falls back to the internal presigned URL.

func (*S3Client) PutObject

func (c *S3Client) PutObject(ctx context.Context, key string, reader io.Reader, size int64) error

PutObject uploads data from a reader to the given key. If the reader is not seekable, it is buffered into memory first.

func (*S3Client) PutObjectWithMetadata

func (c *S3Client) PutObjectWithMetadata(ctx context.Context, key string, reader io.Reader, size int64, meta map[string]string) error

PutObjectWithMetadata is the same as PutObject but persists user-defined metadata (X-Amz-Meta-*) on the stored object. The "filename" key carries the original upload filename — surfaced via HeadObject.Metadata. The "content-type" key, if set, overrides the auto-detected Content-Type.

func (*S3Client) SyncDown

func (c *S3Client) SyncDown(ctx context.Context, tenantID, spaceID uuid.UUID, localRoot string) error

SyncDown downloads the shared/ directory from S3 to localRoot/shared/.

func (*S3Client) SyncPath

func (c *S3Client) SyncPath(ctx context.Context, tenantID, spaceID uuid.UUID, relPath, localRoot string) error

SyncPath uploads a single file from localRoot to S3. relPath is relative to localRoot (e.g., "shared/foo.txt").

func (*S3Client) SyncUp

func (c *S3Client) SyncUp(ctx context.Context, tenantID, spaceID uuid.UUID, localRoot string) error

SyncUp uploads the shared/ directory from localRoot/shared/ to S3.

Jump to

Keyboard shortcuts

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