config

package
v0.6.12 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const ActivePointerFilename = "active_config"

Variables

View Source
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 Activate

func Activate(name string) error

Activate sets the active Configuration file. Will error if file doesn't exist.

func ActiveName

func ActiveName() (string, error)

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 CreateFlagSet() *pflag.FlagSet

func Delete

func Delete(name string) error

Delete deletes a Configuration. Will error if active or missing (*os.PathError).

func ValidateName

func ValidateName(name string) error

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) Get added in v0.6.9

func (c *Configuration) Get(k string) (interface{}, error)

Get gets a property from a qualified or default namespace name.

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 or default namespace name.

func (*Configuration) Unset

func (c *Configuration) Unset(k string) error

Unset removed a property by qualified or default namespace name.

func (Configuration) Validate

func (c Configuration) Validate() error

Validate returns a ValidationError if Config is invalid.

func (Configuration) ValidateProperty added in v0.6.9

func (c Configuration) ValidateProperty(k string) error

ValidateProperty returns an UnknownPropertyError if not a valid property.

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 UnknownPropertyError added in v0.6.9

type UnknownPropertyError struct {
	Property string
}

func (UnknownPropertyError) Error added in v0.6.9

func (n UnknownPropertyError) Error() string

type ValidationError

type ValidationError struct {
	Field      string
	Validation string
}

func (ValidationError) Error

func (e ValidationError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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