Documentation
¶
Overview ¶
Package templig is the main package of the configuration library.
Index ¶
Constants ¶
const SecretDefaultRE = "(?i)key|secret|pass(?:word)?|cert(?:ificate)?"
SecretDefaultRE is the default regular expression used to identify secret values automatically.
Variables ¶
var ( // ErrNoConfigReaders indicates that no configuration readers were provided to the function. ErrNoConfigReaders = errors.New("no configuration readers given") // ErrNoConfigPaths indicates that no configuration file paths were provided where at least one is required. ErrNoConfigPaths = errors.New("no configuration paths given") )
var ( // ErrNodeNil is an error returned when a provided node is nil. ErrNodeNil = errors.New("node is nil") // ErrNodeKindMismatch is an error returned when two nodes have incompatible kinds during an operation. ErrNodeKindMismatch = errors.New("node kind mismatch") // ErrNodeTypeUnhandled is an error returned when a node has an unhandled or unsupported type during processing. ErrNodeTypeUnhandled = errors.New("node type unhandled") // ErrAliasNodeExpected is an error returned when an operation // expects an alias node but encounters a different type. ErrAliasNodeExpected = errors.New("alias node expected") // ErrUnexpectedDocumentNodeConfiguration is an error returned // when a document node has an unexpected or invalid configuration. ErrUnexpectedDocumentNodeConfiguration = errors.New("unexpected document node configuration") // ErrUnequalNameAnchors is an error returned when operations on named anchors fail // due to unequal anchor definitions. ErrUnequalNameAnchors = errors.New("unequal named anchors not yet supported") )
var SecretRE = regexp.MustCompile(SecretDefaultRE)
SecretRE is the regular expression used to identify secret values automatically. In case there are different properties to identify secrets, extend it. Access to this variable is not synchronized, thus modifying it shall be done before working with templig.
var TemplateFunctions = template.FuncMap{
"arg": argumentValue,
"hasArg": argumentPresent,
"required": required,
"read": readFile,
}
TemplateFunctions is a template.FuncMap that allows to globally remove the additional templig template functions or even add own functions on top of what is already provided. For user-provided functions, please use the prefix `uP`, that is guaranteed to never be used as a templig provided function. Access to this variable is not synchronized, thus modifying it shall be done before working with templig.
Functions ¶
func HideSecrets ¶ added in v0.4.0
HideSecrets hides secrets in the given YAML node structure. Secrets are identified using the SecretRE. Depending on the parameter `hideStructure`, the structure of the secret is hidden too (`true`) or visible (`false`).
Types ¶
type Config ¶
type Config[T any] struct { // contains filtered or unexported fields }
Config is the generic structure holding the configuration information for the specified type.
func FromFile ¶
FromFile loads a series of configuration files. The first file is considered the base, all others are loaded on top of that one using the MergeYAMLNodes functionality.
func FromFiles
deprecated
added in
v0.3.0
FromFiles loads a series of configuration files. The first file is considered the base, all others are loaded on top of that one using the MergeYAMLNodes functionality.
Deprecated: As of version 'v0.6.0' this function is deprecated and will be removed in the next major release.
func (*Config[T]) Get ¶
func (c *Config[T]) Get() *T
Get gives a pointer to the deserialized configuration. Get does not load the configuration anew and is principally inexpensive to call.
func (*Config[T]) ToFile ¶
ToFile saves a configuration to a file with the given name, replacing it in case.
func (*Config[T]) ToSecretsHidden ¶
ToSecretsHidden writes the configuration to the given io.Writer and hides secret values using the SecretRE. Strings are replaced with the number of * corresponding to their length. Substructures containing secrets are replaced with a single '*'. The following example
id: id0 secrets: - secret0 - secret1
thus will be replaced by
id: id0 secrets: *
func (*Config[T]) ToSecretsHiddenStructured ¶ added in v0.4.0
ToSecretsHiddenStructured writes the configuration to the given io.Writer and hides secret values using the SecretRE. Strings are replaced with the number of * corresponding to their length. Substructures containing secrets are replaced with a corresponding structure of '*'. The following example
id: id0 secrets: - secret0 - secret1
thus will be replaced by
id: id0 secrets: - ******* - *******
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
overlay
command
Package main of the overlay example.
|
Package main of the overlay example. |
|
simple
command
Package main of the simple example.
|
Package main of the simple example. |
|
templating/arg
command
Package main of the templating function `arg` example.
|
Package main of the templating function `arg` example. |
|
templating/env
command
Package main of the templating function `env` example.
|
Package main of the templating function `env` example. |
|
templating/hasArg
command
Package main of the templating function `hasArg` example.
|
Package main of the templating function `hasArg` example. |
|
templating/read
command
Package main of the templating function `read` example.
|
Package main of the templating function `read` example. |
|
validate
command
Package main of the validation example.
|
Package main of the validation example. |