Documentation ¶
Index ¶
- Constants
- Variables
- func Activate(name string) error
- func ActiveName() (string, error)
- func Configurations() (map[string]Configuration, error)
- func CreateFlagSet() *pflag.FlagSet
- func Delete(name string) error
- func ValidateName(name string) error
- type Configuration
- func (c Configuration) FlatMap() (map[string]interface{}, error)
- func (c *Configuration) FromMap(m map[string]interface{}) error
- func (c Configuration) Properties() []string
- func (c *Configuration) Resolve() error
- func (c *Configuration) Set(k string, v interface{}) error
- func (c *Configuration) Unset(k string) error
- func (c Configuration) Validate() error
- func (c Configuration) Write(name string) error
- type Registry
- type ValidationError
Constants ¶
const ActivePointerFilename = "active_config"
Variables ¶
var ( ErrNoActiveConfiguration = fmt.Errorf("No active configuration.") // Flags defines Flags that may be bound to a Configuration. Use like: // `cmd.PersistentFlags().AddFlagSet(connection.Flags)` Flags *pflag.FlagSet = CreateFlagSet() // Directory is $HOME/config/registry Directory string ErrCannotDeleteActive = fmt.Errorf("Cannot delete active configuration") ErrReservedConfigName = fmt.Errorf("%q is reserved", ActivePointerFilename) )
Functions ¶
func ActiveName ¶
Returns the active file from ~/.config/active_config. Returns "" if active_config is not found.
func Configurations ¶
func Configurations() (map[string]Configuration, error)
Configurations returns stored Configurations by name
func CreateFlagSet ¶
func ValidateName ¶
ValidateName ensures a Configuration name is valid
Types ¶
type Configuration ¶
type Configuration struct { Registry Registry `mapstructure:"registry"` TokenSource string `mapstructure:"token-source" yaml:"token-source"` // runs in shell to generate token }
Configuration is stored and loaded as yaml.
func Active ¶
func Active() (c Configuration, err error)
Active determines the active Configuration name, reads the Configuration, validates it, and returns a Configuration and possibly an error. If `config` flag exists, overrides active_config file.
func ActiveRaw ¶
func ActiveRaw() (name string, c Configuration, err error)
ActiveRaw reads the active file without env or flag bindings.
func Read ¶
func Read(name string) (c Configuration, err error)
Read loads a Configuration from yaml file matching `name`. If name contains a path, the file will be read from that path, otherwise the path is assumed as: ~/.config/registry. Does a simple read from the file: does not bind to env vars or flags, resolve, or validate. See also: ReadValid()
func ReadValid ¶
func ReadValid(name string) (c Configuration, err error)
ReadValid reads the specified Configuration, resolves it, and validates it. If name is empty, no file will be loaded and only bound flags and env vars will be used. An error is returned if the Configuration could not be read from a non-empty name, is not cannot be resolved, or is not valid once loaded and resolved. Binds to standard Flags and env vars. If name is empty, no file will be loaded and only bound flags and env vars will be used. See CreateFlagSet() and bindEnvs().
func (Configuration) FlatMap ¶
func (c Configuration) FlatMap() (map[string]interface{}, error)
FlatMap returns a Configuration as a flat Map.
func (*Configuration) FromMap ¶
func (c *Configuration) FromMap(m map[string]interface{}) error
FromMap populates a Configuration from a flat Map. Existing values are overridden.
func (Configuration) Properties ¶
func (c Configuration) Properties() []string
Properties returns a sorted list of all valid property names.
func (*Configuration) Resolve ¶
func (c *Configuration) Resolve() error
Resolve derived values (eg. Registry.Token from Registry.TokenSource)
func (*Configuration) Set ¶
func (c *Configuration) Set(k string, v interface{}) error
Set sets a property from a qualified name.
func (*Configuration) Unset ¶
func (c *Configuration) Unset(k string) error
Unset removed a property by qualified name.
func (Configuration) Validate ¶
func (c Configuration) Validate() error
Validate returns an error if Config is invalid.
func (Configuration) Write ¶
func (c Configuration) Write(name string) error
Write stores the Configuration in the passed file name.
type Registry ¶
type Registry struct { Address string `mapstructure:"address" yaml:"address"` // service address Insecure bool `mapstructure:"insecure" yaml:"insecure"` // if true, connect over HTTP Location string `mapstructure:"location" yaml:"location"` Project string `mapstructure:"project" yaml:"project"` Token string `mapstructure:"token" yaml:"-"` // generated from TokenSource }
type ValidationError ¶
func (ValidationError) Error ¶
func (e ValidationError) Error() string