patch

package
v0.1.48 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSelector = []string{"$"}

Functions

func ValidateValuesFlags

func ValidateValuesFlags(values []string) (map[string]interface{}, []string, []interface{}, error)

ValidateValuesFlags parses the CLI '--values' keys formatted 'key:json-string', into a map. The map will hold the parsed JSON value by the key. The second return value is an array of field names that is supposed to be deleted form the target. Returns an error is value is not a valid JSON string. Important: strings must be quoted;

'--value foo:bar'     is invalid
'--value foo:"bar"'   results in string "bar"
'--value foo:true'    results in boolean true
'--value foo:'        results in deleting key 'foo' if it exists
'--value ["foo"]'     results in appending string "foo" to arrays

Types

type DeckPatch

type DeckPatch struct {
	// Format         string                 // Name of the format specified
	SelectorSources []string               // Source query for the JSONpath object
	Selectors       []*jsonpath.JSONPath   // JSONpath object
	ObjValues       map[string]interface{} // Values to set on target objects
	ArrValues       []interface{}          // Values to set on target arrays
	Remove          []string               // List of keys to remove from the target object

}

DeckPatch models a single DeckPatch that can be applied on a deckfile.

func (*DeckPatch) ApplyToArrayNode added in v0.1.19

func (patch *DeckPatch) ApplyToArrayNode(node *yaml.Node) error

ApplyToArrayNode applies the DeckPatch on a JSONarray. The yaml.Node MUST be of type "SequenceNode" (JSONarray), otherwise it panics.

func (*DeckPatch) ApplyToNodes

func (patch *DeckPatch) ApplyToNodes(yamlData *yaml.Node) (err error)

ApplyToNodes queries the yamlData using the selector, and applies the patch on every Object returned. Any non-objects returned by the selector will be ignored. If Selector wasn't set yet, will try and create it from the SelectorSource.

func (*DeckPatch) ApplyToObjectNode added in v0.1.19

func (patch *DeckPatch) ApplyToObjectNode(node *yaml.Node) error

ApplyToObjectNode applies the DeckPatch on a JSONobject. The yaml.Node MUST be of type "MappingNode" (JSONobject), otherwise it panics.

func (*DeckPatch) Parse

func (patch *DeckPatch) Parse(obj map[string]interface{}, breadCrumb string) (err error)

Parse will parse JSONobject into a DeckPatch. selector is optional, default to "$". If given MUST be a string, and a valid JSONpath. values is optional, defaults to empty map. If given, MUST be an object. remove is optional, defaults to empty array. If given MUST be an array. Non-string entries will be ignored.

type DeckPatchFile

type DeckPatchFile struct {
	VersionMajor int // 0 if not present
	VersionMinor int // 0 if not present
	Patches      []DeckPatch
}

DeckPatchFile represents a list of patches.

func (*DeckPatchFile) Apply

func (patchFile *DeckPatchFile) Apply(yamlData *yaml.Node) error

Apply applies the set of patches on the yaml.Node given.

func (*DeckPatchFile) MustApply

func (patchFile *DeckPatchFile) MustApply(yamlData *yaml.Node, source string)

MustApply applies the set of patches on the yaml.Node given. Same as Apply, but in case of an error it will panic. 'source' will be used to format the error in case of a panic.

func (*DeckPatchFile) ParseFile

func (patchFile *DeckPatchFile) ParseFile(filename string) error

ParseFile parses a patchfile. Any non-object in the 'patches' array will be ignored. If the array doesn't exist, it returns an empty array.

Jump to

Keyboard shortcuts

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