Documentation
¶
Index ¶
- Variables
- func GetDefaultConfigFilePath() (string, error)
- func GetDefaultConfigPath() (string, error)
- type Hook
- type Key
- type ProfiledConfig
- func (p *ProfiledConfig) BindFlag(configPath string, f *pflag.Flag) error
- func (p *ProfiledConfig) GetBool(key string) bool
- func (p *ProfiledConfig) GetInt(key string) int
- func (p *ProfiledConfig) GetIntOrElse(key string, orElse int) int
- func (p *ProfiledConfig) GetPath() string
- func (p *ProfiledConfig) GetProfile() string
- func (p *ProfiledConfig) GetString(key string) string
- func (p *ProfiledConfig) GetStringSlice(key string) []string
- func (p *ProfiledConfig) Save() error
- func (p *ProfiledConfig) Set(k string, v any)
- func (p *ProfiledConfig) SetString(k string, v string)
Constants ¶
This section is empty.
Variables ¶
var ConfigKey = Key{}
Config is a global instance of the Key type
var OuptutFormat = common.DefaultOutputFormat
Functions ¶
func GetDefaultConfigPath ¶
Returns the expanded default config path depending on what environment variables are set. If XDG_CONFIG_HOME is set, the default is $XDG_CONFIG_HOME/kongctl, otherwise the default is os.UserHomeDir()/.config/kongctl. If these values are not set, an error is returned.
Types ¶
type Hook ¶
type Hook interface {
// Save writes the configuration to the file system
// TODO: Evaluate if writing the credentials is something we want to do at all
// I saw some issues related to writing config which may have been loaded by a variety of sources
// and is that desirable behavior (also security concerns with secrets loaded at runtime)
Save() error
// GetString returns a string value from the configuration
GetString(key string) string
// GetBool returns a boolean value from the configuration
GetBool(key string) bool
// GetInt returns an integer value from the configuration
GetInt(key string) int
// GetIntOrElse returns an integer value from the configuration or a default
GetIntOrElse(key string, orElse int) int
// GetStringSlice returns a slice of strings from the configuration
GetStringSlice(key string) []string
// SetString sets an override for a given string
SetString(key string, value string)
// Set sets an override for a given key
Set(k string, v any)
// Get returns a value from the configuration
Get(key string) any
// BindFlag takes a specific configuration path and
// binds it to a specific flag
BindFlag(configPath string, f *pflag.Flag) error
// The profile for this configuration
GetProfile() string
// The file path used to load this configuration
GetPath() string
}
Hook provides a generatlization of the Viper interface but allows some control, specifically over the Save functionality which we extend to provide safer file management handling
type Key ¶
type Key struct{}
Empty type to represent the _type_ Config. Genesis is to support a key in a Context
type ProfiledConfig ¶
type ProfiledConfig struct {
*v.Viper
ProfileName string
Path string
// contains filtered or unexported fields
}
ProfiledConfig is a Viper but with an associated profile ProfileName
allows for extraction of the profile specific sub-configuration and implements the Hook interface for more restricted interactions with the configuration system
func BuildProfiledConfig ¶
func BuildProfiledConfig(profile string, path string, mainv *v.Viper) *ProfiledConfig
func GetConfig ¶
func GetConfig(path string, profile string, defaultConfigFilePath string) (*ProfiledConfig, error)
GetConfig returns the configuration for this instance of the CLI
func (*ProfiledConfig) BindFlag ¶
func (p *ProfiledConfig) BindFlag(configPath string, f *pflag.Flag) error
func (*ProfiledConfig) GetBool ¶
func (p *ProfiledConfig) GetBool(key string) bool
func (*ProfiledConfig) GetInt ¶
func (p *ProfiledConfig) GetInt(key string) int
func (*ProfiledConfig) GetIntOrElse ¶ added in v0.0.14
func (p *ProfiledConfig) GetIntOrElse(key string, orElse int) int
func (*ProfiledConfig) GetPath ¶
func (p *ProfiledConfig) GetPath() string
func (*ProfiledConfig) GetProfile ¶
func (p *ProfiledConfig) GetProfile() string
func (*ProfiledConfig) GetString ¶
func (p *ProfiledConfig) GetString(key string) string
func (*ProfiledConfig) GetStringSlice ¶
func (p *ProfiledConfig) GetStringSlice(key string) []string
func (*ProfiledConfig) Save ¶
func (p *ProfiledConfig) Save() error
func (*ProfiledConfig) Set ¶
func (p *ProfiledConfig) Set(k string, v any)
func (*ProfiledConfig) SetString ¶
func (p *ProfiledConfig) SetString(k string, v string)