utils

package
v1.0.0-beta.6 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: Apache-2.0 Imports: 21 Imported by: 30

Documentation

Index

Constants

View Source
const (
	GlobalValuesKey = "global"
)

Variables

View Source
var ModuleDisabled = false
View Source
var ModuleEnabled = true

Functions

func CalculateChecksumOfDirectory

func CalculateChecksumOfDirectory(dir string) (string, error)

func CalculateChecksumOfFile

func CalculateChecksumOfFile(path string) (string, error)

func CalculateChecksumOfPaths

func CalculateChecksumOfPaths(paths ...string) (string, error)

func CalculateStringsChecksum

func CalculateStringsChecksum(stringArr ...string) string

func DecodeJsonPatchOperation

func DecodeJsonPatchOperation(v interface{}) (jsonpatch.Operation, error)

func Dump

func Dump(values Values, dumper ValuesDumper) error

func FilesFromRoot

func FilesFromRoot(root string, filterFn func(dir string, name string, info os.FileInfo) bool) (files map[string]map[string]string, err error)

FilesFromRoot returns a map with path and array of files under it

func FindExecutableFilesInPath

func FindExecutableFilesInPath(dir string) (executables []string, nonExecutables []string, err error)

FindExecutableFilesInPath returns a list of executable and a list of non-executable files in path

func JsonPatchFromBytes

func JsonPatchFromBytes(data []byte) (jsonpatch.Patch, error)

func JsonPatchFromReader

func JsonPatchFromReader(r io.Reader) (jsonpatch.Patch, error)

func JsonPatchFromString

func JsonPatchFromString(in string) (jsonpatch.Patch, error)

func LabelsToLogFields

func LabelsToLogFields(labelsMaps ...map[string]string) log.Fields

func ListFullyIn

func ListFullyIn(arr []string, ref []string) bool

ListFullyIn returns whether all 'arr' items contains in `ref` array.

func ListIntersection

func ListIntersection(arrs ...[]string) (result []string)

ListIntersection returns an array with items that are present in all 'arrs' arrays.

func ListSubtract

func ListSubtract(src []string, ignored ...[]string) (result []string)

ListSubtract creates a new array from 'src' array with items that are not present in 'ignored' arrays.

func MergeLabels

func MergeLabels(labelsMaps ...map[string]string) map[string]string

MergeLabels merges several maps into one. Last map keys overrides keys from first maps.

Can be used to copy a map if just one argument is used.

func ModuleNameFromValuesKey

func ModuleNameFromValuesKey(moduleValuesKey string) string

ModuleNameFromValuesKey returns kebab-cased name from camelCased (verySimpleModule become ver-simple-module)

func ModuleNameToValuesKey

func ModuleNameToValuesKey(moduleName string) string

ModuleNameToValuesKey returns camelCased name from kebab-cased (very-simple-module become verySimpleModule)

func SortByReference

func SortByReference(in []string, ref []string) []string

SortByReference returns a new array with items sorted by the order of 'ref' array.

func SortReverse

func SortReverse(in []string) []string

SortReverse creates a copy of 'in' array and sort it in a reverse order.

func SortReverseByReference

func SortReverseByReference(in []string, ref []string) []string

SortReverseByReference returns a new array with items, reverse sorted by the order of 'ref' array.

func SymlinkInfo

func SymlinkInfo(path string, info os.FileInfo) (target string, isDir bool, err error)

func ValidateHookValuesPatch

func ValidateHookValuesPatch(valuesPatch ValuesPatch, acceptableKey string) error
func WalkSymlinks(target string, linkName string, files map[string]map[string]string, filterFn func(dir string, name string, info os.FileInfo) bool) (symlinkedDirectories map[string]string, err error)

WalkSymlinks walks a directory, updates files map and returns symlinked directories

Types

type ModuleConfig

type ModuleConfig struct {
	ModuleName       string
	IsEnabled        *bool
	Values           Values
	IsUpdated        bool
	ModuleConfigKey  string
	ModuleEnabledKey string
	RawConfig        []string
}

func NewModuleConfig

func NewModuleConfig(moduleName string) *ModuleConfig

func (*ModuleConfig) Checksum

func (mc *ModuleConfig) Checksum() string

func (*ModuleConfig) FromConfigMapData

func (mc *ModuleConfig) FromConfigMapData(configData map[string]string) (*ModuleConfig, error)

func (*ModuleConfig) FromYaml

func (mc *ModuleConfig) FromYaml(yamlString []byte) (*ModuleConfig, error)

FromYaml loads module config from a yaml string.

Example:

simpleModule:

param1: 10
param2: 120

simpleModuleEnabled: true

func (*ModuleConfig) GetEnabled

func (mc *ModuleConfig) GetEnabled() string

GetEnabled returns string description of enabled status.

func (*ModuleConfig) LoadFromValues

func (mc *ModuleConfig) LoadFromValues(values Values) (*ModuleConfig, error)

LoadFromValues loads module config from a map.

Values for module in `values` map are addressed by a key. This key should be produced with ModuleNameToValuesKey.

func (ModuleConfig) String

func (mc ModuleConfig) String() string

String returns description of ModuleConfig values.

func (*ModuleConfig) WithEnabled

