config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package config loads Astrate's single TOML configuration file with ASTRATE_* environment overrides (docs/DESIGN.md §5.1, ROADMAP §9 file 8.1). Precedence is default < TOML < environment. Zero-config defaults target the single-VPS case: only a database DSN and (outside dev mode) the broker's TLS identity must be supplied. The master encryption key is referenced here but read by internal/store (env or file), never inlined.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	HTTP         HTTPConfig         `toml:"http"`
	MQTT         MQTTConfig         `toml:"mqtt"`
	Database     DatabaseConfig     `toml:"database"`
	Engine       EngineConfig       `toml:"engine"`
	Pairing      PairingConfig      `toml:"pairing"`
	Housekeeping HousekeepingConfig `toml:"housekeeping"`
	Storage      StorageConfig      `toml:"storage"`
	Security     SecurityConfig     `toml:"security"`
	Realm        RealmConfig        `toml:"realm"`
	Log          LogConfig          `toml:"log"`
}

Config is the whole Astrate configuration.

func Default

func Default() Config

Default returns the zero-config defaults (single-VPS, dev-friendly).

func Load

func Load(path string) (Config, error)

Load reads the config: defaults, then the TOML file at path (skipped when path is empty — env-only operation), then ASTRATE_* env overrides, then validation. The returned Config is ready to wire.

func (*Config) HousekeepingKeys

func (c *Config) HousekeepingKeys() ([]string, error)

HousekeepingKeys resolves the instance-admin JWT public keys, reading any referenced files and appending them to the inline blocks.

func (*Config) RealmJWTPublicKey

func (c *Config) RealmJWTPublicKey() (string, error)

RealmJWTPublicKey resolves the auto-provision realm's JWT public key, preferring the inline block over the file reference.

type DatabaseConfig

type DatabaseConfig struct {
	DSN string `toml:"dsn"`
}

DatabaseConfig is the PostgreSQL/TimescaleDB connection.

type Duration

type Duration time.Duration

Duration is a time.Duration that (un)marshals as a Go duration string ("50ms", "720h") in TOML — time.Duration itself is not a TextUnmarshaler.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText renders the duration as a Go duration string.

func (Duration) Std

func (d Duration) Std() time.Duration

Std returns the underlying time.Duration.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

UnmarshalText parses a Go duration string.

type EngineConfig

type EngineConfig struct {
	Shards          int      `toml:"shards"`
	ShardQueue      int      `toml:"shard_queue"`
	BatchMaxRows    int      `toml:"batch_max_rows"`
	BatchMaxWait    Duration `toml:"batch_max_wait"`
	MaxPayloadBytes int      `toml:"max_payload_bytes"`
}

EngineConfig tunes the ingestion pipeline (§1.4).

type HTTPConfig

type HTTPConfig struct {
	Addr        string `toml:"addr"`
	TLSCertFile string `toml:"tls_cert_file"`
	TLSKeyFile  string `toml:"tls_key_file"`
}

HTTPConfig is the single REST listener (§3.7). TLS is optional: leave the files empty to serve plaintext behind a TLS-terminating reverse proxy.

type HousekeepingConfig

type HousekeepingConfig struct {
	JWTPublicKeys     []string `toml:"jwt_public_keys"`
	JWTPublicKeyFiles []string `toml:"jwt_public_key_files"`
}

HousekeepingConfig carries the instance-admin JWT public keys (a_ha): either inline PEM blocks or file references; both are concatenated.

type LogConfig

type LogConfig struct {
	Level  string `toml:"level"`
	Format string `toml:"format"`
}

LogConfig configures the slog handler (§5.2).

type MQTTConfig

type MQTTConfig struct {
	Addr             string `toml:"addr"`
	TLSCertFile      string `toml:"tls_cert_file"`
	TLSKeyFile       string `toml:"tls_key_file"`
	InsecureDevMode  bool   `toml:"insecure_dev_mode"`
	DevAddr          string `toml:"dev_addr"`
	SessionStorePath string `toml:"session_store_path"`
	// AdvertisedURL is the broker URL handed to devices by the pairing info
	// endpoint. Empty derives "mqtts://<Addr>" (fine for localhost; set it
	// explicitly when devices reach the broker by a different host).
	AdvertisedURL  string `toml:"advertised_url"`
	MaxPacketBytes uint32 `toml:"max_packet_bytes"`
}

MQTTConfig is the embedded broker (§3.1).

type PairingConfig

type PairingConfig struct {
	CertTTL           Duration `toml:"cert_ttl"`
	EnforceLatestCert bool     `toml:"enforce_latest_cert"`
	RegisterRate      float64  `toml:"register_rate"`
	RegisterBurst     int      `toml:"register_burst"`
	CredentialsRate   float64  `toml:"credentials_rate"`
	CredentialsBurst  int      `toml:"credentials_burst"`
	BcryptCost        int      `toml:"bcrypt_cost"`
}

PairingConfig tunes credential issuance and its rate limits (§4.3, §4.5).

type RealmConfig

type RealmConfig struct {
	Name                    string `toml:"name"`
	JWTPublicKey            string `toml:"jwt_public_key"`
	JWTPublicKeyFile        string `toml:"jwt_public_key_file"`
	DeviceRegistrationLimit *int32 `toml:"device_registration_limit"`
}

RealmConfig optionally auto-provisions a realm on boot (§5.1). Name empty disables it; when set, JWTPublicKey (PEM) is required.

type SecurityConfig

type SecurityConfig struct {
	MasterKeyFile string `toml:"master_key_file"`
}

SecurityConfig references the master encryption key that seals realm CA private keys (§4.3). When MasterKeyFile is empty, the store falls back to ASTRATE_MASTER_KEY / ASTRATE_MASTER_KEY_FILE.

type StorageConfig

type StorageConfig struct {
	Retention Duration `toml:"retention"`
}

StorageConfig holds runtime storage policy. Retention applies a global TimescaleDB drop-chunks policy; zero (the default) disables it, leaving per-endpoint TTL (§2.5) as the only expiry.

Jump to

Keyboard shortcuts

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