config

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config loads runtime configuration from the environment (12-factor). It is imported only by the composition root (cmd/server); no other package reads the environment directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Archive added in v1.3.0

type Archive struct {
	MaxEntries    int      // entries an archive may hold; both archive endpoints refuse larger ones
	MaxTotalBytes int64    // uncompressed bytes one extraction may write
	MaxRatio      int64    // per-entry uncompressed ÷ compressed; the zip-bomb guard
	Extensions    []string // allowlist, lower-case with the leading dot; empty allows every extension

	// MaxDirectoryBytes bounds the central directory's byte span, the only cap
	// that can be applied before archive/zip parses it. Zero does not disable
	// it — it derives the bound from MaxEntries, which is the right answer
	// almost always — because this is what bounds the allocation a crafted
	// directory provokes. Set it only for an archive with unusually long paths.
	MaxDirectoryBytes int64
}

Archive bounds archive extraction (POST /files/{id}/extract). Zero disables each cap, matching MaxUploadBytes. Per-entry size is not here: an extracted entry is an upload, so it reuses CAIRNMARK_MAX_UPLOAD_BYTES — the upload cap alone would not cover it, since entries enter below the handler that enforces it.

type Config

type Config struct {
	HTTPAddr        string        // listen address, e.g. ":8080"
	ShutdownTimeout time.Duration // graceful shutdown grace period
	PresignTTL      time.Duration // lifetime of presigned download URLs
	MaxUploadBytes  int64         // reject uploads larger than this; 0 disables the cap

	Postgres Postgres
	Storage  Storage
	GC       GC
	Archive  Archive
	Jobs     Jobs
}

Config is the fully-resolved runtime configuration.

func Load

func Load() (Config, error)

Load reads configuration from the environment, applying defaults. It returns an error if a required value is missing or malformed. As of Phase 1 the Postgres and S3 settings are required — the server connects to both at boot.

type GC

type GC struct {
	Interval       time.Duration
	GracePeriod    time.Duration
	IdempotencyTTL time.Duration
}

GC configures the background reconciliation sweep. A non-positive Interval disables it. GracePeriod is how old an unreferenced object must be before it is treated as an orphan — it must exceed the longest plausible upload so an in-flight write (object stored, row not yet committed) is never reclaimed. IdempotencyTTL is how long upload idempotency keys are retained before the sweep expires them (non-positive disables expiry).

type Jobs added in v1.3.0

type Jobs struct {
	// Concurrency is how many jobs one replica runs at once. Default 1, on
	// purpose: extraction is IO-bound on the object store, the jobs table
	// already keeps two workers off one archive, and every in-flight run pins
	// a read window plus a multipart part of memory. Raise it with evidence.
	Concurrency int

	// HeartbeatTTL is how long a running job may go without a heartbeat
	// before its worker is presumed dead and the job is returned to the
	// queue. Two-sided, like the lease TTL it replaces: too long and a
	// crashed job blocks its archive for that long; too short and a healthy
	// run is stolen mid-flight. Zero is not "disabled" — it would reap every
	// job instantly — so it is refused.
	HeartbeatTTL time.Duration

	// Retention is how long a finished job stays readable through
	// GET /jobs/{id} before the GC sweep deletes it. Non-positive disables
	// the sweep, like CAIRNMARK_IDEMPOTENCY_TTL.
	Retention time.Duration
}

Jobs configures the extraction-job worker (internal/jobs) and the retention of finished jobs. One global knob each — no per-job, per-archive or per-caller policy.

type Postgres

type Postgres struct {
	DSN string // pgx connection string / URL
}

Postgres holds the metadata database connection settings.

type Storage

type Storage struct {
	Endpoint       string // host:port for service-side I/O, no scheme
	PublicEndpoint string // host:port clients are redirected to; defaults to Endpoint
	Region         string
	AccessKey      string
	SecretKey      string
	Bucket         string
	UseSSL         bool // TLS for the service-side endpoint
	PublicUseSSL   bool // TLS scheme for presigned URLs; defaults to UseSSL
}

Storage holds the S3-compatible backend settings.

Endpoint is where the service performs all object I/O (often an internal network name like "minio:9000"). PublicEndpoint is the host baked into presigned URLs handed back to clients; it defaults to Endpoint and only differs when external callers reach the store by a different name than the service does. The host is part of the SigV4 signature, so presigned URLs are signed against PublicEndpoint directly — the host cannot be rewritten after.

Jump to

Keyboard shortcuts

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