config

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config loads and saves the CLI's configuration: named contexts in config.yaml (shareable) and secrets in credentials.yaml (0600), both under $XDG_CONFIG_HOME/webtor (~/.config/webtor by default). The WEBTOR_* env vars override everything, so CI can run without any files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CredentialSource added in v1.1.0

func CredentialSource(name string, fileCreds Credentials) string

CredentialSource reports where a context's secrets currently live: "keyring", "file", or "" when nothing is stored.

func Dir

func Dir() string

Dir returns the configuration directory.

func Exists

func Exists() bool

Exists reports whether a config file is present.

func ExpandHome added in v1.5.0

func ExpandHome(p string) string

ExpandHome resolves a leading ~ to the home directory.

func Load

func Load() (*Config, Credentials, error)

Load reads config.yaml and credentials.yaml. A missing config is an error; missing credentials are not (an empty set is returned).

func Save

func Save(cfg *Config, creds Credentials) error

Save writes both files, creating the directory as needed. credentials.yaml is written 0600 — it holds keys.

func SetCredentials

func SetCredentials(name string, c ContextCredentials) error

SetCredentials stores one context's secrets: in the OS keyring when available (scrubbing any legacy file entry so the plaintext copy does not linger), in credentials.yaml otherwise. Empty credentials delete the entry everywhere.

Types

type BackendName

type BackendName string

BackendName is the config-file spelling of a backend kind.

const (
	BackendWebUI    BackendName = "webui"
	BackendRapidAPI BackendName = "rapidapi"
	BackendDirect   BackendName = "direct"
)

type Config

type Config struct {
	Current  string             `yaml:"current"`
	Contexts map[string]Context `yaml:"contexts"`
	// DownloadDir is where downloads land when -o is not given; empty means
	// the current directory.
	DownloadDir string `yaml:"download_dir,omitempty"`
}

Config is config.yaml: the contexts and which one is current.

type Context

type Context struct {
	Backend BackendName `yaml:"backend"`
	// BaseURL overrides the backend's default endpoint. Required for direct.
	BaseURL string `yaml:"base_url,omitempty"`
}

Context is one named backend configuration.

type ContextCredentials

type ContextCredentials struct {
	// APIKey is the web-ui API key, the RapidAPI key, or direct's
	// pass-through api-key, depending on the context's backend.
	APIKey string `yaml:"api_key,omitempty" json:"api_key,omitempty"`
	// Token is direct's pass-through JWT.
	Token string `yaml:"token,omitempty" json:"token,omitempty"`
}

ContextCredentials are the secrets of one context. The json tags fix the keyring entry's wire format; the yaml tags fix credentials.yaml's.

type Credentials

type Credentials map[string]*ContextCredentials

Credentials is credentials.yaml: per-context secrets, kept out of the shareable config file.

type Resolved

type Resolved struct {
	Name    string
	Context Context
	Creds   ContextCredentials
	// DownloadDir is the default output directory (empty = current dir),
	// with ~ already expanded.
	DownloadDir string
	// FromEnv marks the config-less WEBTOR_BACKEND mode: nothing is stored
	// on disk for this configuration.
	FromEnv bool
}

Resolved is a fully resolved runtime configuration: the chosen context plus its secrets, after env overrides.

func Resolve

func Resolve(contextFlag string) (*Resolved, error)

Resolve picks the runtime configuration: when WEBTOR_BACKEND is set, the WEBTOR_* env vars fully describe it and no files are needed (config-less CI mode); otherwise the named context (flag > config current) is loaded from the files, and env vars are ignored.

func (*Resolved) Backend

func (r *Resolved) Backend() (webtor.Backend, error)

Backend constructs the SDK backend for the resolved configuration.

Jump to

Keyboard shortcuts

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