clconf

package
v2.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package clconf provides functions to extract values from a set of yaml files after merging them.

Index

Constants

This section is empty.

Variables

View Source
var Splitter = regexp.MustCompile(`,`)

Splitter is the regex used to split YAML_FILES and YAML_VARS

Functions

func DecodeBase64Strings

func DecodeBase64Strings(values ...string) ([]string, error)

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 FillValue

func FillValue(keyPath string, conf interface{}, out interface{}) bool

FillValue will fill a struct, out, with values from conf.

func GetValue

func GetValue(conf interface{}, keyPath string) (interface{}, error)

GetValue returns the value at the indicated path. Paths are separated by the '/' character. The empty string or "/" will return conf itself.

func ListToMap added in v2.1.0

func ListToMap(l []interface{}) map[interface{}]interface{}

ListToMap converts a list to an integer map.

func LoadConf

func LoadConf(files []string, overrides []string) (map[interface{}]interface{}, error)

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 LoadConfFromEnvironmentInterface added in v2.1.0

func LoadConfFromEnvironmentInterface(files []string, overrides []string) (interface{}, error)

LoadConfFromEnvironmentInterface will load all configurations present. In order of precedence (highest last), files, YAML_FILES env var, overrides, YAML_VARS env var.

func LoadConfInterface added in v2.1.0

func LoadConfInterface(files []string, overrides []string) (interface{}, error)

LoadConfInterface will load all configurations provided. In order of precedence (highest last), files, overrides.

func LoadSettableConfFromEnvironment

func LoadSettableConfFromEnvironment(files []string) (string, map[interface{}]interface{}, error)

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

func MarshalYaml(in interface{}) ([]byte, error)

MarshalYaml will convert an object to yaml

func MergeValue

func MergeValue(config interface{}, keyPath string, value interface{}, overwrite bool) error

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

func MkdirAllNoUmask(path string, perms os.FileMode) error

MkdirAllNoUmask is os.MkdirAll that ignores the current unix umask.

func NewTestConfig

func NewTestConfig() (interface{}, error)

func NewTestConfigContent

func NewTestConfigContent() ([]byte, error)

func NewTestConfigFile

func NewTestConfigFile() string

func NewTestKeysFile

func NewTestKeysFile() string

func ReadEnvVars

func ReadEnvVars(names ...string) ([]string, error)

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

func ReadFiles(files ...string) ([]string, error)

ReadFiles will read all the files supplied and return an array of their contents. The order of files to contents will be preserved.

func SaveConf

func SaveConf(config interface{}, file string) error

SaveConf will save config to file as yaml

func SetValue

func SetValue(config interface{}, keyPath string, value interface{}) error

SetValue will set the value of config at keyPath to value.

func ToKvMap

func ToKvMap(conf interface{}) map[string]string

ToKvMap will return a one-level map of key value pairs where the key is a / separated path of subkeys.

func UnixModeToFileMode

func UnixModeToFileMode(unixMode string) (os.FileMode, error)

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

func UnmarshalAllYaml(yamlString string) ([]interface{}, error)

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

func UnmarshalSingleYaml(yamlString string) (interface{}, error)

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

func UnmarshalYaml(yamlStrings ...string) (map[interface{}]interface{}, error)

UnmarshalYaml will parse all the supplied yaml strings, merge the resulting objects, and return the resulting map. If a root node is a list it will be converted to an int map prior to merging.

func UnmarshalYamlInterface added in v2.1.0

func UnmarshalYamlInterface(yamlStrings ...string) (interface{}, error)

UnmarshalYamlInterface will parse all the supplied yaml strings, merge the resulting objects, and return the resulting map. If a root node is a list it will be converted to an int map prior to merging. An emtpy document returns nil.

func ValuesAtPathsAreEqual

func ValuesAtPathsAreEqual(config interface{}, a, b string) bool

func Walk

func Walk(callback func(key []string, value interface{}), conf interface{})

Walk will recursively iterate over all the nodes of conf calling callback for each node.

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.

func (ConfSources) LoadInterface added in v2.1.0

func (s ConfSources) LoadInterface() (interface{}, error)

LoadInterface 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

func (*SecretAgent) Encrypt

func (secretAgent *SecretAgent) Encrypt(decrypted string) (string, error)

Encrypt will return the encrypted value represented by decrypted

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.

func (*Template) Execute

func (tmpl *Template) Execute(data interface{}) (string, error)

Execute will process the template text using data and the function map from confd.

type TemplateConfig

type TemplateConfig struct {
	Prefix      string
	SecretAgent *SecretAgent
	LeftDelim   string
	RightDelim  string
}

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
	// LeftDelim is passed to go teplate.Delims
	LeftDelim string
	// RightDelim is passed to go teplate.Delims
	RightDelim string
}

TemplateOptions are settings for ProcessTemplates.

type TemplateResult

type TemplateResult struct {
	Src  string
	Dest string
}

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.

Directories

Path Synopsis
Package memkv implements an in-memory key/value store with same API surface as "github.com/kelseyhightower/memkv".
Package memkv implements an in-memory key/value store with same API surface as "github.com/kelseyhightower/memkv".
Package template serves to isolate the large number of public functions created by template_funcs.go.
Package template serves to isolate the large number of public functions created by template_funcs.go.

Jump to

Keyboard shortcuts

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