config

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 16 Imported by: 0

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

View Source
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

func EnsureDefaultConfig() (bool, error)

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

func SetAPIKey(key string) error

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.

Types

type Config

type Config struct {
	APIURL      string `koanf:"api_url"`
	APIKey      string `koanf:"api_key"`
	Team        string `koanf:"team"`
	KeyringURL  string `koanf:"keyring_url"`
	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"`
}

Config holds the resolved configuration for the CLI.

func Load

func Load(configPath string, flags *pflag.FlagSet) (*Config, error)

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.

func (Config) Timeout

func (c Config) Timeout() time.Duration

Timeout parses the HTTPTimeout string as a Go duration. A zero or negative parsed value (which http.Client treats as "no timeout") is rejected in favour of the 10-second default — Load validates this up front, so reaching the fallback here means the config bypassed Load.

func (*Config) ToTOML

func (c *Config) ToTOML(maskAPIKey bool) string

ToTOML renders the config as a TOML string suitable for display. If the API key is set, it is masked.

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 VerifyConfig

type VerifyConfig struct {
	Silent         bool `koanf:"silent"`
	JSON           bool `koanf:"json"`
	SkipExternal   bool `koanf:"skip_external"`
	SkipSignatures bool `koanf:"skip_signatures"`
	Remote         bool `koanf:"remote"`
}

VerifyConfig holds verify-subcommand-specific configuration.

Jump to

Keyboard shortcuts

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