Documentation ¶
Index ¶
- Constants
- Variables
- func Load(data []byte) (config *cmdutils.Config, err error)
- func LoadFromFile(filename string) (*cmdutils.Config, error)
- func ModifyConfig(configAccess ConfigAccess, newConfig cmdutils.Config, relativizePaths bool) error
- func Write(config cmdutils.Config) ([]byte, error)
- func WriteToFile(config cmdutils.Config, filename string) error
- type ClientConfig
- func NewInteractiveClientConfig(config cmdutils.Config, contextName string, ...) ClientConfig
- func NewNonInteractiveClientConfig(config cmdutils.Config, contextName string, ...) ClientConfig
- func NewNonInteractiveDeferredLoadingClientConfig(loader ClientConfigLoader, overrides *cmdutils.ConfigOverrides) ClientConfig
- type ClientConfigLoader
- type ClientConfigLoadingRules
- func (rules *ClientConfigLoadingRules) GetDefaultFilename() string
- func (rules *ClientConfigLoadingRules) GetLoadingPrecedence() []string
- func (rules *ClientConfigLoadingRules) GetStartingConfig() (*cmdutils.Config, error)
- func (rules *ClientConfigLoadingRules) Load() (*cmdutils.Config, error)
- func (rules *ClientConfigLoadingRules) Migrate() error
- func (rules ClientConfigLoadingRules) ResolvePaths() bool
- type ConfigAccess
- type DeferredLoadingClientConfig
- type DirectClientConfig
- type PathOptions
Constants ¶
const ( RecommendedConfigPathEnvVar = "PULSARCONFIG" RecommendedHomeDir = ".config" RecommendedFileName = "pulsar/config" )
Variables ¶
var ( RecommendedConfigDir = path.Join(utils.HomeDir(), RecommendedHomeDir) RecommendedHomeFile = path.Join(RecommendedConfigDir, RecommendedFileName) )
Functions ¶
func Load ¶
Load takes a byte slice and deserializes the contents into Config object. Encapsulates deserialization without assuming the source is a file.
func LoadFromFile ¶
LoadFromFile takes a filename and deserializes the contents into Config object
func ModifyConfig ¶
func ModifyConfig(configAccess ConfigAccess, newConfig cmdutils.Config, relativizePaths bool) error
ModifyConfig takes a Config object and write filed of Config struct to file
Types ¶
type ClientConfig ¶
type ClientConfig interface { // RawConfig returns the merged result of all overrides RawConfig() (cmdutils.Config, error) // ConfigAccess returns the rules for loading/persisting the config. ConfigAccess() ConfigAccess }
func NewInteractiveClientConfig ¶
func NewInteractiveClientConfig(config cmdutils.Config, contextName string, overrides *cmdutils.ConfigOverrides, fallbackReader io.Reader, configAccess ConfigAccess) ClientConfig
NewInteractiveClientConfig creates a DirectClientConfig using the passed context name and a reader in case auth information is not provided via files or flags
func NewNonInteractiveClientConfig ¶
func NewNonInteractiveClientConfig(config cmdutils.Config, contextName string, overrides *cmdutils.ConfigOverrides, configAccess ConfigAccess) ClientConfig
NewNonInteractiveClientConfig creates a DirectClientConfig using the passed context name and does not have a fallback reader for auth information
func NewNonInteractiveDeferredLoadingClientConfig ¶
func NewNonInteractiveDeferredLoadingClientConfig(loader ClientConfigLoader, overrides *cmdutils.ConfigOverrides) ClientConfig
NewNonInteractiveDeferredLoadingClientConfig creates a ConfigClientClientConfig using the passed context name
type ClientConfigLoader ¶
type ClientConfigLoader interface { ConfigAccess // Load returns the latest config Load() (*cmdutils.Config, error) }
type ClientConfigLoadingRules ¶
type ClientConfigLoadingRules struct { Precedence []string // MigrationRules is a map of destination files to source files. If a destination file is not present, // then the source file is checked. // If the source file is present, then it is copied to the destination file BEFORE any further loading happens. MigrationRules map[string]string // DoNotResolvePaths indicates whether or not to resolve paths with respect to the originating files. // This is phrased as a negative so that a default object that doesn't set this will usually get // the behavior it wants. DoNotResolvePaths bool // DefaultClientConfig is an optional field indicating what rules to use to calculate a default configuration. // This should match the overrides passed in to ClientConfig loader. DefaultClientConfig ClientConfig // WarnIfAllMissing indicates whether the configuration files pointed by pulsarCONFIG environment // variable are present or not. // In case of missing files, it warns the user about the missing files. WarnIfAllMissing bool }
ClientConfigLoadingRules is an ExplicitPath and string slice of specific locations that are used for merging together a Config Callers can put the chain together however they want, but we'd recommend: EnvVarPathFiles if set (a list of files if set) OR the HomeDirectoryPath ExplicitPath is special, because if a user specifically requests a certain file be used and error is reported if this file is not present
func NewDefaultClientConfigLoadingRules ¶
func NewDefaultClientConfigLoadingRules() *ClientConfigLoadingRules
NewDefaultClientConfigLoadingRules returns a ClientConfigLoadingRules object with default fields filled in. You are not required to use this constructor
func (*ClientConfigLoadingRules) GetDefaultFilename ¶
func (rules *ClientConfigLoadingRules) GetDefaultFilename() string
GetDefaultFilename implements ConfigAccess
func (*ClientConfigLoadingRules) GetLoadingPrecedence ¶
func (rules *ClientConfigLoadingRules) GetLoadingPrecedence() []string
GetLoadingPrecedence implements ConfigAccess
func (*ClientConfigLoadingRules) GetStartingConfig ¶
func (rules *ClientConfigLoadingRules) GetStartingConfig() (*cmdutils.Config, error)
GetStartingConfig implements ConfigAccess
func (*ClientConfigLoadingRules) Load ¶
func (rules *ClientConfigLoadingRules) Load() (*cmdutils.Config, error)
Load starts by running the MigrationRules and then takes the loading rules and returns a Config object based on following rules.
if the ExplicitPath, return the unmerged explicit file Otherwise, return a merged config based on the Precedence slice
A missing ExplicitPath file produces an error. Empty filenames or other missing files are ignored. Read errors or files with non-deserializable content produce errors. The first file to set a particular map key wins and map key's value is never changed. BUT, if you set a struct value that is NOT contained inside of map, the value WILL be changed. This results in some odd looking logic to merge in one direction, merge in the other, and then merge the two. It also means that if two files specify a "red-user", only values from the first file's red-user are used. Even non-conflicting entries from the second file's "red-user" are discarded. Relative paths inside of the .pulsarconfig files are resolved against the .pulsarconfig file's parent folder and only absolute file paths are returned.
func (*ClientConfigLoadingRules) Migrate ¶
func (rules *ClientConfigLoadingRules) Migrate() error
Migrate uses the MigrationRules map. If a destination file is not present, then the source file is checked. If the source file is present, then it is copied to the destination file BEFORE any further loading happens.
func (ClientConfigLoadingRules) ResolvePaths ¶
func (rules ClientConfigLoadingRules) ResolvePaths() bool
type ConfigAccess ¶
type ConfigAccess interface { // GetLoadingPrecedence returns the slice of files that should be used for loading and inspecting the config GetLoadingPrecedence() []string // GetStartingConfig returns the config that subcommands should being operating against. // It may or may not be merged depending on loading rules GetStartingConfig() (*cmdutils.Config, error) // GetDefaultFilename returns the name of the file you should write into (create if necessary), // if you're trying to create a new stanza as opposed to updating an existing one. GetDefaultFilename() string }
type DeferredLoadingClientConfig ¶
type DeferredLoadingClientConfig struct {
// contains filtered or unexported fields
}
DeferredLoadingClientConfig is a ClientConfig interface that is backed by a client config loader.
func (*DeferredLoadingClientConfig) ConfigAccess ¶
func (config *DeferredLoadingClientConfig) ConfigAccess() ConfigAccess
ConfigAccess implements ClientConfig
type DirectClientConfig ¶
type DirectClientConfig struct {
// contains filtered or unexported fields
}
DirectClientConfig is a ClientConfig interface that is backed by a clientcmdapi.Config, options overrides, and an optional fallbackReader for auth information
func (*DirectClientConfig) ConfigAccess ¶
func (config *DirectClientConfig) ConfigAccess() ConfigAccess
ConfigAccess implements ClientConfig
type PathOptions ¶
type PathOptions struct { // GlobalFile is the full path to the file to load as the global (final) option GlobalFile string // GlobalFileSubpath is an optional value used for displaying help GlobalFileSubpath string LoadingRules *ClientConfigLoadingRules }
func NewDefaultPathOptions ¶
func NewDefaultPathOptions() *PathOptions
func (*PathOptions) GetDefaultFilename ¶
func (o *PathOptions) GetDefaultFilename() string
func (*PathOptions) GetLoadingPrecedence ¶
func (o *PathOptions) GetLoadingPrecedence() []string
func (*PathOptions) GetStartingConfig ¶
func (o *PathOptions) GetStartingConfig() (*cmdutils.Config, error)