Files
anchorage/internal/pkg/config/defaults.go
William Gill 12bf35caf8 anchorage v1.0 initial tree
Greenfield Go multi-tenant IPFS Pinning Service wire-compatible with the
IPFS Pinning Services API spec. Paired 1:1 with Kubo over localhost RPC,
clustered via embedded NATS JetStream, Postgres source-of-truth with
RLS-enforced tenancy, Fiber + huma v2 for the HTTP surface, Authentik
OIDC for session login with kid-rotated HS256 JWT API tokens.

Feature-complete against the 22-milestone build plan, including the
ship-it v1.0 gap items:

  * admin CLIs: drain/uncordon, maintenance, mint-token, rotate-key,
    prune-denylist, rebalance --dry-run, cache-stats, cluster-presences
  * TTL leader election via NATS KV, fence tokens, JetStream dedup
  * rebalancer (plan/apply split), reconciler, requeue sweeper
  * ristretto caches with NATS-backed cross-node invalidation
    (placements live-nodes + token denylist)
  * maintenance watchdog for stuck cluster-pause flag
  * Prometheus /metrics with CIDR ACL, HTTP/pin/scheduler/cache gauges
  * rate limiting: session (10/min) + anonymous global (120/min)
  * integration tests: rebalance, refcount multi-org, RLS belt
  * goreleaser (tar + deb/rpm/apk + Alpine Docker) targeting Gitea

Stack: Cobra/Viper, Fiber v2 + huma v2, embedded NATS JetStream,
pgx/sqlc/golang-migrate, ristretto, TypeID, prometheus/client_golang,
testcontainers-go.
2026-04-16 18:13:36 -05:00

71 lines
2.7 KiB
Go

package config
import "github.com/spf13/viper"
// setDefaults applies the baked-in defaults. Keep in lockstep with
// configs/anchorage.example.yaml — the example file should never document
// a value that differs silently from these defaults.
func setDefaults(v *viper.Viper) {
// Server
v.SetDefault("server.host", "0.0.0.0")
v.SetDefault("server.port", 8080)
v.SetDefault("server.readTimeout", "10s")
v.SetDefault("server.writeTimeout", "30s")
// server.metrics.allowCIDRs intentionally has NO default set via Viper —
// nil is how we signal "fall through to metrics.DefaultAllowCIDRs".
// Explicit `[]` in YAML → operator-chosen allow-all.
v.SetDefault("server.rateLimit.sessionPerMinute", 10)
v.SetDefault("server.rateLimit.anonymousPerMinute", 120)
// Node — id falls back to OS hostname in applyHostnameFallback.
v.SetDefault("node.multiaddrs", []string{})
v.SetDefault("node.stateDir", "/var/lib/anchorage")
// IPFS (local paired Kubo)
v.SetDefault("ipfs.rpc", "http://localhost:5001")
v.SetDefault("ipfs.timeout", "2m")
v.SetDefault("ipfs.reconciler.interval", "10m")
v.SetDefault("ipfs.reconciler.autoRepair", false)
// Cluster — safe single-node defaults; operators bump minReplicas in HA.
v.SetDefault("cluster.minReplicas", 1)
v.SetDefault("cluster.heartbeatInterval", "5s")
v.SetDefault("cluster.downAfter", "30s")
v.SetDefault("cluster.rebalanceInterval", "1m")
v.SetDefault("cluster.autoRepair", false)
v.SetDefault("cluster.drainGracePeriod", "2m")
v.SetDefault("cluster.maintenance.maxDuration", "1h")
// Postgres
v.SetDefault("postgres.maxConns", 20)
v.SetDefault("postgres.autoMigrate", true)
v.SetDefault("postgres.requeueSweeper", "30s")
// NATS
v.SetDefault("nats.client.host", "0.0.0.0")
v.SetDefault("nats.client.port", 4222)
v.SetDefault("nats.cluster.name", "anchorage")
v.SetDefault("nats.cluster.host", "0.0.0.0")
v.SetDefault("nats.cluster.port", 6222)
v.SetDefault("nats.cluster.routes", []string{})
v.SetDefault("nats.jetstream.replicas", 3)
// Auth — TTLs only; keys/issuers must be provided by the operator.
//
// defaultTTL is for interactive / web-session tokens (short).
// maxTTL = 395 days (1 year + 30-day grace) accommodates IPFS
// client tokens issued to long-lived CLI / CI / service identities
// — see `anchorage admin mint-token` for the break-glass path.
v.SetDefault("auth.apiToken.defaultTTL", "24h")
v.SetDefault("auth.apiToken.maxTTL", "9480h")
// Logging — text to stderr by default; file is opt-in.
v.SetDefault("logging.level", "info")
v.SetDefault("logging.format", "text")
v.SetDefault("logging.source", false)
v.SetDefault("logging.maxSizeMB", 100)
v.SetDefault("logging.maxBackups", 10)
v.SetDefault("logging.maxAgeDays", 30)
v.SetDefault("logging.compress", true)
}