config

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2020 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package config defines data structure and logic for loading and refreshing configurations for Honeydipper

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollapseTrigger added in v1.0.0

func CollapseTrigger(t *Trigger, c *DataSet) (*Trigger, *CollapsedTrigger)

CollapseTrigger collapses matching criteria, exports and sysData of a trigger and its inheritted triggers

func ExportFunctionContext added in v1.5.0

func ExportFunctionContext(f *Function, envData map[string]interface{}, cfg *Config) map[string]interface{}

ExportFunctionContext create a context data structure based on the collapsed function exports

func GetGitSSHAuth

func GetGitSSHAuth() transport.AuthMethod

GetGitSSHAuth creates an AuthMethod to be used for various git operations

Types

type Action

type Action struct {
	System   string
	Function string
}

Action is the runtime data representation of an action.

type CollapsedTrigger added in v1.0.0

type CollapsedTrigger struct {
	Match      map[string]interface{}   `json:"match"`
	Exports    []map[string]interface{} `json:"exports"`
	SysData    map[string]interface{}   `json:"sysData"`
	Parameters map[string]interface{}   `json:"parameters"`
}

CollapsedTrigger is a trigger with collapsed matching criteria, parameters, merged sysData and stack of exports

func (*CollapsedTrigger) ExportContext added in v1.0.0

func (t *CollapsedTrigger) ExportContext(eventName string, envData map[string]interface{}) map[string]interface{}

ExportContext putting raw data from event into context as abstracted fields

type Config

type Config struct {
	InitRepo          RepoInfo
	Services          []string
	DataSet           *DataSet
	Loaded            map[RepoInfo]*Repo
	WorkingDir        string
	LastRunningConfig struct {
		DataSet *DataSet
		Loaded  map[RepoInfo]*Repo
	}
	OnChange      func()
	IsConfigCheck bool
	CheckRemote   bool
	IsDocGen      bool
	DocSrc        string
	DocDst        string
}

Config is a wrapper around the final complete configration of the daemon including history and the runtime information

func (*Config) Bootstrap

func (c *Config) Bootstrap(wd string)

Bootstrap loads the configuration during daemon bootstrap. WorkingDir is where git will clone remote repo into.

func (*Config) GetDriverData

func (c *Config) GetDriverData(path string) (ret interface{}, ok bool)

GetDriverData gets an item from a driver's data block.

conn,ok := c.GetDriverData("redis.connection")

The function returns an interface{} that could be anything.

func (*Config) GetDriverDataStr

func (c *Config) GetDriverDataStr(path string) (ret string, ok bool)

GetDriverDataStr gets an item from a driver's data block.

logLevel,ok := c.GetDriverData("daemon.loglevel")

The function assume the return value is a string will do a type assertion upon returning.

func (*Config) Refresh

func (c *Config) Refresh()

Refresh checks remote git remote, reload if changes are detected. It requires that the OnChange variable is defined prior to invoking the function.

func (*Config) RollBack

func (c *Config) RollBack()

RollBack the configuration to the saved last running configuration. It requires that the OnChange variable is defined prior to invoking the function.

func (*Config) Watch

func (c *Config) Watch()

Watch runs a loop to periodically check remote git repo, reload if changes are detected. It requires that the OnChange variable is defined prior to invoking the function.

type DataSet

type DataSet struct {
	Systems   map[string]System
	Rules     []Rule
	Drivers   map[string]interface{}
	Includes  []string
	Repos     []RepoInfo
	Workflows map[string]Workflow
	Contexts  map[string]interface{}
}

DataSet is a subset of configuration that can be assembled to the complete final configuration.

type Error added in v0.1.9

type Error struct {
	Error error
	File  string
}

Error represents a configuration error

type Event

type Event struct {
	System  string
	Trigger string
}

Event is the runtime data representation of an event.

type Function

