tpl

package
v0.44.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTemplateVarNotFound = tplError.Code("template_var_not_found").ErrorPref("no value was supplied for template variable '%s'")
)

Evaluate errors

Functions

func ErrIllegalSecretCharacter

func ErrIllegalSecretCharacter(lineNo, colNo int, char rune) error

ErrIllegalSecretCharacter is returned when a secret tag contains a character that is not allowed.

func ErrIllegalVariableCharacter

func ErrIllegalVariableCharacter(lineNo, colNo int, char rune) error

ErrIllegalVariableCharacter is returned when a variable tag contains a character that is not allowed.

func ErrSecretTagNotClosed

func ErrSecretTagNotClosed(lineNo, colNo int) error

ErrSecretTagNotClosed is returned when a secret tag is opened, but never closed.

func ErrUnexpectedCharacter

func ErrUnexpectedCharacter(lineNo, colNo int, actual, expected rune) error

ErrUnexpectedCharacter is returned when expecting a specific character, for example the first character of a closing delimiter after a space occurred in a tag, or the second character of a closing delimiter after the first character of the closing delimiter.

func ErrVariableTagNotClosed

func ErrVariableTagNotClosed(lineNo, colNo int) error

ErrVariableTagNotClosed is returned when a variable tag is opened, but never closed.

func IsV1Template added in v0.24.1

func IsV1Template(raw []byte) bool

IsV1Template returns whether v1 secret tags are used in the given raw bytes.

Types

type Parser

type Parser interface {
	Parse(raw string, column, line int) (Template, error)
}

Parser parses a raw string to a template.

func NewParser

func NewParser() Parser

NewParser returns a parser for the latest template syntax.

func NewV1Parser

func NewV1Parser() Parser

NewV1Parser returns a parser for the v1 template syntax.

V1 templates can contain secret paths between ${}: ${ path/to/secret }

V1 templates do not support template variables.

func NewV2Parser

func NewV2Parser() Parser

NewV2Parser returns a parser for the v2 template syntax.

V2 templates can contain secret paths between brackets: {{ path/to/secret }}

Within secret paths, variables can be used. Variables are given between `${` and `}`. For example: {{ ${app}/db/secret }} Variables cannot be used outside of secret paths.

Spaces directly after opening delimiters (`{{` and `${`) and directly before closing delimiters (`}}`, `}`) are ignored. They are not included in the secret pahts and variable names.

type SecretReader

type SecretReader interface {
	ReadSecret(path string) (string, error)
}

SecretReader fetches a secret by its path.

type Template

type Template interface {
	// Evaluate renders a template. It replaces all variable- and secret tags in the template.
	// The supplied variables should have lowercase keys.
	Evaluate(varReader VariableReader, sr SecretReader) (string, error)

	ContainsSecrets() bool
}

Template contains secret and variable references. It can be evaluated to resolve to a string.

type VariableReader added in v0.34.0

type VariableReader interface {
	ReadVariable(name string) (string, error)
}

VariableReader fetches a template variable by its name.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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