config

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package config handles YAML configuration stored under the XDG config directory. Secrets are NEVER written to the config file — only base_url, spec_path, output, and timeout.

Configuration loading and saving is backed by spf13/viper, matching the design document. Viper provides file + env + defaults cascade and YAML (de)serialization out of the box.

Index

Constants

View Source
const (
	DefaultOutput  = "json"
	DefaultTimeout = 30 * time.Second
)

Defaults applied when a value is missing.

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns the resolved config directory honoring XDG. Order: $XDG_CONFIG_HOME/invgate-cli, else $HOME/.config/invgate-cli.

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns the full path to config.yaml.

func DefaultSpecPath

func DefaultSpecPath() (string, error)

DefaultSpecPath returns the default location for a spec file under the config directory.

func RunSetup

func RunSetup(opts SetupOptions) error

RunSetup guides the user through configuring invgate-cli. In interactive mode it downloads the spec, then prompts for base URL, credentials, and output format. In non-interactive mode it validates that required flags are set. On completion it writes the config file and stores secrets in the keychain, then tests the connection.

Types

type Config

type Config struct {
	BaseURL  string        `yaml:"base_url"`
	SpecPath string        `yaml:"spec_path"`
	Output   string        `yaml:"output"`
	Timeout  time.Duration `yaml:"timeout"`
}

Config holds the non-secret CLI configuration persisted to disk.

func Load

func Load() (*Config, error)

Load reads the YAML config file (if it exists) and applies env var overrides via viper's automatic env lookup. Missing files are not errors — defaults are applied. Env vars always win over file values.

func LoadFromPath

func LoadFromPath(path string) (*Config, error)

LoadFromPath loads a config from an explicit path (used in tests). Env vars still override file values via viper's automatic env.

func (*Config) Save

func (c *Config) Save() error

Save writes the config to disk as YAML. Only non-secret fields are written. The config directory is created if it does not exist.

func (*Config) SaveToPath

func (c *Config) SaveToPath(path string) error

SaveToPath writes the config to an explicit path (used in tests).

type SetupFlags

type SetupFlags struct {
	BaseURL      string
	ClientID     string
	ClientSecret string
	Output       string
	TokenURL     string
	SpecURL      string
}

SetupFlags holds the non-interactive setup parameters. When all required fields are populated, no prompts are shown.

type SetupOptions

type SetupOptions struct {
	Interactive bool
	In          io.Reader
	Out         io.Writer
	Flags       SetupFlags
	Keyring     auth.Keyring
	HTTPClient  *http.Client
}

SetupOptions configures how RunSetup operates.

Jump to

Keyboard shortcuts

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