storage

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: AGPL-3.0 Imports: 23 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 IsNoSuchUpload added in v0.6.1

func IsNoSuchUpload(err error) bool

IsNoSuchUpload reports whether S3 no longer has the multipart upload.

func IsNotFound added in v0.6.1

func IsNotFound(err error) bool

IsNotFound reports whether an exact S3 object does not exist.

func IsPreconditionFailed added in v0.6.1

func IsPreconditionFailed(err error) bool

IsPreconditionFailed reports a failed conditional object mutation.

func SpacePrefix

func SpacePrefix(tenantID, spaceID uuid.UUID) string

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

Types

type CompletedPart added in v0.6.1

type CompletedPart struct {
	Number int
	ETag   string
}

CompletedPart identifies one uploaded multipart segment.

type MultipartPart added in v0.6.1

type MultipartPart struct {
	Number int
	ETag   string
	Size   int64
}

MultipartPart is authoritative metadata reported by S3 for an uploaded part.

type ObjectInfo

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

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) AbortMultipartUpload added in v0.6.1

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

AbortMultipartUpload removes all unpublished parts for an exact upload.

func (*S3Client) CompleteMultipartUpload added in v0.6.1

func (c *S3Client) CompleteMultipartUpload(ctx context.Context, key, uploadID string, parts []CompletedPart) error

CompleteMultipartUpload atomically publishes uploaded parts at the exact key.

func (*S3Client) ConditionalCopyObject added in v0.6.1

func (c *S3Client) ConditionalCopyObject(ctx context.Context, srcKey, dstKey, sourceETag, destinationETag string, destinationExisted bool) error

ConditionalCopyObject publishes a verified staging object only if both the staging ETag and destination version still match the prepared transfer. The destination condition rides on multipart completion because common S3-compatible stores ignore destination conditions on CopyObject.

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) CreateMultipartUpload added in v0.6.1

func (c *S3Client) CreateMultipartUpload(ctx context.Context, key, contentType string, metadata map[string]string) (string, error)

CreateMultipartUpload starts an upload scoped to one exact object key.

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) ListMultipartParts added in v0.6.1

func (c *S3Client) ListMultipartParts(ctx context.Context, key, uploadID string) ([]MultipartPart, error)

ListMultipartParts returns S3-authoritative ETags and sizes for an upload.

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) PublicPresignDownloadURL added in v0.6.1

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

PublicPresignDownloadURL returns a public GET URL whose signed response headers force one safe client-visible filename.

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) PublicPresignUploadPart added in v0.6.1

func (c *S3Client) PublicPresignUploadPart(ctx context.Context, key, uploadID string, number int, expiry time.Duration) (string, error)

PublicPresignUploadPart grants a PUT for one part of one exact multipart upload.

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) PutObjectStream added in v0.6.1

func (c *S3Client) PutObjectStream(ctx context.Context, key string, body io.ReadSeeker, size int64, contentType string) error

PutObjectStream uploads a seekable body without buffering it in memory. It is intended for build artifacts, whose size can be much larger than ordinary API uploads and whose content type is already known by the caller.

func (*S3Client) PutObjectWithMetadata added in v0.2.0

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