type Function struct {
	Driver     string
	RawAction  string
	Parameters map[string](interface{})
	// An action should have only one of target action or a raw action.
	Target          Action
	Export          map[string]interface{}
	ExportOnSuccess map[string]interface{} `json:"export_on_success" mapstructure:"export_on_success"`
	ExportOnFailure map[string]interface{} `json:"export_on_failure" mapstructure:"export_on_failure"`
	Description     string
	Meta            interface{}
}

Function is the datastructure hold the information to run actions.

type Repo

type Repo struct {
	DataSet DataSet

	Errors []Error
	// contains filtered or unexported fields
}

Repo contains runtime repo info used to track what has been loaded in a repo.

type RepoInfo

type RepoInfo struct {
	Repo        string
	Branch      string
	Path        string
	Name        string
	Description string
}

RepoInfo points to a git repo where config data can be read from.

type Rule

type Rule struct {
	When Trigger
	Do   Workflow
}

Rule is a data structure defining what action to take when certain event happen.

type System

type System struct {
	Data        map[string](interface{})
	Triggers    map[string]Trigger
	Functions   map[string]Function
	Extends     []string
	Description string
	Meta        interface{}
}

System is an abstract construct to group data, trigger and function definitions.

func SystemCopy

func SystemCopy(s *System) (*System, error)

SystemCopy performs a deep copy of the given system

type Trigger

type Trigger struct {
	Driver     string
	RawEvent   string
	Match      map[string]interface{} `json:"if_match" mapstructure:"if_match"`
	Parameters map[string]interface{}
	// A trigger should have only one of source event a raw event.
	Source      Event
	Export      map[string]interface{}
	Description string
	Meta        interface{}
}

Trigger is the datastructure hold the information to match and process an event.

type Workflow

type Workflow struct {
	Name        string
	Description string
	Meta        interface{}
	Context     string
	Contexts    interface{}
	Local       map[string]interface{} `json:"with" mapstructure:"with"`

	Match       interface{} `json:"if_match" mapstructure:"if_match"`
	UnlessMatch interface{} `json:"unless_match" mapstructure:"unelss_match"`
	WhileMatch  interface{} `json:"while_match" mapstructure:"while_match"`
	UntilMatch  interface{} `json:"until_match" mapstructure:"until_match"`
	If          []string
	IfAny       []string `json:"if_any" mapstructure:"if_any"`
	Unless      []string
	UnlessAll   []string `json:"unless_any" mapstructure:"unless_all"`
	While       []string
	WhileAny    []string `json:"while_any" mapstructure:"while_any"`
	Until       []string
	UntilAll    []string `json:"until_any" mapstructure:"until_all"`

	Else interface{} `json:"else,omitempty"`

	Iterate         interface{}
	IterateParallel interface{} `json:"iterate_parallel" mapstructure:"iterate_parallel"`
	IterateAs       string      `json:"iterate_as" mapstructure:"iterate_as"`

	Retry   string
	Backoff string

	OnError      string `json:"on_error" mapstructure:"on_error"`
	OnFailure    string `json:"on_failure" mapstructure:"on_failure"`
	Workflow     string `json:"call_workflow" mapstructure:"call_workflow"`
	Function     Function
	CallFunction string `json:"call_function" mapstructure:"call_function"`
	CallDriver   string `json:"call_driver" mapstructure:"call_driver"`
	Steps        []Workflow
	Threads      []Workflow
	Wait         string

	Switch  string
	Cases   map[string]interface{}
	Default interface{}

	Export          map[string]interface{}
	ExportOnSuccess map[string]interface{} `json:"export_on_success" mapstructure:"export_on_success"`
	ExportOnFailure map[string]interface{} `json:"export_on_failure" mapstructure:"export_on_failure"`
	NoExport        []string               `json:"no_export" mapstructure:"no_export"`
}

Workflow defines one or more actions needed to complete certain task and how they are orchestrated.

Jump to

Keyboard shortcuts

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