Documentation
¶
Overview ¶
Package clconf provides functions to extract values from a set of yaml files after merging them.
Index ¶
- Variables
- func DecodeBase64Strings(values ...string) ([]string, error)
- func Fill(keyPath string, conf interface{}, decoderConfig *mapstructure.DecoderConfig) error
- func FillValue(keyPath string, conf interface{}, out interface{}) bool
- func GetValue(conf interface{}, keyPath string) (interface{}, error)
- func LoadConf(files []string, overrides []string) (map[interface{}]interface{}, error)
- func LoadConfFromEnvironment(files []string, overrides []string) (map[interface{}]interface{}, error)
- func LoadSettableConfFromEnvironment(files []string) (string, map[interface{}]interface{}, error)
- func MarshalYaml(in interface{}) ([]byte, error)
- func MergeValue(config interface{}, keyPath string, value interface{}, overwrite bool) error
- func MkdirAllNoUmask(path string, perms os.FileMode) error
- func NewTestConfig() (interface{}, error)
- func NewTestConfigContent() ([]byte, error)
- func NewTestConfigFile() string
- func NewTestKeysFile() string
- func ReadEnvVars(names ...string) ([]string, error)
- func ReadFiles(files ...string) ([]string, error)
- func SaveConf(config interface{}, file string) error
- func SetValue(config interface{}, keyPath string, value interface{}) error
- func ToKvMap(conf interface{}) map[string]string
- func UnixModeToFileMode(unixMode string) (os.FileMode, error)
- func UnmarshalAllYaml(yamlString string) ([]interface{}, error)
- func UnmarshalSingleYaml(yamlString string) (interface{}, error)
- func UnmarshalYaml(yamlStrings ...string) (map[interface{}]interface{}, error)
- func ValuesAtPathsAreEqual(config interface{}, a, b string) bool
- func Walk(callback func(key []string, value interface{}), conf interface{})
- type ConfSources
- type SecretAgent
- type Template
- type TemplateConfig
- type TemplateOptions
- type TemplateResult
Constants ¶
This section is empty.
Variables ¶
var Splitter = regexp.MustCompile(`,`)
Splitter is the regex used to split YAML_FILES and YAML_VARS
Functions ¶
func DecodeBase64Strings ¶
DecodeBase64Strings will decode all the base64 strings supplied
func Fill ¶
func Fill(keyPath string, conf interface{}, decoderConfig *mapstructure.DecoderConfig) error
Fill will fill a according to DecoderConfig with the values from conf.
func GetValue ¶
GetValue returns the value at the indicated path. Paths are separated by the '/' character. The empty string or "/" will return conf itself.
func LoadConf ¶
LoadConf will load all configurations provided. In order of precedence (highest last), files, overrides.
func LoadConfFromEnvironment ¶
func LoadConfFromEnvironment(files []string, overrides []string) (map[interface{}]interface{}, error)
LoadConfFromEnvironment will load all configurations present. In order of precedence (highest last), files, YAML_FILES env var, overrides, YAML_VARS env var.
func LoadSettableConfFromEnvironment ¶
LoadSettableConfFromEnvironment loads configuration for setting. Only one file is allowed, but can be specified, either by the environment variable YAML_FILES, or as the single value in the supplied files array. Returns the name of the file to be written, the conf map, and a non-nil error upon failure. If the file does not currently exist, an empty map will be returned and a call to SaveConf will create the file.
func MarshalYaml ¶
MarshalYaml will convert an object to yaml
func MergeValue ¶
MergeValue will merge the values from value into config at keyPath. If overwrite is true, values from value will overwrite existing values in config.
func MkdirAllNoUmask ¶
MkdirAllNoUmask is os.MkdirAll that ignores the current unix umask.
func NewTestConfig ¶
func NewTestConfig() (interface{}, error)
func NewTestConfigContent ¶
func NewTestConfigFile ¶
func NewTestConfigFile() string
func NewTestKeysFile ¶
func NewTestKeysFile() string
func ReadEnvVars ¶
ReadEnvVars will read all the environment variables named and return an array of their values. The order of the names to values will be preserved.
func ReadFiles ¶
ReadFiles will read all the files supplied and return an array of their contents. The order of files to contents will be preserved.
func ToKvMap ¶
ToKvMap will return a one-level map of key value pairs where the key is a / separated path of subkeys.
func UnixModeToFileMode ¶
UnixModeToFileMode converts a unix file mode including special bits to a golang os.FileMode. The special bits (sticky, setuid, setgid) don't line up exactly between the two. Example: 02777 would set the setuid bit on unix but would end up 0777 if used as an os.FileMode
func UnmarshalAllYaml ¶
UnmarshalAllYaml will unmarshal all yaml docs in a single yaml/json string without merging. This form works for any yaml data, not just objects.
func UnmarshalSingleYaml ¶
UnmarshalSingleYaml will unmarshal the first yaml doc in a single yaml/json string without merging. This form works for any yaml data, not just objects.
func UnmarshalYaml ¶
UnmarshalYaml will parse all the supplied yaml strings, merge the resulting objects, and return the resulting map. This only works for objects because the merge requires objects.
func ValuesAtPathsAreEqual ¶
Types ¶
type ConfSources ¶
type ConfSources struct {
// Environment loads config from environment vars when true. The vars loaded
// are:
// YAML_FILES: comma separated values will be appended to Files
// YAML_VARS: comma separated values of other environment variables to read
// and whose base64 strings will be appended to Overrides
Environment bool
// Files is a list of filenames to read
Files []string
// Overrides are Base64 encoded strings of yaml
Overrides []string
// An optional (can be nil) stream to read raw yaml (potentially multiple
// inline documents)
Stream io.Reader
}
ConfSources contains sources of yaml for loading. See Load() for precedence
func (ConfSources) Load ¶
func (s ConfSources) Load() (map[interface{}]interface{}, error)
Load will load the config determined by settings in the struct. In order of precedence (highest last), Files, YAML_FILES env var, Overrides, YAML_VARS env var, Stream.
type SecretAgent ¶
type SecretAgent struct {
// contains filtered or unexported fields
}
SecretAgent loads and holds a keypair needed for encryption/decryption
func NewSecretAgent ¶
func NewSecretAgent(key []byte) *SecretAgent
NewSecretAgent will return a new SecretAgent with the provided key.
func NewSecretAgentFromBase64 ¶
func NewSecretAgentFromBase64(keyBase64 string) (*SecretAgent, error)
NewSecretAgentFromBase64 loads from keyBase64
func NewSecretAgentFromFile ¶
func NewSecretAgentFromFile(keyFile string) (*SecretAgent, error)
NewSecretAgentFromFile loads from keyFile
func NewTestSecretAgent ¶
func NewTestSecretAgent() (*SecretAgent, error)
func (*SecretAgent) Decrypt ¶
func (secretAgent *SecretAgent) Decrypt(encrypted string) (string, error)
Decrypt will return the decrypted value represented by encrypted
func (*SecretAgent) DecryptPaths ¶
func (secretAgent *SecretAgent) DecryptPaths(config interface{}, encryptedPaths ...string) error
DecryptPaths will will replace the values at the indicated paths with thier decrypted values
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a wrapper for template.Template to include custom template functions corresponding to confd functions.
func NewTemplate ¶
func NewTemplate(name, text string, config *TemplateConfig) (*Template, error)
NewTemplate returns a parsed Template configured with standard functions.
func NewTemplateFromBase64 ¶
func NewTemplateFromBase64(name, base64 string, config *TemplateConfig) (*Template, error)
NewTemplateFromBase64 decodes base64 then calls NewTemplate with the result.
func NewTemplateFromFile ¶
func NewTemplateFromFile(name, file string, config *TemplateConfig) (*Template, error)
NewTemplateFromFile reads file then calls NewTemplate with the result.
type TemplateConfig ¶
type TemplateConfig struct {
Prefix string
SecretAgent *SecretAgent
}
TemplateConfig allows for optional configuration.
type TemplateOptions ¶
type TemplateOptions struct {
// CopyTemplatePerms uses the existing template permissions instead of FileMode for template
// permissions
CopyTemplatePerms bool
// Flatten flattens the templates into the root of the dest instead of the preserving
// the relative path under the source.
Flatten bool
// KeepEmpty forces empty result files to be written (usually not written or removed if already existing)
KeepEmpty bool
// KeepExistingPerms determines whether to use existing permissions on template files that are overwritten.
KeepExistingPerms bool
// Rm determines whether template files distinct from their target are deleted after processing.
Rm bool
// FileMode is the permissions to apply to template files when writing.
FileMode os.FileMode
// DirMode is the permission similar to FileMode but for new folders.
DirMode os.FileMode
// Extension is the extension to use when searching folders. If missing all files will be used.
// The extension is stripped from the file name when templating.
Extension string
}
TemplateOptions are settings for ProcessTemplates.
type TemplateResult ¶
TemplateResult stores the result of a single template processing.
func ProcessTemplates ¶
func ProcessTemplates(srcs []string, dest string, value interface{}, secretAgent *SecretAgent, options TemplateOptions, ) ([]TemplateResult, error)
ProcessTemplates processes templates. If dest is non empty it must be a folder into which templates will be placed after processing (the folder will be created if necessary). If empty templates are processed into the folders in which they are found.