sources

package
v0.0.0-...-409007c Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigSuffix       = ".yaml"
	ConfigFname        = "common" + ConfigSuffix
	ConfigD            = "config.d"
	EnvironmentsSubdir = "environments"
	TemplatesSubdir    = "templates"
)
View Source
const GlobalVarsKey = "_vars"

Variables

View Source
var FuncMap = template.FuncMap{
	"iadd":       func(x, y int) int { return x + y },
	"imul":       func(x, y int) int { return x * y },
	"idiv":       func(x, y int) int { return x / y },
	"imod":       func(x, m int) int { return x % m },
	"tostr":      util.ToString,
	"strtoi":     util.AtoI,
	"safe":       util.SafeValue,
	"coalesce":   util.Coalesce,
	"tolower":    util.SafeToLower,
	"match":      util.SafeMatch,
	"regexrepl":  util.SafeReplaceAllString,
	"quotedlist": util.QuotedList,
	"sequence":   util.Sequence,
	"timeoffset": util.TimeOffset,
	"isfile":     util.IsFile,
	"decode64": func(in string) string {
		data, err := base64.StdEncoding.DecodeString(in)
		if err != nil {
			panic(err)
		}
		return string(data)
	},
}

Default functions set available to templates.

View Source
var TestEnvVars = map[string]string{
	"x": "v_from_env_x",
}

Env vars that will be set for each run

View Source
var (
	TestsDefBaseDir = filepath.Join(base_dir, "test-run")
)

Functions

func AssertRunForEnvironment

func AssertRunForEnvironment(t *testing.T, dir string, environment string, result_dir string)

Assert that processed templates match expectations storet in the results/ dir

func AssertVarsChain

func AssertVarsChain(t *testing.T, p *Processor, dir string, environment string)