func (mc *ModuleConfig) WithEnabled(v bool) *ModuleConfig

func (*ModuleConfig) WithUpdated

func (mc *ModuleConfig) WithUpdated(v bool) *ModuleConfig

func (*ModuleConfig) WithValues

func (mc *ModuleConfig) WithValues(values Values) *ModuleConfig

type Values

type Values map[string]interface{}

Values stores values for modules or hooks by name.

func ApplyValuesPatch

func ApplyValuesPatch(values Values, valuesPatch ValuesPatch) (Values, bool, error)

ApplyValuesPatch applies a set of json patch operations to the values and returns a result

func Load

func Load(key string, loader ValuesLoader) (Values, error)

Load values by specific key from loader

func LoadAll

func LoadAll(loader ValuesLoader) (Values, error)

LoadAll loads values from all keys from loader

func MergeValues

func MergeValues(values ...Values) Values

func NewGlobalValues

func NewGlobalValues(globalSectionContent string) (Values, error)

NewGlobalValues creates Values with global section loaded from input string.

func NewValues

func NewValues(data map[string]interface{}) (Values, error)

NewValues load all sections from input data and makes sure that input map can be marshaled to yaml and that yaml is compatible with json.

func NewValuesFromBytes

func NewValuesFromBytes(data []byte) (Values, error)

NewValuesFromBytes loads values sections from maps in yaml or json format

func (Values) AsBytes

func (v Values) AsBytes(format string) ([]byte, error)

func (Values) AsConfigMapData

func (v Values) AsConfigMapData() (map[string]string, error)

AsConfigMapData returns values as map that can be used as a 'data' field in the ConfigMap.

func (Values) AsString

func (v Values) AsString(format string) (string, error)

func (Values) Checksum

func (v Values) Checksum() (string, error)

func (Values) DebugString

func (v Values) DebugString() string

DebugString returns values as yaml or an error line if dump is failed

func (Values) Global

func (v Values) Global() Values

func (Values) HasGlobal

func (v Values) HasGlobal() bool

func (Values) HasKey

func (v Values) HasKey(key string) bool

func (Values) JsonBytes

func (v Values) JsonBytes() ([]byte, error)

func (Values) JsonString

func (v Values) JsonString() (string, error)

func (Values) SectionByKey

func (v Values) SectionByKey(key string) Values

func (Values) YamlBytes

func (v Values) YamlBytes() ([]byte, error)

func (Values) YamlString

func (v Values) YamlString() (string, error)

type ValuesDumper

type ValuesDumper interface {
	Write(values Values) error
}

func NewDumperToJsonFile

func NewDumperToJsonFile(path string) ValuesDumper

type ValuesDumperToJsonFile

type ValuesDumperToJsonFile struct {
	FileName string
}

func (*ValuesDumperToJsonFile) Write

func (*ValuesDumperToJsonFile) Write(values Values) error

type ValuesLoader

type ValuesLoader interface {
	Read() (Values, error)
}

func NewLoaderFromJsonFile

func NewLoaderFromJsonFile(path string) ValuesLoader

type ValuesLoaderFromJsonFile

type ValuesLoaderFromJsonFile struct {
	FileName string
}

func (*ValuesLoaderFromJsonFile) Read

type ValuesPatch

type ValuesPatch struct {
	Operations []*ValuesPatchOperation
}

func AppendValuesPatch

func AppendValuesPatch(valuesPatches []ValuesPatch, newValuesPatch ValuesPatch) []ValuesPatch

func CompactPatches

func CompactPatches(operations []*ValuesPatchOperation) ValuesPatch

CompactPatches simplifies a patches tree — one path, one operation.

func CompactValuesPatches

func CompactValuesPatches(valuesPatches []ValuesPatch, newValuesPatch ValuesPatch) []ValuesPatch

func MustValuesPatch

func MustValuesPatch(res *ValuesPatch, err error) *ValuesPatch

TODO used only in tests

func ValuesPatchFromBytes

func ValuesPatchFromBytes(data []byte) (*ValuesPatch, error)

ValuesPatchFromBytes reads a JSON stream of json patches and single operations from bytes and returns a ValuesPatch with all json patch operations. TODO do we need a separate ValuesPatchOperation type??

func ValuesPatchFromFile

func ValuesPatchFromFile(filePath string) (*ValuesPatch, error)

func (*ValuesPatch) Apply

func (p *ValuesPatch) Apply(doc []byte) ([]byte, error)

Apply calls jsonpatch.Apply to mutate a JSON document according to the patch.

func (*ValuesPatch) ToJsonPatch

func (p *ValuesPatch) ToJsonPatch() (jsonpatch.Patch, error)

type ValuesPatchOperation

type ValuesPatchOperation struct {
	Op    string      `json:"op"`
	Path  string      `json:"path"`
	Value interface{} `json:"value,omitempty"`
}

func (*ValuesPatchOperation) ToString

func (op *ValuesPatchOperation) ToString() string

type ValuesPatchType

type ValuesPatchType string
const ConfigMapPatch ValuesPatchType = "CONFIG_MAP_PATCH"
const MemoryValuesPatch ValuesPatchType = "MEMORY_VALUES_PATCH"

Jump to

Keyboard shortcuts

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