Documentation
¶
Overview ¶
package config manages the local cli state: orchestrator contexts (base url + token) and the per-context active host. it is persisted to a yaml file under the user's config dir. it knows nothing about the api.
Index ¶
- Variables
- func DefaultPath() (string, error)
- type Config
- func (c *Config) Add(ctx Context)
- func (c *Config) Current(override string) (*Context, error)
- func (c *Config) Get(name string) (*Context, error)
- func (c *Config) Path() string
- func (c *Config) Remove(name string) error
- func (c *Config) Save() error
- func (c *Config) SetActiveHost(override, hostID string) error
- func (c *Config) Use(name string) error
- type Context
Constants ¶
This section is empty.
Variables ¶
var ErrNoContext = errors.New("no active context: run `fuse connect <url> --token <token>` first")
ErrNoContext is returned when an operation needs an active context but none is selected.
Functions ¶
func DefaultPath ¶
DefaultPath returns the config file path, honoring XDG_CONFIG_HOME and falling back to ~/.config/fuse/config.yaml.
Types ¶
type Config ¶
type Config struct {
CurrentContext string `yaml:"current_context,omitempty"`
Contexts []Context `yaml:"contexts,omitempty"`
// contains filtered or unexported fields
}
Config is the whole cli state.
func Load ¶
Load reads the config from path. if path is empty, DefaultPath is used. a missing file is not an error: an empty config (with path set) is returned so the caller can add a context and Save.
func (*Config) Current ¶
Current returns the active context. if name is non-empty it overrides the stored current context (used for a per-invocation --context flag).
func (*Config) Remove ¶
Remove deletes a context. if it was current, the current selection is cleared.
func (*Config) Save ¶
Save writes the config to its path with restrictive permissions (it holds tokens). the parent directory is created if needed.
func (*Config) SetActiveHost ¶
SetActiveHost records the selected host for the current context.
type Context ¶
type Context struct {
Name string `yaml:"name"`
// BaseURL is the orchestrator root (scheme://host:port), no /v1 suffix.
BaseURL string `yaml:"base_url"`
// Token is the bearer token. empty is allowed for dev/insecure mode.
Token string `yaml:"token,omitempty"`
// Master marks a context whose token is the master token (required for
// api-key commands). informational only; the server is the source of truth.
Master bool `yaml:"master,omitempty"`
// ActiveHost is the host id selected via `fuse host <id>`. it scopes the
// host-scoped commands for this context.
ActiveHost string `yaml:"active_host,omitempty"`
}
Context is a single orchestrator the cli can talk to. one orchestrator is one control plane (base url + bearer token). hosts live inside it.