objectstore

package
v5.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package objectstore provides AppTheory's narrow object-store helper surface.

Index

Constants

View Source
const MaxPresignPutExpiresIn = 15 * time.Minute

MaxPresignPutExpiresIn is the framework ceiling for a bounded object upload grant.

An upload grant is the single narrow presigning exception in AppTheory's object-store contract. It never extends past fifteen minutes.

Variables

View Source
var (
	// ErrInvalidGetLimit is returned when a Get request does not set a positive byte cap.
	ErrInvalidGetLimit = errors.New("objectstore: max bytes must be positive")
	// ErrObjectTooLarge is returned when a bounded Get would exceed its byte cap.
	ErrObjectTooLarge = errors.New("objectstore: object exceeds max bytes")
	// ErrObjectNotFound is returned by deterministic stores when the requested object is absent.
	ErrObjectNotFound = errors.New("objectstore: object not found")
)

Stable object-store operation errors.

View Source
var ErrInvalidEncryptionConfig = errors.New("objectstore: invalid encryption config")

ErrInvalidEncryptionConfig is returned when S3 encryption options are contradictory or incomplete.

View Source
var ErrInvalidObjectRef = errors.New("objectstore: invalid object ref")

ErrInvalidObjectRef is returned when an object reference is incomplete or unsupported.

View Source
var ErrInvalidPresignPut = errors.New("objectstore: invalid presign put")

ErrInvalidPresignPut is returned when an upload-grant request is incomplete or unsafe.

View Source
var ErrInvalidStoreConfig = errors.New("objectstore: invalid store config")

ErrInvalidStoreConfig is returned when an object-store implementation is misconfigured.

Functions

This section is empty.

Types

type DeleteInput

type DeleteInput struct {
	Ref ObjectRef
}

DeleteInput removes one object reference. Ref.VersionID is honored by stores that support versioned objects.

type GetInput

type GetInput struct {
	Ref      ObjectRef
	MaxBytes int64
}

GetInput reads one object reference with a required maximum byte cap.

type GetOutput

type GetOutput struct {
	Ref         ObjectRef
	Payload     []byte
	ContentType string
	Metadata    map[string]string
}

GetOutput is the bounded byte payload returned by Store.Get.

type ObjectRef

type ObjectRef struct {
	Bucket    string
	Key       string
	VersionID string
}

ObjectRef identifies one object in an S3-compatible object store.

Bucket and Key are always required. VersionID is optional and is used only by version-aware operations such as Get and Delete.

func ParseObjectRef

func ParseObjectRef(raw string) (ObjectRef, error)

ParseObjectRef parses a strict s3://bucket/key reference.

The parser does not normalize, decode, or default any component: valid bucket and key values are preserved exactly as they appear in the input reference.

func (ObjectRef) Validate

func (r ObjectRef) Validate() error

Validate verifies that the reference has the components required for an AppTheory object-store operation.

type PresignPutInput

type PresignPutInput struct {
	Ref            ObjectRef
	ContentLength  int64
	ChecksumSHA256 string
	ContentType    string
	MaxBytes       int64
	ExpiresIn      time.Duration
}

PresignPutInput describes one bounded upload grant request.

Every field is required. Ref must be an exact, unversioned s3://bucket/key reference; ContentLength must be positive and no larger than MaxBytes; ChecksumSHA256 must be the canonical base64 encoding of the 32-byte SHA-256 digest of the exact bytes the client will upload; ContentType must be non-empty; and ExpiresIn must be a whole number of seconds, positive and at most MaxPresignPutExpiresIn. ContentLength, MaxBytes and ExpiresIn are typed integers here, so a fractional byte count or expiry cannot even be expressed; the other runtimes refuse one with ErrInvalidPresignPut instead.

func (PresignPutInput) Validate

func (i PresignPutInput) Validate() error

Validate verifies that an upload-grant request is complete and safe.

Every failure mode is fail-closed: an unversioned exact reference, a positive content length no larger than MaxBytes, a non-empty unpadded content type, the canonical base64 SHA-256 digest, and an expiry of a whole number of seconds, above zero and at most MaxPresignPutExpiresIn.

Whole seconds matter because the grant carries the expiry as X-Amz-Expires, an integer number of seconds. A sub-second or fractional expiry would be truncated to zero by the signer and mint a link that has already expired, so it is refused here with ErrInvalidPresignPut, identically for the S3 store and the test fake.

type PresignPutOutput

type PresignPutOutput struct {
	Ref       ObjectRef
	URL       string
	Method    string
	Headers   map[string]string
	ExpiresAt time.Time
}

PresignPutOutput is a bounded upload grant.

Headers holds exactly the headers the client must send with the upload. The URL only ever authorizes those bytes: content length, content type and checksum are part of the signed headers.

type PutInput

type PutInput struct {
	Ref         ObjectRef
	Payload     []byte
	ContentType string
	Metadata    map[string]string
}

PutInput writes a byte payload to one object reference.

type S3EncryptionConfig

type S3EncryptionConfig struct {
	Mode     S3EncryptionMode
	KMSKeyID string
}

S3EncryptionConfig configures fail-closed S3 server-side encryption headers.

type S3EncryptionMode

type S3EncryptionMode string

S3EncryptionMode selects the server-side encryption headers emitted for S3 PutObject.

const (
	// S3EncryptionBucketDefault emits no server-side encryption headers and relies on bucket policy/defaults.
	S3EncryptionBucketDefault S3EncryptionMode = "bucket-default"
	// S3EncryptionS3Managed emits the S3-managed AES256 server-side encryption header.
	S3EncryptionS3Managed S3EncryptionMode = "s3-managed"
	// S3EncryptionKMS emits AWS KMS server-side encryption headers with a required key ID.
	S3EncryptionKMS S3EncryptionMode = "kms"
)

type S3StoreConfig

type S3StoreConfig struct {
	Encryption S3EncryptionConfig
}

S3StoreConfig configures the narrow S3-backed Store implementation.

type Store

type Store interface {
	Put(context.Context, PutInput) (ObjectRef, error)
	Get(context.Context, GetInput) (*GetOutput, error)
	Delete(context.Context, DeleteInput) error
}

Store is AppTheory's narrow object-store contract.

It intentionally supports only byte Put, bounded Get, and Delete. There is no unbounded read method and no listing, public URL, multipart, copy, head, or raw client escape hatch.

UploadGranter is the one bounded presigning exception and is deliberately a separate capability interface rather than a fourth Store method, so a store opts in to minting upload links and no existing Store implementation changes shape.

func NewS3Store

func NewS3Store(ctx context.Context, storeConfig S3StoreConfig) (Store, error)

NewS3Store loads AWS SDK v2 configuration and returns the S3-backed Store.

The returned store also implements UploadGranter, so callers that need the bounded upload grant upgrade the interface rather than changing how they construct the store:

granter, ok := store.(objectstore.UploadGranter)

type UploadGranter

type UploadGranter interface {
	PresignPut(context.Context, PresignPutInput) (*PresignPutOutput, error)
}

UploadGranter is AppTheory's bounded upload-grant capability.

It is deliberately separate from Store: the bounded Put/Get/Delete contract is unchanged, and a store opts in to minting upload links. The only grant it can mint authorizes a single PUT of declared bytes to one exact object reference, with a signed content length, content type and SHA-256 checksum, for at most MaxPresignPutExpiresIn.

Presigned GET, presigning without a checksum, list, multipart, copy, head, public URLs and raw clients remain forbidden: they have no method here and none on Store.

Jump to

Keyboard shortcuts

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