funcs

package
v0.1.0-beta.202310050320 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorMessageFunc = function.New(&function.Spec{
	Description: ` Given a reference to a step, error_message will return a string containing the first error message, if any. If there were no errors, it will return an empty string. This is useful for simple step primitives.`,
	Params: []function.Parameter{
		{
			Name:             "step",
			Type:             cty.DynamicPseudoType,
			AllowUnknown:     true,
			AllowDynamicType: true,
			AllowNull:        true,
		},
	},
	Type: function.StaticReturnType(cty.String),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {

		if len(args) == 0 {
			return cty.StringVal(""), nil
		}

		val := args[0]

		valueMap := val.AsValueMap()
		if valueMap == nil {
			return cty.StringVal(""), nil
		}

		if valueMap["errors"].IsNull() {
			return cty.StringVal(""), nil
		}

		errors := valueMap["errors"].AsValueSlice()
		if len(errors) == 0 {
			return cty.StringVal(""), nil
		}

		firstError := errors[0]
		firstErrorMap := firstError.AsValueMap()

		return firstErrorMap[schema.AttributeTypeMessage], nil
	},
})

error_message: Given a reference to a step, error_message will return a string containing the first error message, if any. If there were no errors, it will return an empty string. This is useful for simple step primitives.

View Source
var IsErrorFunc = function.New(&function.Spec{
	Description: `Given a reference to a step, is_error returns a boolean true if there are 1 or more errors, or false it there are no errors.`,
	Params: []function.Parameter{
		{
			Name:             "step",
			Type:             cty.DynamicPseudoType,
			AllowUnknown:     true,
			AllowDynamicType: true,
			AllowNull:        true,
		},
	},
	Type: function.StaticReturnType(cty.Bool),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		val := args[0]

		valueMap := val.AsValueMap()
		if valueMap == nil {
			return cty.True, nil
		}

		if valueMap["errors"].IsNull() {
			return cty.False, nil
		}

		return cty.True, nil
	},
})

is_error: Given a reference to a step, is_error returns a boolean true if there are 1 or more errors, or false it there are no errors.

Functions

func ContextFunctions

func ContextFunctions(baseDir string) map[string]function.Function

ContextFunctions returns the set of functions that should be used to when evaluating expressions

Types

This section is empty.

Jump to

Keyboard shortcuts

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