archive

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package archive is the cloud seam for long-term archival of agent runs: a create-only object store over Amazon S3 or Google Cloud Storage.

Patchy only ever writes an object once and never deletes one. Retention, legal hold, encryption keys, tiering and expiry all belong to the bucket's own policy (S3 Object Lock, a GCS retention lock, CMK/CMEK, lifecycle rules), so an operator's audit guarantees never depend on patchy behaving.

Every write is conditional on the object not existing (S3 If-None-Match: *, GCS DoesNotExist). A retry that finds an object already there succeeds when the stored sha256 matches the new body and fails with ErrConflict when it does not, so a re-collected run converges instead of either overwriting evidence or erroring forever.

Credentials always come from the platform's default chain (IRSA or EKS Pod Identity, GKE workload identity, ADC), so no key material exists anywhere. The package has no Kubernetes imports: internal/runarchive owns assembling a run's objects and recording where they went.

Index

Constants

View Source
const MaxPresignTTL = 7 * 24 * time.Hour

MaxPresignTTL is the longest a presigned URL may live. Both S3 SigV4 and GCS V4 signing cap expiry at seven days.

View Source
const MetadataSHA256 = "sha256"

MetadataSHA256 is the user-metadata key every object carries its body's hex sha256 under (x-amz-meta-sha256 on S3, metadata.sha256 on GCS). It is what makes a create-only retry idempotent without re-reading the body.

Variables

View Source
var (
	// ErrNotFound reports an object that does not exist.
	ErrNotFound = errors.New("archive: object not found")
	// ErrConflict reports a create-only write that found a different object
	// already at the key. It is never retried: the archive is immutable, so
	// a different body means the caller is not writing what it wrote before.
	ErrConflict = errors.New("archive: object exists with different content")
)

Functions

func Join

func Join(parts ...string) string

Join builds an object key from parts, dropping empty parts and stray slashes so a prefix of "", "audit" or "/audit/" all behave alike.

func RegisterFlags

func RegisterFlags(f *pflag.FlagSet)

RegisterFlags declares the store-location flags every binary that reads or writes the archive shares (PATCHY_ARCHIVE_* in the environment).

func SHA256

func SHA256(body []byte) string

SHA256 is the hex digest the archive records for body.

Types

type Config

type Config struct {
	// Provider is s3 or gcs; empty disables archival.
	Provider Provider
	// Bucket name.
	Bucket string
	// Prefix every key starts with (no leading or trailing slash needed).
	Prefix string
	// Region of an S3 bucket; empty uses the SDK default chain.
	Region string
	// Endpoint overrides the service endpoint, for S3-compatible stores and
	// tests. On S3 it also switches to path-style addressing.
	Endpoint string
	// KMSKey encrypts each write with this key (an S3 KMS key id or ARN, or
	// a GCS CryptoKey resource name). Empty leaves the bucket default.
	KMSKey string
}

Config locates the bucket and the key prefix runs are archived under. An empty Provider means archival is disabled.

func ConfigFrom

func ConfigFrom(o StringGetter) Config

ConfigFrom reads the flags RegisterFlags declared.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether archival is configured.

func (Config) Key

func (c Config) Key(parts ...string) string

Key joins the configured prefix with parts into an object key.

func (Config) Validate

func (c Config) Validate() error

Validate checks an enabled configuration is complete.

type Location

type Location struct {
	Provider Provider
	Bucket   string
	Region   string
	Endpoint string
	Key      string
}

Location is everything needed to find one object without any patchy configuration: a CLI holding only the run's status can open the store and read the key with the caller's own credentials.

func (Location) Config

func (l Location) Config() Config

Config is the store configuration that reaches this location.

func (Location) URI

func (l Location) URI() string

URI renders the location as s3://bucket/key or gs://bucket/key.

type Provider

type Provider string

Provider names an object-store backend.

const (
	ProviderS3  Provider = "s3"
	ProviderGCS Provider = "gcs"
)

The supported providers.

type Store

type Store interface {
	// Put writes body at key exactly once. Writing the same bytes again
	// succeeds; writing different bytes fails with ErrConflict.
	Put(ctx context.Context, key string, body []byte, contentType string) error
	// Get opens an object for reading; ErrNotFound when it is absent.
	Get(ctx context.Context, key string) (io.ReadCloser, error)
	// Presign returns a URL that GETs key without credentials until it
	// expires. A non-empty attachment asks the browser to download the
	// object under that file name instead of displaying it.
	Presign(ctx context.Context, key string, ttl time.Duration,
		attachment string) (url string, expires time.Time, err error)
	// Close releases the client.
	Close() error
}

Store is a create-only object store.

func Open

func Open(ctx context.Context, cfg Config) (Store, error)

Open connects to the configured store using the platform's default credential chain. It does not touch the bucket: a store that cannot be reached surfaces on the first write, where the caller's retry policy applies.

type StringGetter

type StringGetter interface {
	String(key string) string
}

StringGetter reads a resolved flag value.

Directories

Path Synopsis
Package archivetest provides an in-memory archive.Store for tests of the packages that archive runs or serve archived objects.
Package archivetest provides an in-memory archive.Store for tests of the packages that archive runs or serve archived objects.

Jump to

Keyboard shortcuts

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