config

package
v0.2.0-rc.2 Latest Latest
Warning

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

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

Documentation

Overview

Package config persists non-secret CLI configuration and resolves the API URL via a deterministic layered priority chain.

Resolution order for the API URL (highest priority first):

  1. --api-url flag
  2. DBGORILLA_API_URL env var
  3. $XDG_CONFIG_HOME/dbgorilla/cli.toml (per-user; defaults to ~/.config/dbgorilla/cli.toml when XDG_CONFIG_HOME is unset)
  4. /etc/dbgorilla/cli.toml (system-wide; macOS uses /Library/Application Support/dbgorilla/cli.toml)
  5. (no default; caller surfaces a helpful error pointing at `dbg config`)

The user-config location follows the XDG Base Directory spec rather than a proprietary dotfile dir. Dotfile-walking credential stealers find both anyway, and XDG alignment lets backup/sync tooling treat dbg like every other modern CLI.

On-prem deployments don't share a single canonical URL, so we deliberately do not bake one in. The install script (scripts/install.sh.tmpl) writes the user-level config file at install time so the dev never has to type the URL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir() (string, error)

Dir returns the per-user config directory (XDG-aware), creating it if needed. On Unix-like systems this is $XDG_CONFIG_HOME/dbgorilla, defaulting to ~/.config/dbgorilla. On Windows it's whatever os.UserConfigDir returns (typically %AppData%\dbgorilla).

func ResolveInsecure

func ResolveInsecure(flagValue, flagSet bool) bool

ResolveInsecure returns whether TLS verification should be skipped.

If the --insecure flag was explicitly set on the command line, that wins (including --insecure=false to deliberately override a persisted true). Otherwise falls back to user-config api.insecure, then system-config. flagSet should come from cmd.Flags().Changed("insecure").

func SystemConfigPath

func SystemConfigPath() string

SystemConfigPath returns the OS-appropriate system-wide config path used by MDM-deployed configurations. This file is read-only from the CLI's point of view; we never write it.

func UserConfigPath

func UserConfigPath() (string, error)

UserConfigPath returns the per-user config file path.

Types

type APIConfig

type APIConfig struct {
	URL string `toml:"url,omitempty"`
	// Insecure mirrors the --insecure flag. Persisted on login when the
	// flag was used so the user doesn't have to pass it on every call
	// against an on-prem deployment with a private CA.
	Insecure bool `toml:"insecure,omitempty"`
}

type Config

type Config struct {
	API APIConfig `toml:"api"`
}

Config is the persisted CLI configuration.

func LoadSystem

func LoadSystem() (*Config, error)

LoadSystem reads the system-wide config. A missing file returns a zero-value Config and nil error -- system config is optional.

func LoadUser

func LoadUser() (*Config, error)

LoadUser reads the per-user config. A missing file returns a zero-value Config and nil error.

func (*Config) SaveUser

func (c *Config) SaveUser() error

SaveUser writes the per-user config atomically. The write goes to a tempfile + rename, with the tempfile created via OpenFile so the mode (0600) is enforced even if the destination already exists with weaker permissions (which os.WriteFile would otherwise preserve).

type ResolvedSource

type ResolvedSource string

ResolvedSource describes where the resolved API URL came from. Useful for `dbg config get api-url` so users can see exactly which layer won.

const (
	SourceFlag   ResolvedSource = "flag"
	SourceEnv    ResolvedSource = "env"
	SourceUser   ResolvedSource = "user-config"
	SourceSystem ResolvedSource = "system-config"
	SourceNone   ResolvedSource = "none"
)

func ResolveAPIURL

func ResolveAPIURL(flagValue string) (string, ResolvedSource)

ResolveAPIURL returns the API URL using the documented layered priority. Returns the URL plus the source it came from. Empty URL + SourceNone means nothing is configured and the caller should error with a helpful message.

Jump to

Keyboard shortcuts

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