blob

package
v0.0.0-...-bdfed93 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package blob stores files (documents, screenshots, confirmation pages) in a directory volume or an S3-compatible bucket. Sealed encrypts every object for its user (platform/crypto), so the storage only ever sees ciphertext.

Index

Constants

View Source
const MaxObject = 64 << 20

MaxObject bounds one object (uploads have their own, smaller limits).

Variables

View Source
var (
	// ErrNotFound reports a missing object.
	ErrNotFound = errors.New("blob not found")
	// ErrBadKey reports a key that is not a safe relative path.
	ErrBadKey = errors.New("invalid blob key")
	// ErrTooLarge reports an object above MaxObject.
	ErrTooLarge = errors.New("blob too large")
)

Functions

func ValidKey

func ValidKey(key string) bool

ValidKey reports whether key is safe as a relative path and an object name: 1 to 12 segments joined by '/'.

Types

type Dir

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

Dir stores objects as files below one directory. All access goes through os.Root, so no key can leave it (symlinks included); writes go to a temporary file first and are renamed into place.

func NewDir

func NewDir(dir string) (*Dir, error)

NewDir opens (and creates) dir.

func (*Dir) Close

func (d *Dir) Close() error

Close releases the directory.

func (*Dir) Delete

func (d *Dir) Delete(ctx context.Context, key string) error

Delete implements Store.

func (*Dir) Get

func (d *Dir) Get(ctx context.Context, key string) ([]byte, error)

Get implements Store.

func (*Dir) Put

func (d *Dir) Put(ctx context.Context, key string, data []byte) error

Put implements Store.

type S3

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

S3 stores objects in a bucket of an S3-compatible service (AWS, MinIO, Garage, Hetzner, …).

func (*S3) Delete

func (s *S3) Delete(ctx context.Context, key string) error

Delete implements Store.

func (*S3) Get

func (s *S3) Get(ctx context.Context, key string) ([]byte, error)

Get implements Store.

func (*S3) Put

func (s *S3) Put(ctx context.Context, key string, data []byte) error

Put implements Store.

type S3Credentials

type S3Credentials struct {
	AccessKey, SecretKey config.Secret
}

S3Credentials are the access key pair of a bucket.

type Sealed

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

Sealed stores the objects of each user under users/<id>/, encrypted with the user's data key and bound to the key, so an object moved to another key or user does not open.

func NewSealed

func NewSealed(store Store, sealer Sealer) *Sealed

NewSealed returns an encrypting store over store.

func (*Sealed) Delete

func (s *Sealed) Delete(ctx context.Context, userID uuid.UUID, key string) error

Delete removes an object.

func (*Sealed) Get

func (s *Sealed) Get(ctx context.Context, userID uuid.UUID, key string) ([]byte, error)

Get loads and decrypts an object.

func (*Sealed) Put

func (s *Sealed) Put(ctx context.Context, userID uuid.UUID, key string, data []byte) error

Put encrypts data and stores it.

type Sealer

type Sealer interface {
	Seal(ctx context.Context, userID uuid.UUID, purpose string, plaintext []byte) ([]byte, error)
	Open(ctx context.Context, userID uuid.UUID, purpose string, ciphertext []byte) ([]byte, error)
}

Sealer encrypts per user (crypto.Envelope).

type Store

type Store interface {
	Put(ctx context.Context, key string, data []byte) error
	Get(ctx context.Context, key string) ([]byte, error)
	// Delete removes an object; a missing one is not an error.
	Delete(ctx context.Context, key string) error
}

Store keeps opaque objects by key.

func Open

func Open(raw string, creds S3Credentials) (Store, error)

Open returns the store a URL names: file:///var/lib/getafjob/blobs or s3://bucket/prefix?endpoint=https://s3.example.org&region=eu-central-1.

Jump to

Keyboard shortcuts

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