Documentation
¶
Overview ¶
Package config loads runtime configuration from a JSON file, with environment variables taking precedence. Currently it carries the PostgreSQL connection.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdoptLegacyDataDir ¶ added in v0.4.2
AdoptLegacyDataDir moves a pre-rename `data` directory to the new `data-redteam` default when the latter does not exist yet, so an in-place upgrade keeps the JWT key, traffic index and workspaces. It returns the directory to use and, when a migration happened, the old path ("" otherwise). If the rename fails it keeps using the old directory rather than starting with an empty one.
func BaseDir ¶
func BaseDir() string
BaseDir is the directory that anchors all runtime artifacts (config.json and the data/ store). It is the directory the running binary lives in, so a distributed executable keeps its files next to itself on any OS (Windows, Linux, …) regardless of the working directory it is launched from.
When launched via `go run`, the binary is throwaway: it sits either in a temp build dir (cache miss → fresh link) OR straight inside the Go build cache (cache hit → run from $GOCACHE/.../...-d). We detect both and fall back to the current working directory so dev artifacts (data/, transcripts) and config resolve against the project dir, not the throwaway binary's location.
func DefaultDataDir ¶ added in v0.4.2
func DefaultDataDir() string
DefaultDataDir is the runtime data directory that sits next to the executable.
func Env ¶ added in v0.4.2
Env returns the value of ARTEX_REDTEAM_<suffix>, falling back to the legacy ARTEX_<suffix> name. The ARTEX → ARTEX-RedTeam rename must not break existing deployments, so the new name wins and the old one keeps working.
func Path ¶
func Path() string
Path returns the config file path. Resolution order:
- env ARTEX_REDTEAM_CONFIG (legacy ARTEX_CONFIG also accepted)
- ./config.json in the current working directory (running from the project dir — robust no matter where `go run` placed the temp/cached binary)
- config.json next to the executable (a distributed binary keeps it beside)
The first existing file wins. If none exist, the CWD path is returned so the "not found" message points at the project dir the user most likely expected.
func PostgresDSN ¶
PostgresDSN resolves the connection string with precedence:
env ARTEX_REDTEAM_PG_DSN (legacy ARTEX_PG_DSN) > config file (database.dsn, or assembled from fields)
There is NO built-in fallback: when neither source supplies a database config, it returns an error naming the config path it inspected, so startup fails loudly instead of silently connecting to a wrong default. source describes where the DSN came from (for startup logging).
Types ¶
type Database ¶
type Database struct {
DSN string `json:"dsn"`
Host string `json:"host"`
Port int `json:"port"`
User string `json:"user"`
Password string `json:"password"`
DBName string `json:"dbname"`
SSLMode string `json:"sslmode"`
}
Database is the PostgreSQL connection config. Either set DSN directly, or set the component fields and a DSN is assembled from them.