Documentation
¶
Index ¶
- func CleanAgentPath(p string) (string, error)
- func SpacePrefix(tenantID, spaceID uuid.UUID) string
- type ObjectInfo
- type S3Client
- func (c *S3Client) CopyObject(ctx context.Context, srcKey, dstKey string) error
- func (c *S3Client) DeleteObject(ctx context.Context, key string) error
- func (c *S3Client) DeleteObjects(ctx context.Context, keys ...string) (int, error)
- func (c *S3Client) DeletePrefix(ctx context.Context, prefix string) error
- func (c *S3Client) EnsureBucket(ctx context.Context) error
- func (c *S3Client) GetObject(ctx context.Context, key string) (io.ReadCloser, error)
- func (c *S3Client) GetObjectRange(ctx context.Context, key string, start, end int64) (io.ReadCloser, error)
- func (c *S3Client) HeadObject(ctx context.Context, key string) (ObjectInfo, string, error)
- func (c *S3Client) ListObjects(ctx context.Context, prefix string) ([]ObjectInfo, error)
- func (c *S3Client) Ping(ctx context.Context) error
- func (c *S3Client) PresignGetURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (c *S3Client) PresignPutURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (c *S3Client) PublicPresignGetURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (c *S3Client) PutObject(ctx context.Context, key string, reader io.Reader, size int64) error
- func (c *S3Client) PutObjectWithMetadata(ctx context.Context, key string, reader io.Reader, size int64, ...) error
- func (c *S3Client) SyncDown(ctx context.Context, tenantID, spaceID uuid.UUID, localRoot string) error
- func (c *S3Client) SyncPath(ctx context.Context, tenantID, spaceID uuid.UUID, relPath, localRoot string) error
- func (c *S3Client) SyncUp(ctx context.Context, tenantID, spaceID uuid.UUID, localRoot string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanAgentPath ¶ added in v0.4.0
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 ¶
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 ¶
NewS3Client creates an S3Client from config. Panics if S3URL is empty.
func NewS3ClientFromParams ¶
NewS3ClientFromParams creates an S3Client from explicit parameters (for non-airlock binaries like Anchor).
func (*S3Client) CopyObject ¶
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 ¶
DeleteObject deletes the object at the given key.
func (*S3Client) DeleteObjects ¶ added in v0.4.0
DeleteObjects deletes listed keys.
func (*S3Client) DeletePrefix ¶
DeletePrefix deletes all objects under the given prefix.
func (*S3Client) GetObject ¶
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 ¶
HeadObject returns metadata for the object at the given key.
func (*S3Client) ListObjects ¶
ListObjects lists objects under the given prefix.
func (*S3Client) Ping ¶
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 ¶
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/.