yaml

package
v0.108.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EngineDefault is the default YAML engine.
	EngineDefault = "default"
	// EngineUndefined is the undefined YAML engine.
	EngineUndefined = ""
	// EngineYamlPath is the YAML engine yamlpath.
	EngineYamlPath = "yamlpath"
	// EngineGoYaml is the YAML engine go-yaml.
	EngineGoYaml = "go-yaml"
)

Variables

View Source
var (
	// ErrKeyNotFound is returned when a key is not found in a yaml file
	ErrKeyNotFound = errors.New("key not found")
)

Functions

This section is empty.

Types

type Spec

type Spec struct {
	//"engine" defines the engine to use to manipulate the yaml file.
	//
	//There is no one good Golang library to manipulate yaml files.
	//And each one of them have has its pros and cons so we decided to allow this customization based on user's needs.
	//
	//remark:
	//  * Accepted value is one of "yamlpath", "go-yaml","default" or nothing
	//  * go-yaml, "default" and "" are equivalent
	Engine string `yaml:",omitempty"`
	//"file" defines the yaml file path to interact with.
	//
	//compatible:
	//  * source
	//  * condition
	//  * target
	//
	//remark:
	//  * "file" and "files" are mutually exclusive
	//  * scheme "https://", "http://", and "file://" are supported in path for source and condition
	//
	File string `yaml:",omitempty"`
	//"files" defines the list of yaml files path to interact with.
	//
	//compatible:
	//  * condition
	//  * target
	//
	//remark:
	//  * file and files are mutually exclusive
	//  * protocols "https://", "http://", and "file://" are supported in file path for source and condition
	//
	Files []string `yaml:",omitempty"`
	//"key" defines the yaml keypath.
	//
	//compatible:
	//  * source
	//  * condition
	//  * target
	//
	//remark:
	//  * key is a simpler version of yamlpath accepts keys.
	//
	//example using default engine:
	//  * key: $.name
	//  * key: $.agent.name
	//  * key: $.agents[0].name
	//  * key: $.agents[*].name
	//  * key: $.'agents.name'
	//  * key: $.repos[?(@.repository == 'website')].owner" (require engine set to yamlpath)
	//
	//remark:
	//  field path with key/value is not supported at the moment.
	//  some help would be useful on https://github.com/goccy/go-yaml/issues/290
	//
	Key string `yaml:",omitempty"`
	//"keys" defines multiple yaml keypaths to update with the same value.
	//
	//compatible:
	//  * target
	//
	//remark:
	//  * keys is mutually exclusive with key.
	//  * keys accepts the same syntax as key for each element.
	//  * all keys will be updated with the same value.
	//  * only available for target operations, not for source or condition.
	//
	//example using default engine:
	//  * keys:
	//    - $.image.tag
	//    - $.sidecar.tag
	//  * keys:
	//    - $.agents[0].version
	//    - $.agents[1].version
	//
	Keys []string `yaml:",omitempty"`
	//value is the value associated with a yaml key.
	//
	//compatible:
	//  * source
	//  * condition
	//  * target
	//
	//default:
	//	When used from a condition or a target, the default value is set to the associated source output.
	//
	Value string `yaml:",omitempty"`
	//keyonly allows to check only if a key exist and do not return an error otherwise
	//
	//compatible:
	//	* condition
	//
	//default:
	//	false
	//
	KeyOnly bool `yaml:",omitempty"`
	//searchpattern defines if the MatchPattern should be applied on the file(s) path
	//
	//If set to true, it modifies the behavior of the `file` and `files` attributes to search for files matching the pattern instead of searching for files with the exact name.
	//When looking for file path pattern, it requires pattern to match all of name, not just a substring.
	//
	//The pattern syntax is:
	//
	//“`
	//    pattern:
	//        { term }
	//    term:
	//        '*'         matches any sequence of non-Separator characters
	//        '?'         matches any single non-Separator character
	//        '[' [ '^' ] { character-range } ']'
	//                    character class (must be non-empty)
	//        c           matches character c (c != '*', '?', '\\', '[')
	//        '\\' c      matches character c
	//
	//    character-range:
	//        c           matches character c (c != '\\', '-', ']')
	//        '\\' c      matches character c
	//        lo '-' hi   matches character c for lo <= c <= hi
	//“`
	//
	SearchPattern bool `yaml:",omitempty"`
	//comment defines a comment to add after the value.
	//
	//default: empty
	//
	//compatible:
	//  * target
	//
	//remarks:
	//  * Please note that the comment is added if the value is modified by Updatecli
	//
	Comment string `yaml:",omitempty"`
}

"yaml" defines the specification for manipulating "yaml" files. It can be used as a "source", a "condition", or a "target".

func (*Spec) Validate added in v0.44.0

func (s *Spec) Validate() error

Validate validates the object and returns an error (with all the failed validation messages) if it is not valid

type Yaml

type Yaml struct {
	// contains filtered or unexported fields
}

Yaml defines a resource of kind "yaml"

func New

func New(spec interface{}) (*Yaml, error)

New returns a reference to a newly initialized Yaml object from a Spec or an error if the provided YamlSpec triggers a validation error.

func (*Yaml) Changelog

func (y *Yaml) Changelog(from, to string) *result.Changelogs

Changelog returns the changelog for this resource, or an empty string if not supported

func (*Yaml) Condition

func (y *Yaml) Condition(source string, scm scm.ScmHandler) (pass bool, message string, err error)

Condition checks if a key exists in a yaml file

func (*Yaml) Read

func (y *Yaml) Read() error

Read puts the content of the file(s) as value of the y.files map if the file(s) exist(s) or log the non existence of the file

func (*Yaml) ReportConfig added in v0.99.0

func (y *Yaml) ReportConfig() interface{}

ReportConfig returns a new configuration object with only the necessary fields to identify the resource without any sensitive information or context specific data.

func (*Yaml) Source

func (y *Yaml) Source(workingDir string, resultSource *result.Source) error

Source return the latest version

func (*Yaml) Target

func (y *Yaml) Target(source string, scm scm.ScmHandler, dryRun bool, resultTarget *result.Target) error

Target updates a scm repository based on the modified yaml file.

func (*Yaml) UpdateAbsoluteFilePath added in v0.50.0

func (y *Yaml) UpdateAbsoluteFilePath(workDir string)

Jump to

Keyboard shortcuts

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