config

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigKey = Key{}

Config is a global instance of the Key type

Functions

func GetDefaultConfigFilePath

func GetDefaultConfigFilePath() (string, error)

func GetDefaultConfigPath

func GetDefaultConfigPath() (string, error)

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
	// 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) 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)

Jump to

Keyboard shortcuts

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