config

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package config reads the configuration of every command from environment variables into one typed Config, validated as a whole at startup so a command stops before doing anything with a value it cannot use (ADR 0002).

The variables, their defaults and an example are in .env.example. A secret, such as the log key, is held as a Secret: it never appears in a log line, an error message or a formatted Config.

Commands write only under Config.DataDir, the data volume, so the rest of the file system can be mounted read-only.

Index

Constants

View Source
const (
	EnvAddr     = "ARNAKOFF_ADDR"
	EnvLogLevel = "ARNAKOFF_LOG_LEVEL"
	EnvLogKey   = "ARNAKOFF_LOG_KEY"
	EnvDataDir  = "ARNAKOFF_DATA_DIR"

	EnvSourceACPR = "ARNAKOFF_SOURCE_ACPR"

	EnvAlertWebhook = "ARNAKOFF_ALERT_WEBHOOK"

	EnvProblemBaseURL = "ARNAKOFF_PROBLEM_BASE_URL"
)

Environment variables read by Load.

View Source
const (
	DefaultAddr     = ":8100"
	DefaultLogLevel = "info"
	DefaultDataDir  = "var"

	// DefaultSourceACPR keeps the ACPR blacklist off: its reuse licence is
	// still to be obtained (docs/sources.md).
	DefaultSourceACPR = "false"

	// DefaultProblemBaseURL is where arnakoff/web documents the problems
	// the API answers, one page per code.
	DefaultProblemBaseURL = "https://arnakoff.com/docs/erreurs/"
)

Defaults applied by Load to an unset variable. ARNAKOFF_LOG_KEY has none.

View Source
const MinLogKeyBytes = logging.MinKeyBytes

MinLogKeyBytes is the shortest log key Load accepts, once hex-decoded: the minimum of logging.New.

Variables

View Source
var ErrInvalid = errors.New("invalid configuration")

ErrInvalid means a variable holds a value Load cannot use.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Addr is the TCP address the HTTP API listens on, "host:port" with a
	// numeric port; an empty host means every interface.
	Addr string

	// LogLevel is the minimum level written to the log.
	LogLevel slog.Level

	// LogKey is the HMAC key that pseudonymises personal data in the log.
	LogKey Secret

	// DataDir is the only directory the commands write to: the data
	// volume. Every other path may be read-only.
	DataDir string

	// SourceACPR turns the ACPR blacklist on, once its reuse licence is
	// obtained.
	SourceACPR bool

	// AlertWebhook is the HTTPS URL a failed or rejected sync is posted
	// to; nil when unset or empty, and then alerts are only logged. It is a
	// Secret: a webhook URL usually carries its credential.
	AlertWebhook Secret

	// ProblemBaseURL is the HTTPS URL of the documentation of the API's
	// problems, ending with a slash: the type of a problem is its code
	// under it.
	ProblemBaseURL string
}

Config is the configuration of every command.

func Load

func Load(lookup func(string) (string, bool)) (Config, error)

Load reads the configuration with lookup, such as os.LookupEnv. A variable that is set, even to an empty string, is used as is; an unset one takes its default. It returns every invalid variable at once, each wrapping ErrInvalid; an error never quotes the value of a Secret.

func (Config) SnapshotDir

func (c Config) SnapshotDir() string

SnapshotDir is where the validated snapshots of the sources are stored, inside DataDir.

type Secret

type Secret []byte

Secret is a configuration value that must never reach a log, an error or a response. Every fmt verb, encoding/json and log/slog write it as "[redacted]"; only Bytes gives the value.

func (Secret) Bytes

func (s Secret) Bytes() []byte

Bytes returns a copy of the secret value.

func (Secret) Format

func (s Secret) Format(f fmt.State, _ rune)

Format implements fmt.Formatter: every verb writes "[redacted]".

func (Secret) LogValue

func (s Secret) LogValue() slog.Value

LogValue implements slog.LogValuer.

func (Secret) MarshalText

func (s Secret) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler, which encoding/json uses.

Jump to

Keyboard shortcuts

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