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 ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultTOML string
Functions ¶
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 config file.
func EnsureDefaultConfig ¶
EnsureDefaultConfig creates the config directory and writes the default config.toml if it does not already exist. Returns true if the file was created.
func SetAPIKey ¶ added in v0.4.0
SetAPIKey writes key as the top-level api_key value in the user's config file, 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 SetTeam ¶ added in v0.8.0
SetTeam writes id as the top-level team value in the user's config file, 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"`
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.