config

package
v0.1.1-beta Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns the default config file path. Prefers the XDG-compliant ~/.config/band/config.json, but falls back to the legacy ~/.band/config.json if it exists and the new path doesn't (auto-migration).

func Save

func Save(path string, cfg *Config) error

Save writes cfg as JSON to path, creating parent directories as needed. Directories are created with 0700 permissions; the file is written with 0600.

Types

type Config

type Config struct {
	// Active profile name
	ActiveProfile string `json:"active_profile,omitempty"`

	// Named profiles (keyed by profile name)
	Profiles map[string]*Profile `json:"profiles,omitempty"`

	// Global settings
	Format string `json:"format,omitempty"`

	// Legacy fields — kept for backward compatibility during migration.
	// If present and Profiles is empty, auto-migrate to a "default" profile.
	ClientID    string   `json:"client_id,omitempty"`
	AccountID   string   `json:"account_id,omitempty"`
	Accounts    []string `json:"accounts,omitempty"`
	Environment string   `json:"environment,omitempty"`
}

Config holds the CLI configuration values persisted to ~/.band/config.json.

func Load

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

Load reads config from path and returns defaults if the file does not exist. The default format is "json". BW_* env overlays are applied at read time by ActiveProfileConfig, never mutated into stored fields here — otherwise a later Save would persist the session value onto disk.

func (*Config) ActiveProfileConfig

func (c *Config) ActiveProfileConfig() *Profile

ActiveProfileConfig returns the active profile with BW_* env overlays applied. The returned *Profile is always a fresh copy — mutating it does not affect stored profiles, so writers (Load → Save flows) cannot accidentally leak session env values onto disk.

func (*Config) HasMultipleEnvironments

func (c *Config) HasMultipleEnvironments() bool

HasMultipleEnvironments reports whether the configured profiles span more than one distinct environment. This is used to decide whether to surface the active environment in CLI output — a customer with only prod credentials doesn't need to see "Environment: production" on every command.

func (*Config) ProfileNames

func (c *Config) ProfileNames() []string

ProfileNames returns sorted profile names.

func (*Config) SetProfile

func (c *Config) SetProfile(name string, p *Profile)

SetProfile stores a profile and sets it as active.

type Profile

type Profile struct {
	ClientID    string   `json:"client_id,omitempty"`
	AccountID   string   `json:"account_id,omitempty"`
	Accounts    []string `json:"accounts,omitempty"`
	Environment string   `json:"environment,omitempty"` // prod, test

	// Roles lists the JWT-granted role names on this credential. Used to
	// gate commands locally and produce capability hints in `auth status`.
	Roles []string `json:"roles,omitempty"`

	// Build is true when the credential is for a Bandwidth Build account
	// (voice-only, credit-based).
	Build bool `json:"build,omitempty"`
}

Profile holds credentials and account info for a single set of API credentials.

Jump to

Keyboard shortcuts

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