s3

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasEndpointOverride

func HasEndpointOverride() bool

HasEndpointOverride reports whether an S3-compatible endpoint is configured in place of AWS.

Types

type Client

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

Client wraps the AWS S3 SDK client with convenience methods.

func NewClient

func NewClient(ctx context.Context, region string) (*Client, *apierror.APIError)

NewClient creates a new S3 client using the given AWS region.

The EC2 IMDS credential provider is disabled: pods receive credentials via IRSA (web identity token), never the node instance role, and IMDS is unreachable from pods anyway (the node hop limit is pinned to 1 as MCP hardening). Leaving IMDS in the credential chain makes credential resolution block for the full request deadline (~5s) on every call when no other provider is configured, rather than failing fast.

func (*Client) Copy

func (c *Client) Copy(ctx context.Context, bucket, srcKey, dstKey string) *apierror.APIError

Copy copies an object within a bucket. The destination inherits SSE-AES256 from the bucket default. Idempotent: re-copying overwrites the destination, so an attach retry is safe.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, bucket, key string) *apierror.APIError

Delete removes an object from S3. S3 DeleteObject is idempotent — it returns success for a missing key — so this is safe to re-run after a partial purge.

func (*Client) FileExists

func (c *Client) FileExists(ctx context.Context, bucket, key string) (bool, *apierror.APIError)

FileExists checks whether an object exists in S3.

func (*Client) Get

func (c *Client) Get(ctx context.Context, bucket, key string) ([]byte, *apierror.APIError)

Get fetches an object's full bytes. The caller owns the returned slice; objects are expected to be modest (raw emails), so the whole body is read into memory.

func (*Client) GetPresignedPutURL

func (c *Client) GetPresignedPutURL(ctx context.Context, bucket, key, contentType string, expiry time.Duration) (string, *apierror.APIError)

GetPresignedPutURL generates a presigned PUT URL for direct client upload. The client must send the same Content-Type header when uploading. SSE-AES256 is applied on the bucket default.

func (*Client) GetPresignedURL

func (c *Client) GetPresignedURL(ctx context.Context, bucket, key string, expiry time.Duration) (string, *apierror.APIError)

GetPresignedURL generates a presigned GET URL for an S3 object.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, bucket, key string, body io.Reader, contentType string) *apierror.APIError

Upload uploads a file to S3.

type ObjectStore

type ObjectStore interface {
	Upload(ctx context.Context, bucket, key string, body io.Reader, contentType string) *apierror.APIError
	GetPresignedURL(ctx context.Context, bucket, key string, expiry time.Duration) (string, *apierror.APIError)
	// GetPresignedPutURL generates a presigned PUT URL so a client can upload directly to the bucket, keeping large media off the API request path.
	GetPresignedPutURL(ctx context.Context, bucket, key, contentType string, expiry time.Duration) (string, *apierror.APIError)
	FileExists(ctx context.Context, bucket, key string) (bool, *apierror.APIError)
	// Get fetches an object's full bytes. Used to read a raw inbound email the SES receipt rule stored.
	Get(ctx context.Context, bucket, key string) ([]byte, *apierror.APIError)
	// Delete removes an object. It is idempotent: deleting an already-absent key is not an error, so a reaper can re-attempt after a crash between the object delete and the DB row delete.
	Delete(ctx context.Context, bucket, key string) *apierror.APIError
	// Copy copies an object within a bucket (srcKey → dstKey). Used to promote a staged upload to its permanent key on attach; it is idempotent (re-copying overwrites the destination).
	Copy(ctx context.Context, bucket, srcKey, dstKey string) *apierror.APIError
}

ObjectStore defines the interface for object storage operations.

type StubClient

type StubClient struct {
	FileExistsResult bool
	// GetResult is the byte payload returned by Get (e.g. a canned raw email for inbound-bridge tests).
	GetResult []byte
}

StubClient is a no-op ObjectStore implementation for use in test mode. FileExistsResult controls what FileExists reports: it defaults to false (so photo/label lookups behave as "absent"), but a service that needs uploads to validate as present in test mode (e.g. chat attachments) can set it to true.

func (*StubClient) Copy

func (s *StubClient) Copy(_ context.Context, _, _, _ string) *apierror.APIError

func (*StubClient) Delete

func (s *StubClient) Delete(_ context.Context, _, _ string) *apierror.APIError

func (*StubClient) FileExists

func (s *StubClient) FileExists(_ context.Context, _, _ string) (bool, *apierror.APIError)

func (*StubClient) Get

func (s *StubClient) Get(_ context.Context, _, _ string) ([]byte, *apierror.APIError)

func (*StubClient) GetPresignedPutURL

func (s *StubClient) GetPresignedPutURL(_ context.Context, _, _, _ string, _ time.Duration) (string, *apierror.APIError)

func (*StubClient) GetPresignedURL

func (s *StubClient) GetPresignedURL(_ context.Context, _, _ string, _ time.Duration) (string, *apierror.APIError)

func (*StubClient) Upload

func (s *StubClient) Upload(_ context.Context, _, _ string, _ io.Reader, _ string) *apierror.APIError

Jump to

Keyboard shortcuts

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