config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthTypeAPIKey = "api_key"
	AuthTypeOAuth  = "oauth"
)

Auth type constants for Profile.AuthType.

Variables

This section is empty.

Functions

func DeleteProfile

func DeleteProfile(name string) error

DeleteProfile removes a profile file from disk.

func Dir

func Dir() (string, error)

Dir returns the configuration directory path (~/.config/promptvm/).

func MaskAPIKey

func MaskAPIKey(key string) string

MaskAPIKey returns a masked version of an API key for display.

func SaveProfile

func SaveProfile(p *Profile) error

SaveProfile writes a profile to disk atomically, with 0600 permissions on POSIX systems (best-effort on Windows).

Atomic write semantics: the YAML is written to a sibling .tmp file, fsync'd, and renamed over the destination. A partial profile file is never observable to a concurrent reader.

func ValidateProfileName

func ValidateProfileName(name string) error

ValidateProfileName rejects profile names that contain path separators, parent references, or other unsafe characters.

Types

type Config

type Config struct {
	ActiveProfile string   `yaml:"active_profile"`
	Defaults      Defaults `yaml:"defaults"`
}

Config represents the global CLI configuration.

func Load

func Load() (*Config, error)

Load reads the global config from disk. Returns defaults if the file doesn't exist.

func (*Config) ActiveProfileData

func (c *Config) ActiveProfileData() (*Profile, error)

ActiveProfileData loads the currently active profile.

func (*Config) AllSettings

func (c *Config) AllSettings() map[string]string

AllSettings returns all config keys and their values.

func (*Config) Get

func (c *Config) Get(key string) (string, error)

Get returns a config value by dot-notation key.

func (*Config) Save

func (c *Config) Save() error

Save writes the global config to disk.

func (*Config) Set

func (c *Config) Set(key, value string) error

Set updates a config value by dot-notation key.

func (*Config) SetActiveProfile

func (c *Config) SetActiveProfile(name string) error

SetActiveProfile updates the active profile name and saves.

type Defaults

type Defaults struct {
	Output    string `yaml:"output"`
	NoColor   bool   `yaml:"no_color"`
	Workspace string `yaml:"workspace,omitempty"`
}

Defaults holds default CLI settings.

type Profile

type Profile struct {
	Name         string `yaml:"name"`
	APIKey       string `yaml:"api_key,omitempty"`
	PublicKey    string `yaml:"public_key,omitempty"`
	SecretKey    string `yaml:"secret_key,omitempty"`
	BaseURL      string `yaml:"base_url"`
	Environment  string `yaml:"environment"`
	Organization string `yaml:"organization,omitempty"`

	// OAuth / SSO metadata. Empty for legacy API-key profiles.
	AuthType  string    `yaml:"auth_type,omitempty"`
	TokenRef  string    `yaml:"token_ref,omitempty"`
	ExpiresAt time.Time `yaml:"expires_at,omitempty"`
	UserID    string    `yaml:"user_id,omitempty"`
	UserEmail string    `yaml:"user_email,omitempty"`
}

Profile represents a named authentication profile.

Profiles support two authentication modes selected by AuthType:

  • "api_key" (legacy): the credential pair (PublicKey + SecretKey) is stored explicitly. The combined APIKey field is retained for backward compatibility with profiles written by older CLI builds.
  • "oauth" (SSO): no access/refresh tokens live in this file; tokens are stored in the OS keychain keyed by TokenRef. Only metadata (expiry, user id/email) is persisted here.

func ListProfiles

func ListProfiles() ([]*Profile, error)

ListProfiles returns all saved profiles.

func LoadProfile

func LoadProfile(name string) (*Profile, error)

LoadProfile reads a profile by name from disk. If the profile is in the legacy single-string `api_key: pk:sk` shape and there are no `public_key`/`secret_key` fields, LoadProfile transparently splits the credential and rewrites the file atomically with the dual-key fields populated.

A migration write failure (disk full, perms, read-only FS) is non-fatal: a warning is logged and the in-memory Profile carries the split values for the duration of the session. The next start retries.

func (*Profile) IsOAuth

func (p *Profile) IsOAuth() bool

IsOAuth reports whether the profile uses OAuth/SSO authentication.

Jump to

Keyboard shortcuts

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