funcs

package
v1.3.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnvFunc = function.New(&function.Spec{
	Description: `Get environment variable`,
	Params: []function.Parameter{
		{
			Name: "key",
			Type: cty.String,
		},
	},
	Type: function.StaticReturnType(cty.String),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		key := args[0].AsString()

		value, exists := os.LookupEnv(key)

		if !exists {
			return cty.StringVal(""), nil
		}

		return cty.StringVal(value), 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.

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()

		perr := firstErrorMap["error"]
		if perr.IsNull() {
			return cty.StringVal(""), nil
		}

		perrMap := perr.AsValueMap()
		return perrMap["detail"], 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) {
		if len(args) == 0 {
			return cty.False, nil
		}

		val := args[0]

		if val.IsNull() {
			return cty.False, nil
		}

		if !val.Type().IsMapType() && !val.Type().IsObjectType() {
			return cty.False, nil
		}

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

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

		if valueMap["errors"].Type().IsListType() && valueMap["errors"].Type().IsSetType() {
			return cty.False, nil
		}

		errorSlice := valueMap["errors"].AsValueSlice()
		if errorSlice == nil {
			return cty.False, nil
		}

		if len(errorSlice) == 0 {
			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