config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config handles loading, saving, and resolving configuration values for the melange CLI. Credential resolution follows this order: environment > environment file > explicitly selected config storage > keyring > legacy config fallback.

Index

Constants

View Source
const (
	EnvHost       = "MELANGE_HOST"
	EnvAPIKey     = "MELANGE_API_KEY"
	EnvAPIKeyFile = "MELANGE_API_KEY_FILE"

	DefaultHost = "https://api.zetic.ai"

	// CredentialStorageConfig marks a host whose token was explicitly stored
	// in the mode-0600 config file after the user opted into
	// --insecure-storage. Resolution skips the unavailable keyring only for
	// this explicit per-host selection.
	CredentialStorageConfig = "config"
)

Env variable names — centralized so callers don't hard-code strings.

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() string

ConfigDir returns the platform-appropriate directory for the config file.

  • Linux/macOS: ${XDG_CONFIG_HOME:-$HOME/.config}/melange
  • Windows: %AppData%\melange

func Save

func Save(cfg *Config) error

Save saves the config to the default config path (0600 file, 0755 dir).

func SaveTo

func SaveTo(cfg *Config, path string) error

SaveTo saves the config to the specified path.

Types

type Config

type Config struct {
	Host        string               `yaml:"host"`
	DefaultRepo string               `yaml:"default_repo"`
	Hosts       map[string]HostEntry `yaml:"hosts"`
}

Config is the top-level config file schema.

func Load

func Load() (*Config, error)

Load loads the config from the default config path. A missing file is not an error — it returns an empty Config. A corrupted YAML file returns an error.

func LoadFrom

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

LoadFrom loads config from the specified path. A missing file returns an empty Config without error.

func (*Config) DeleteHostAPIKey

func (c *Config) DeleteHostAPIKey(host string) error

DeleteHostAPIKey removes the API key for host from the config file and saves it. Removing an absent host is not an error.

func (*Config) ResolveHost

func (c *Config) ResolveHost(flagValue string) Resolved

ResolveHost returns the API host following the precedence chain:

flag > env:MELANGE_HOST > config.host > default

func (*Config) ResolveToken

func (c *Config) ResolveToken(host string) (Resolved, error)

ResolveToken returns the API token for the given host without consulting a keyring. Call ResolveTokenWith for the full CLI credential resolution path. A set-but-unreadable MELANGE_API_KEY_FILE is a hard error.

func (*Config) ResolveTokenWith

func (c *Config) ResolveTokenWith(host string, lookup func(host string) (string, bool, error)) (Resolved, error)

ResolveTokenWith is ResolveToken with an injected keyring lookup (nil = no keyring). The lookup is a plain func so this package does not import internal/keyring; commands pass keyring.Lookup. Precedence:

env:MELANGE_API_KEY > env:MELANGE_API_KEY_FILE > explicitly selected
config storage > keyring > legacy config > empty

A keyring lookup failure remains a hard error unless this host explicitly selected config storage. This prevents an unavailable keyring from silently switching credentials.

func (*Config) SetHostAPIKey

func (c *Config) SetHostAPIKey(host, key string) error

SetHostAPIKey stores an API key for host in the config file and saves it.

type HostEntry

type HostEntry struct {
	APIKey  string `yaml:"api_key"`
	Storage string `yaml:"storage,omitempty"`
}

HostEntry holds per-host credentials.

type Resolved

type Resolved struct {
	Value  string
	Source string
}

Resolved is a value together with its source label.

Jump to

Keyboard shortcuts

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