vendor: update github.com/hashicorp/hcl/v2 to v2.19.1

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-10-19 14:49:10 +02:00
parent ad674e2666
commit 34b9a629a0
157 changed files with 20123 additions and 5438 deletions

View File

@ -12,6 +12,7 @@ import (
)
var HasIndexFunc = function.New(&function.Spec{
Description: `Returns true if if the given collection can be indexed with the given key without producing an error, or false otherwise.`,
Params: []function.Parameter{
{
Name: "collection",
@ -31,12 +32,14 @@ var HasIndexFunc = function.New(&function.Spec{
}
return cty.Bool, nil
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
return args[0].HasIndex(args[1]), nil
},
})
var IndexFunc = function.New(&function.Spec{
Description: `Returns the element with the given key from the given collection, or raises an error if there is no such element.`,
Params: []function.Parameter{
{
Name: "collection",
@ -106,11 +109,13 @@ var IndexFunc = function.New(&function.Spec{
})
var LengthFunc = function.New(&function.Spec{
Description: `Returns the number of elements in the given collection.`,
Params: []function.Parameter{
{
Name: "collection",
Type: cty.DynamicPseudoType,
AllowDynamicType: true,
AllowUnknown: true,
AllowMarked: true,
},
},
@ -121,12 +126,14 @@ var LengthFunc = function.New(&function.Spec{
}
return cty.Number, nil
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
return args[0].Length(), nil
},
})
var ElementFunc = function.New(&function.Spec{
Description: `Returns the element with the given index from the given list or tuple, applying the modulo operation to the given index if it's greater than the number of elements.`,
Params: []function.Parameter{
{
Name: "list",
@ -206,9 +213,11 @@ var ElementFunc = function.New(&function.Spec{
// CoalesceListFunc is a function that takes any number of list arguments
// and returns the first one that isn't empty.
var CoalesceListFunc = function.New(&function.Spec{
Params: []function.Parameter{},
Description: `Returns the first of the given sequences that has a length greater than zero.`,
Params: []function.Parameter{},
VarParam: &function.Parameter{
Name: "vals",
Description: `List or tuple values to test in the given order.`,
Type: cty.DynamicPseudoType,
AllowUnknown: true,
AllowDynamicType: true,
@ -245,6 +254,7 @@ var CoalesceListFunc = function.New(&function.Spec{
return last, nil
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
for _, arg := range args {
if !arg.IsKnown() {
@ -270,13 +280,15 @@ var CoalesceListFunc = function.New(&function.Spec{
// CompactFunc is a function that takes a list of strings and returns a new list
// with any empty string elements removed.
var CompactFunc = function.New(&function.Spec{
Description: `Removes all empty string elements from the given list of strings.`,
Params: []function.Parameter{
{
Name: "list",
Type: cty.List(cty.String),
},
},
Type: function.StaticReturnType(cty.List(cty.String)),
Type: function.StaticReturnType(cty.List(cty.String)),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
listVal := args[0]
if !listVal.IsWhollyKnown() {
@ -306,6 +318,7 @@ var CompactFunc = function.New(&function.Spec{
// ContainsFunc is a function that determines whether a given list or
// set contains a given single value as one of its elements.
var ContainsFunc = function.New(&function.Spec{
Description: `Returns true if the given value is a value in the given list, tuple, or set, or false otherwise.`,
Params: []function.Parameter{
{
Name: "list",
@ -316,7 +329,8 @@ var ContainsFunc = function.New(&function.Spec{
Type: cty.DynamicPseudoType,
},
},
Type: function.StaticReturnType(cty.Bool),
Type: function.StaticReturnType(cty.Bool),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
arg := args[0]
ty := arg.Type()
@ -364,6 +378,7 @@ var ContainsFunc = function.New(&function.Spec{
// DistinctFunc is a function that takes a list and returns a new list
// with any duplicate elements removed.
var DistinctFunc = function.New(&function.Spec{
Description: `Removes any duplicate values from the given list, preserving the order of remaining elements.`,
Params: []function.Parameter{
{
Name: "list",
@ -373,6 +388,7 @@ var DistinctFunc = function.New(&function.Spec{
Type: func(args []cty.Value) (cty.Type, error) {
return args[0].Type(), nil
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
listVal := args[0]
@ -399,14 +415,17 @@ var DistinctFunc = function.New(&function.Spec{
// ChunklistFunc is a function that splits a single list into fixed-size chunks,
// returning a list of lists.
var ChunklistFunc = function.New(&function.Spec{
Description: `Splits a single list into multiple lists where each has at most the given number of elements.`,
Params: []function.Parameter{
{
Name: "list",
Description: `The list to split into chunks.`,
Type: cty.List(cty.DynamicPseudoType),
AllowMarked: true,
},
{
Name: "size",
Description: `The maximum length of each chunk. All but the last element of the result is guaranteed to be of exactly this size.`,
Type: cty.Number,
AllowMarked: true,
},
@ -414,6 +433,7 @@ var ChunklistFunc = function.New(&function.Spec{
Type: func(args []cty.Value) (cty.Type, error) {
return cty.List(args[0].Type()), nil
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
listVal := args[0]
sizeVal := args[1]
@ -471,6 +491,7 @@ var ChunklistFunc = function.New(&function.Spec{
// FlattenFunc is a function that takes a list and replaces any elements
// that are lists with a flattened sequence of the list contents.
var FlattenFunc = function.New(&function.Spec{
Description: `Transforms a list, set, or tuple value into a tuple by replacing any given elements that are themselves sequences with a flattened tuple of all of the nested elements concatenated together.`,
Params: []function.Parameter{
{
Name: "list",
@ -500,6 +521,7 @@ var FlattenFunc = function.New(&function.Spec{
}
return cty.Tuple(tys), nil
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
inputList := args[0]
@ -525,6 +547,7 @@ func flattener(flattenList cty.Value) ([]cty.Value, []cty.ValueMarks, bool) {
if len(flattenListMarks) > 0 {
markses = append(markses, flattenListMarks)
}
if !flattenList.Length().IsKnown() {
// If we don't know the length of what we're flattening then we can't
// predict the length of our result yet either.
@ -542,7 +565,7 @@ func flattener(flattenList cty.Value) ([]cty.Value, []cty.ValueMarks, bool) {
isKnown = false
}
if val.Type().IsListType() || val.Type().IsSetType() || val.Type().IsTupleType() {
if !val.IsNull() && (val.Type().IsListType() || val.Type().IsSetType() || val.Type().IsTupleType()) {
if !val.IsKnown() {
isKnown = false
_, unknownMarks := val.Unmark()
@ -566,9 +589,11 @@ func flattener(flattenList cty.Value) ([]cty.Value, []cty.ValueMarks, bool) {
// KeysFunc is a function that takes a map and returns a sorted list of the map keys.
var KeysFunc = function.New(&function.Spec{
Description: `Returns a list of the keys of the given map in lexicographical order.`,
Params: []function.Parameter{
{
Name: "inputMap",
Description: `The map to extract keys from. May instead be an object-typed value, in which case the result is a tuple of the object attributes.`,
Type: cty.DynamicPseudoType,
AllowUnknown: true,
AllowMarked: true,
@ -595,6 +620,7 @@ var KeysFunc = function.New(&function.Spec{
return cty.DynamicPseudoType, function.NewArgErrorf(0, "must have map or object type")
}
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
// We must unmark the value before we can use ElementIterator on it, and
// then re-apply the same marks (possibly none) when we return. Since we
@ -641,6 +667,7 @@ var KeysFunc = function.New(&function.Spec{
// LookupFunc is a function that performs dynamic lookups of map types.
var LookupFunc = function.New(&function.Spec{
Description: `Returns the value of the element with the given key from the given map, or returns the default value if there is no such element.`,
Params: []function.Parameter{
{
Name: "inputMap",
@ -733,7 +760,8 @@ var LookupFunc = function.New(&function.Spec{
// If more than one given map or object defines the same key then the one that
// is later in the argument sequence takes precedence.
var MergeFunc = function.New(&function.Spec{
Params: []function.Parameter{},
Description: `Merges all of the elements from the given maps into a single map, or the attributes from given objects into a single object.`,
Params: []function.Parameter{},
VarParam: &function.Parameter{
Name: "maps",
Type: cty.DynamicPseudoType,
@ -814,6 +842,7 @@ var MergeFunc = function.New(&function.Spec{
return cty.Object(attrs), nil
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
outputMap := make(map[string]cty.Value)
var markses []cty.ValueMarks // remember any marked maps/objects we find
@ -849,6 +878,7 @@ var MergeFunc = function.New(&function.Spec{
// ReverseListFunc takes a sequence and produces a new sequence of the same length
// with all of the same elements as the given sequence but in reverse order.
var ReverseListFunc = function.New(&function.Spec{
Description: `Returns the given list with its elements in reverse order.`,
Params: []function.Parameter{
{
Name: "list",
@ -872,6 +902,7 @@ var ReverseListFunc = function.New(&function.Spec{
return cty.NilType, function.NewArgErrorf(0, "can only reverse list or tuple values, not %s", argTy.FriendlyName())
}
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
in, marks := args[0].Unmark()
inVals := in.AsValueSlice()
@ -897,11 +928,14 @@ var ReverseListFunc = function.New(&function.Spec{
// preserving the ordering of all of the input lists. Otherwise the result is a
// set of tuples.
var SetProductFunc = function.New(&function.Spec{
Params: []function.Parameter{},
Description: `Calculates the cartesian product of two or more sets.`,
Params: []function.Parameter{},
VarParam: &function.Parameter{
Name: "sets",
Type: cty.DynamicPseudoType,
AllowMarked: true,
Name: "sets",
Description: "The sets to consider. Also accepts lists and tuples, and if all arguments are of list or tuple type then the result will preserve the input ordering",
Type: cty.DynamicPseudoType,
AllowMarked: true,
AllowUnknown: true,
},
Type: func(args []cty.Value) (retType cty.Type, err error) {
if len(args) < 2 {
@ -943,6 +977,7 @@ var SetProductFunc = function.New(&function.Spec{
}
return cty.Set(cty.Tuple(elemTys)), nil
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
ety := retType.ElementType()
var retMarks cty.ValueMarks
@ -955,7 +990,7 @@ var SetProductFunc = function.New(&function.Spec{
// Continue processing after we find an argument with unknown
// length to ensure that we cover all the marks
if !arg.Length().IsKnown() {
if !(arg.IsKnown() && arg.Length().IsKnown()) {
hasUnknownLength = true
continue
}
@ -967,7 +1002,62 @@ var SetProductFunc = function.New(&function.Spec{
}
if hasUnknownLength {
return cty.UnknownVal(retType).WithMarks(retMarks), nil
defer func() {
// We're definitely going to return from somewhere in this
// branch and however we do it we must reapply the marks
// on the way out.
ret = ret.WithMarks(retMarks)
}()
ret := cty.UnknownVal(retType)
// Even if we don't know the exact length we may be able to
// constrain the upper and lower bounds of the resulting length.
maxLength := 1
for _, arg := range args {
arg, _ := arg.Unmark() // safe to discard marks because "retMarks" already contains them all
argRng := arg.Range()
ty := argRng.TypeConstraint()
var argMaxLen int
if ty.IsCollectionType() {
argMaxLen = argRng.LengthUpperBound()
} else if ty.IsTupleType() {
argMaxLen = ty.Length()
} else {
// Should not get here but if we do then we'll just
// bail out with an unrefined unknown value.
return ret, nil
}
// The upper bound of a totally-unrefined collection is
// math.MaxInt, which will quickly get us to integer overflow
// here, and so out of pragmatism we'll just impose a reasonable
// upper limit on what is a useful bound to track and return
// unrefined for unusually-large input.
if argMaxLen > 1024 { // arbitrarily-decided threshold
return ret, nil
}
maxLength *= argMaxLen
if maxLength > 2048 { // arbitrarily-decided threshold
return ret, nil
}
if maxLength < 0 { // Seems like we already overflowed, then.
return ret, nil
}
}
if maxLength == 0 {
// This refinement will typically allow the unknown value to
// collapse into a known empty collection.
ret = ret.Refine().CollectionLength(0).NewValue()
} else {
// If we know there's a nonzero maximum number of elements then
// set element coalescing cannot reduce to fewer than one
// element.
ret = ret.Refine().
CollectionLengthLowerBound(1).
CollectionLengthUpperBound(maxLength).
NewValue()
}
return ret, nil
}
if total == 0 {
@ -1037,6 +1127,7 @@ var SetProductFunc = function.New(&function.Spec{
// SliceFunc is a function that extracts some consecutive elements
// from within a list.
var SliceFunc = function.New(&function.Spec{
Description: `Extracts a subslice of the given list or tuple value.`,
Params: []function.Parameter{
{
Name: "list",
@ -1079,6 +1170,7 @@ var SliceFunc = function.New(&function.Spec{
}
return cty.Tuple(argTy.TupleElementTypes()[startIndex:endIndex]), nil
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
inputList, marks := args[0].Unmark()
@ -1158,9 +1250,10 @@ func sliceIndexes(args []cty.Value) (int, int, bool, error) {
// ValuesFunc is a function that returns a list of the map values,
// in the order of the sorted keys.
var ValuesFunc = function.New(&function.Spec{
Description: `Returns the values of elements of a given map, or the values of attributes of a given object, in lexicographic order by key or attribute name.`,
Params: []function.Parameter{
{
Name: "values",
Name: "mapping",
Type: cty.DynamicPseudoType,
AllowMarked: true,
},
@ -1192,6 +1285,7 @@ var ValuesFunc = function.New(&function.Spec{
}
return cty.NilType, errors.New("values() requires a map as the first argument")
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
mapVar := args[0]
@ -1225,6 +1319,7 @@ var ValuesFunc = function.New(&function.Spec{
// ZipmapFunc is a function that constructs a map from a list of keys
// and a corresponding list of values.
var ZipmapFunc = function.New(&function.Spec{
Description: `Constructs a map from a list of keys and a corresponding list of values, which must both be of the same length.`,
Params: []function.Parameter{
{
Name: "keys",
@ -1279,6 +1374,7 @@ var ZipmapFunc = function.New(&function.Spec{
return cty.NilType, errors.New("values argument must be a list or tuple value")
}
},
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
keys := args[0]
values := args[1]