Documentation
¶
Overview ¶
Package config manages mistctl contexts: a named combination of Mist cloud, API token and default org/site, stored in a kubeconfig-style file.
Index ¶
Constants ¶
const DefaultCacheTTL = 10 * time.Minute
DefaultCacheTTL is used when cache-ttl is not set.
Variables ¶
var ErrChanged = errors.New("the config file was changed by another process; run the command again")
ErrChanged is returned by Save when the file changed on disk after it was loaded (another mistctl process saved it in the meantime).
Functions ¶
func DefaultPath ¶
DefaultPath returns the config path, honouring $MISTCTL_CONFIG.
Types ¶
type Config ¶
type Config struct {
CurrentContext string `yaml:"current-context,omitempty" json:"current-context,omitempty"`
Contexts map[string]*Context `yaml:"contexts,omitempty" json:"contexts,omitempty"`
// CacheTTL is how long cached name/ID indexes stay fresh, in Go duration
// syntax (default 10m).
CacheTTL string `yaml:"cache-ttl,omitempty" json:"cache-ttl,omitempty"`
// contains filtered or unexported fields
}
Config is the on-disk configuration.
func Load ¶
Load reads and validates the config at path. A missing file yields an empty config. Unknown keys, null contexts and an invalid cache-ttl are errors, so a typo never silently changes which org or token is used.
func (*Config) PermissionWarning ¶
PermissionWarning returns a message when the file holds a token and other users can read it (mistctl writes it 0600, a hand-made file may not be).
func (*Config) Save ¶
Save writes the config atomically with 0600 permissions, since it can hold tokens. It refuses to overwrite a file that changed since Load, so two concurrent commands cannot silently drop each other's update.
type Context ¶
type Context struct {
Cloud string `yaml:"cloud" json:"cloud"`
Token string `yaml:"token,omitempty" json:"token,omitempty"`
TokenEnv string `yaml:"token_env,omitempty" json:"token_env,omitempty"`
Org string `yaml:"org,omitempty" json:"org,omitempty"`
Site string `yaml:"site,omitempty" json:"site,omitempty"`
}
Context is one named target. The JSON tags match the YAML ones so that `config view -o json` uses the same field names as the file.
func (*Context) ResolveToken ¶
ResolveToken returns the token for a context, reading token_env if set.