objectstore

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package objectstore defines supported contrib object storage contracts for adapters.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidRef reports that an object bucket or key is empty or unsafe.
	ErrInvalidRef = errors.New("invalid object reference")
	// ErrInvalidObject reports that an object body or metadata is invalid.
	ErrInvalidObject = errors.New("invalid object")
	// ErrObjectTooLarge reports that an object exceeds the configured size limit.
	ErrObjectTooLarge = errors.New("object too large")
	// ErrContentTypeNotAllowed reports that an object content type is outside policy.
	ErrContentTypeNotAllowed = errors.New("object content type not allowed")
	// ErrUnsafeMetadata reports that object metadata appears to contain a secret.
	ErrUnsafeMetadata = errors.New("unsafe object metadata")
	// ErrObjectNotFound reports that an object does not exist.
	ErrObjectNotFound = errors.New("object not found")
	// ErrInvalidSignedURL reports invalid signed URL options.
	ErrInvalidSignedURL = errors.New("invalid signed url options")
)

Functions

func ReadAtMost

func ReadAtMost(body io.Reader, maxBytes int64) ([]byte, int64, error)

ReadAtMost reads a body into memory while enforcing a maximum size when maxBytes is positive.

func SafeMetadata

func SafeMetadata(metadata map[string]string) (map[string]string, error)

SafeMetadata validates metadata and returns a defensive copy.

func ValidateRef

func ValidateRef(ref Ref) error

ValidateRef rejects empty buckets, unsafe bucket names, and traversal-shaped keys.

Types

type GetResult

type GetResult struct {
	Body        io.ReadCloser
	ContentType string
	Size        int64
	Metadata    map[string]string
	ETag        string
}

GetResult describes an object read result. Callers must close Body.

type Policy

type Policy struct {
	MaxObjectSize       int64
	AllowedContentTypes []string
}

Policy enforces object size and content-type constraints.

func (Policy) ValidatePut

func (p Policy) ValidatePut(opts PutOptions) error

ValidatePut enforces size and content type limits.

type PutOptions

type PutOptions struct {
	Size        int64
	ContentType string
	Metadata    map[string]string
}

PutOptions describes object write policy inputs.

type Ref

type Ref struct {
	Bucket string
	Key    string
}

Ref identifies an object in a bucket.

type SignedURLOptions

type SignedURLOptions struct {
	Method      string
	Expires     time.Duration
	ContentType string
}

SignedURLOptions configures a time-limited object URL.

func NormalizeSignedURLOptions

func NormalizeSignedURLOptions(opts SignedURLOptions) (SignedURLOptions, error)

NormalizeSignedURLOptions applies defaults and validates a signed URL request.

type SignedURLer

type SignedURLer interface {
	SignedURL(ctx context.Context, ref Ref, opts SignedURLOptions) (string, error)
}

SignedURLer is implemented by stores that can issue time-limited object URLs.

type Store

type Store interface {
	Put(ctx context.Context, ref Ref, body io.Reader, opts PutOptions) error
	Get(ctx context.Context, ref Ref) (GetResult, error)
	Delete(ctx context.Context, ref Ref) error
}

Store is the minimal object storage contract used by contrib adapters and generated services.

Directories

Path Synopsis
Package objectstoretest contains reusable object store contract tests.
Package objectstoretest contains reusable object store contract tests.

Jump to

Keyboard shortcuts

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