Documentation
¶
Overview ¶
Package config resolves the CLI's runtime configuration from compiled defaults, an optional TOML config file, environment variables, and command-line flags — in that order, with later sources overriding earlier ones.
Index ¶
- Variables
- func ActivePath() string
- func ConfigDir() string
- func ConfigFilePath() string
- func EnsureDefaultConfig() (bool, error)
- func SetAPIKey(key string) error
- func SetActivePath(path string)
- func SetTeam(id string) error
- type Config
- type ConvertConfig
- type HashConfig
- type LoggingConfig
- type VerifyConfig
Constants ¶
This section is empty.
Variables ¶
var DefaultTOML string
Functions ¶
func ActivePath ¶ added in v0.12.0
func ActivePath() string
ActivePath returns the config file actually in effect: the --config override when one was supplied, otherwise the platform default.
It is correct even when Load was never called — some commands and tests reach display/persistence sites before (or without) loading the config, and they must not silently target a different file than the one that was read.
func ConfigDir ¶
func ConfigDir() string
ConfigDir returns the config directory path. The implementation is split across config_unix.go and config_windows.go via build tags so each platform's branch is exercised — and scored for coverage — only on the platform where it can actually run.
func ConfigFilePath ¶
func ConfigFilePath() string
ConfigFilePath returns the full path to the PLATFORM DEFAULT config file — the location used when the user did not pass --config. It deliberately ignores any override so cmd/root.go can render it as the documented default in the --config flag's help text (built at init() time, long before any config is loaded).
Callers asking "which file is actually in effect right now?" want ActivePath instead.
func EnsureDefaultConfig ¶
EnsureDefaultConfig creates the directory of the config file in effect and writes the default config.toml there if it does not already exist. Returns true if the file was created.
The path comes from ActivePath, not ConfigFilePath, so a --config override creates (and is subsequently written to) the file the user actually named.
func SetAPIKey ¶ added in v0.4.0
SetAPIKey writes key as the top-level api_key value in the config file in effect (ActivePath — the --config override when one was given, otherwise the platform default), preserving comments and other settings. Creates the file from the embedded default if it does not yet exist, and tightens permissions to 0600 because the file now contains a secret.
func SetActivePath ¶ added in v0.12.0
func SetActivePath(path string)
SetActivePath records path as the --config override in effect for the rest of the process. The empty string clears the override, restoring the platform default. Load calls this with the configPath it was given, so ordinary CLI flows never need to call it directly; it is exported for tests and for callers that resolve the path themselves.
This mirrors the package-global idiom already used by auth.SetDefault and httpclient.SetTransport.
func SetTeam ¶ added in v0.8.0
SetTeam writes id as the top-level team value in the config file in effect (ActivePath — the --config override when one was given, otherwise the platform default), preserving comments and other settings. Creates the file from the embedded default if it does not yet exist. Permissions are kept at 0600 to match SetAPIKey — the file co-exists with the api_key secret, so a less-tight regime would only loosen security on the shared file.
Types ¶
type Config ¶
type Config struct {
// BaseURL is the user-configurable origin (scheme + host + port)
// for all Truestamp services. Default https://www.truestamp.com.
// Settable via base_url in config.toml, TRUESTAMP_BASE_URL env,
// or --base-url flag.
BaseURL string `koanf:"base_url"`
// Computed from BaseURL during Load — not user-settable.
APIURL string `koanf:"-"`
KeyringURL string `koanf:"-"`
WebSocketURL string `koanf:"-"`
HealthURL string `koanf:"-"`
APIKey string `koanf:"api_key"`
// APIKeyExplicit is true when api_key came from an intentional
// override — the --api-key flag or the TRUESTAMP_API_KEY env var —
// rather than the config file. An explicit key wins over a stored
// OAuth session so CI/headless behavior stays deterministic. Computed
// during Load; not user-settable.
APIKeyExplicit bool `koanf:"-"`
Team string `koanf:"team"`
HTTPTimeout string `koanf:"http_timeout"`
// CosignPath pins the cosign binary used during `truestamp upgrade`.
// Must be an absolute path to an executable when set; empty means
// fall back to $PATH lookup. Settable in config.toml as
// `cosign_path = "..."` or via the TRUESTAMP_COSIGN_PATH env var.
CosignPath string `koanf:"cosign_path"`
Verify VerifyConfig `koanf:"verify"`
Hash HashConfig `koanf:"hash"`
Convert ConvertConfig `koanf:"convert"`
Logging LoggingConfig `koanf:"logging"`
}
Config holds the resolved configuration for the CLI.
All Truestamp service URLs derive from a single BaseURL — the JSON API, keyring, console WebSocket, and health endpoint paths are fixed by the server and computed from BaseURL during Load. Callers that need a specific URL read the corresponding field directly (cfg.APIURL, cfg.KeyringURL, etc.); they should not be re-derived from BaseURL ad hoc, so the path layout stays in one place.
func Load ¶
Load reads configuration in priority order: defaults → config file → env → CLI flags. configPath overrides the default config file location if non-empty. flags should be the merged flag set from the executed command (rootFlags for persistent, cmdFlags for command-specific). Only flags that were explicitly set by the user override.
type ConvertConfig ¶ added in v0.5.0
type ConvertConfig struct {
TimeZone string `koanf:"time_zone"`
}
ConvertConfig holds convert-subcommand-specific configuration.
type HashConfig ¶ added in v0.5.0
type HashConfig struct {
Algorithm string `koanf:"algorithm"`
Encoding string `koanf:"encoding"`
Style string `koanf:"style"`
}
HashConfig holds hash-subcommand-specific configuration.
type LoggingConfig ¶ added in v0.8.0
type LoggingConfig struct {
// File overrides the platform-default log file path. Empty means
// fall back to logging.DefaultPath() (~/Library/Caches/truestamp/
// truestamp.log on macOS, ~/.cache/truestamp/truestamp.log on
// Linux, %LOCALAPPDATA%\truestamp\Cache\truestamp.log on Windows).
File string `koanf:"file"`
// Level filters output: "debug" | "info" | "warn" | "error".
// Empty defaults to "info".
Level string `koanf:"level"`
// MaxSizeMB is the lumberjack rotation threshold. 0 = library
// default (10 MB).
MaxSizeMB int `koanf:"max_size_mb"`
// MaxBackups is the count of rotated files retained. 0 = 5.
MaxBackups int `koanf:"max_backups"`
// MaxAgeDays is how long rotated files are kept. 0 = 14.
MaxAgeDays int `koanf:"max_age_days"`
}
LoggingConfig holds CLI-wide logging settings. The logger is constructed once at the cobra root and shared by every subcommand (one-shot tools and the long-lived console TUI) so a single rotated JSON file captures every invocation.