Assert that Processor vars chains for environment templates match expectations. Expectations are stored in vars_chain/<environment>.yaml files. What we are testing here is that config.d/ values superseed common.yaml, and environments/* superseed common,yaml environments

func CloneFuncMap

func CloneFuncMap() template.FuncMap

Returns a FuncMap clone, so parallel processing does not complain.

func LoadConfigFile

func LoadConfigFile(path string) util.AnyMap

Config file loader. Loads Yaml into a map.

func RegisterSource

func RegisterSource(name string, factory SourceFactory, order int, force bool)

Register Source point

func RegisterTemplateFunc

func RegisterTemplateFunc(name string, fn interface{})

Register additional function.

func RunTests

func RunTests(t *testing.T, test_fn func(t *testing.T, dir string))

test-run iterator, that sets up the stage - env vars

Types

type BaseSource

type BaseSource struct {
	MergeHistory
}

A basic SourceInterface implementation, with nil returns.

func MakeBaseSource

func MakeBaseSource() BaseSource

func (*BaseSource) AllEnvironments

func (s *BaseSource) AllEnvironments() []string

func (*BaseSource) AllTemplates

func (s *BaseSource) AllTemplates() Templates

func (*BaseSource) DeployablesForEnvironment

func (s *BaseSource) DeployablesForEnvironment(environment string) *Deployables

func (*BaseSource) Template

func (s *BaseSource) Template(n string) *Template

type Deployables

type Deployables struct {
	Vars
	Specs
}

A set of Vars and Specs, used per environment or default

func MakeDeployables

func MakeDeployables(m util.AnyMap) *Deployables

Turns a map into Deployables.

func (*Deployables) Merge

func (ds *Deployables) Merge(ds1 *Deployables)

Applies an overriding set.

func (*Deployables) Overlay

func (ds *Deployables) Overlay(ds1 *Deployables)

Applies an overriding set, overlaying the new default Vars over the existing Specs first.

func (*Deployables) PreparedSpecs

func (ds *Deployables) PreparedSpecs() Specs

Returns the Specs with applied default Vars where appropriate

type DeployablesSource

type DeployablesSource struct {
	*Deployables
	BaseSource
}

Generic DeployablesSource type and SourceInterface implementation

func (*DeployablesSource) DeployablesForEnvironment

func (d *DeployablesSource) DeployablesForEnvironment(environment string) *Deployables

func (*DeployablesSource) MergeConfig

func (d *DeployablesSource) MergeConfig(origin string, deployables interface{})

type EnvForPrefix

type EnvForPrefix string

Helper type to set/clear env vars

func FindEnvVarsPrefix

func FindEnvVarsPrefix(dir string) EnvForPrefix

Find suitable env_vars_prefix in config(s)

func (*EnvForPrefix) Clear

func (ep *EnvForPrefix) Clear()

func (*EnvForPrefix) Set

func (ep *EnvForPrefix) Set(v, val string)

type EnvVarsSource

type EnvVarsSource struct {
	*DeployablesSource
}

An env vars version of DeployablesSource type. NOSpecs, just Vars.

func (*EnvVarsSource) MergeConfig

func (v *EnvVarsSource) MergeConfig(origin string, prefix interface{})

type EnvironmentDeployables

type EnvironmentDeployables map[string]*Deployables

A Deployables per environment version of DeployablesSource type

type EnvironmentsSource

type EnvironmentsSource struct {
	EnvironmentDeployables
	BaseSource
}

func (*EnvironmentsSource) AllEnvironments

func (e *EnvironmentsSource) AllEnvironments() []string

func (*EnvironmentsSource) DeployablesForEnvironment

func (e *EnvironmentsSource) DeployablesForEnvironment(environment string) *Deployables

func (*EnvironmentsSource) MergeConfig

func (e *EnvironmentsSource) MergeConfig(origin string, es interface{})

type ExpectedVarsChains

type ExpectedVarsChains map[string]VarsChain

type FileSystemSource

type FileSystemSource struct {
	*EnvironmentsSource
	Templates
}

A EnvironmentsSource type upgrade with Templates

func (*FileSystemSource) AllTemplates

func (f *FileSystemSource) AllTemplates() Templates

func (*FileSystemSource) MergeConfig

func (f *FileSystemSource) MergeConfig(origin string, d interface{})

func (*FileSystemSource) Template

func (f *FileSystemSource) Template(name string) *Template

type MergeEvent

type MergeEvent struct {
	Origin string
	Loaded interface{}
}

Forensic helpers, merge events audit

type MergeHistory

type MergeHistory []*MergeEvent

func (*MergeHistory) AddHistory

func (h *MergeHistory) AddHistory(origin string, values interface{})

type Processor

type Processor struct {
	DefaultEnvironment string
	Sources            []*SourceInstance
}

The main workhorse - a collection of SourceInstances that applies Vars hierarchically to Templates

func LoadConfigsFromDir

func LoadConfigsFromDir(dir string) *Processor

Config dir loader. Creates a new Processor and loads it with config maps. Calls LoadConfigFile() for each file to get those maps.

func NewProcessor

func NewProcessor() *Processor

Gives a Processor, based on the RegisteredSources

func (*Processor) Get

func (p *Processor) Get(name string) SourceInterface

func (*Processor) ListEnvironments

func (p *Processor) ListEnvironments() []string

List all environments known to the Sources

func (*Processor) ListTemplates

func (p *Processor) ListTemplates() []map[string]string

List all templates known to the Sources

func (*Processor) MergeConfig

func (p *Processor) MergeConfig(origin string, config util.AnyMap)

Load Sources from a map. Map keys match RegisteredSource names. Unknow source names are reported and skipped.

func (*Processor) RunForEnvironment

func (p *Processor) RunForEnvironment(environment string, target_base_dir string)

Process Templates for a given environment. Deliver files to the target_base_dir if specified. Templates are processed in parallel.

func (*Processor) Specs

func (p *Processor) Specs(environment string) Specs

Return the corresponding set of Specs for an environment. Hierarchically overlays Specs from the Sources according to their order.

func (*Processor) Template

func (p *Processor) Template(name string) *Template

Find the template by its name

type RegisteredSource

type RegisteredSource struct {
	SourceFactory
	// contains filtered or unexported fields
}

Infrastructure for registering sources in order. RegisteredSource is astructure that can potentially be loaded with config values/templates.

type RegisteredSources

type RegisteredSources map[string]*RegisteredSource

func (*RegisteredSources) NewProcessor

func (rs *RegisteredSources) NewProcessor() *Processor

Makes a Processor and loads it with SourceInstances

func (*RegisteredSources) Register

func (rs *RegisteredSources) Register(name string, factory SourceFactory, order int, force bool)

type SourceFactory

type SourceFactory func() SourceInterface

type SourceInstance

type SourceInstance struct {
	Name string
	SourceInterface
}

A named Source - type that implements SourceInterface

type SourceInterface

type SourceInterface interface {
	MergeConfig(origin string, values interface{})
	DeployablesForEnvironment(environment string) *Deployables
	Template(string) *Template
	AllEnvironments() []string
	AllTemplates() Templates
}

Source interface

func MakeDeployablesSource

func MakeDeployablesSource() SourceInterface

func MakeEnvVarsSource

func MakeEnvVarsSource() SourceInterface

func MakeEnvironmentsSource

func MakeEnvironmentsSource() SourceInterface

func MakeFileSystemSource

func MakeFileSystemSource() SourceInterface

type Spec

type Spec struct {
	Target string
	User   string
	Group  string
	Perms  os.FileMode
	Vars   Vars
}

Template deployment Spec storage type.

func MakeSpec

func MakeSpec(m util.AnyMap) *Spec

Turns a map into Spec.

func (*Spec) Deploy

func (s *Spec) Deploy(t *Template, base_dir string)

Turns template into the target, setting the permissions/ownership

func (*Spec) Merge

func (s *Spec) Merge(s1 *Spec)

type Specs

type Specs map[string]*Spec

type Template

type Template struct {
	Path    string
	Content string
}

Tempate storage type

func (*Template) Write

func (t *Template) Write(out io.Writer, v Vars)

Feeds the processed template to the writer. Adds "val" funtion to the FuncMap mix, so templates can access variables directly by the name.

type Templates

type Templates map[string]*Template

type Vars

type Vars map[string]string

Variables storage type.

func MakeVars

func MakeVars(vs util.AnyMap) Vars

Turns a map into Vars.

func (Vars) Clone

func (vs Vars) Clone() Vars

func (Vars) Merge

func (vs Vars) Merge(vars ...Vars)

func (Vars) SetMissing

func (vs Vars) SetMissing(vars ...Vars)

type VarsChain

type VarsChain []*VarsLink

func DumpVarsChain

func DumpVarsChain(p *Processor, environment string, tpl string) VarsChain

Marshal Processor sources vars for environment/template into VarsChain

type VarsLink struct {
	Source string
	Vars
}

Helper type for setting up executed vars chains expectations

Jump to

Keyboard shortcuts

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