yamlprocessor

package
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

Package yamlprocessor implements YAML processing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Processor

type Processor interface {
	// GetTemplateName returns the name of the template that needs to be
	// retrieved from the source.
	GetTemplateName(version, flavor string) string

	// GetVariables parses the template blob of bytes and provides a
	// list of variables that the template uses.
	GetVariables([]byte) ([]string, error)

	// GetVariables parses the template blob of bytes and provides a
	// map of variables that the template uses with their default values.
	GetVariableMap([]byte) (map[string]*string, error)

	// Process processes the template blob of bytes and will return the final
	// yaml with values retrieved from the values getter
	Process([]byte, func(string) (string, error)) ([]byte, error)
}

Processor defines the methods necessary for creating a specific yaml processor.

type SimpleProcessor

type SimpleProcessor struct{}

SimpleProcessor is a yaml processor that uses envsubst to substitute values for variables in the format ${var}. It also allows default values if specified in the format ${var:=default}. See https://github.com/drone/envsubst for more details.

func NewSimpleProcessor

func NewSimpleProcessor() *SimpleProcessor

NewSimpleProcessor returns a new simple template processor.

func (*SimpleProcessor) GetTemplateName

func (tp *SimpleProcessor) GetTemplateName(_, flavor string) string

GetTemplateName returns the name of the template that the simple processor uses. It follows the cluster template naming convention of "cluster-template<-flavor>.yaml".

func (*SimpleProcessor) GetVariableMap added in v0.4.0

func (tp *SimpleProcessor) GetVariableMap(rawArtifact []byte) (map[string]*string, error)

GetVariableMap returns a map of the variables specified in the yaml.

func (*SimpleProcessor) GetVariables

func (tp *SimpleProcessor) GetVariables(rawArtifact []byte) ([]string, error)

GetVariables returns a list of the variables specified in the yaml.

func (*SimpleProcessor) Process

func (tp *SimpleProcessor) Process(rawArtifact []byte, variablesClient func(string) (string, error)) ([]byte, error)

Process returns the final yaml with all the variables replaced with their respective values. If there are variables without corresponding values, it will return the raw yaml along with an error.

Jump to

Keyboard shortcuts

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