updated GHA
Update to v2 SDK updated dependencies
This commit is contained in:
14
vendor/github.com/zclconf/go-cty/cty/msgpack/doc.go
generated
vendored
14
vendor/github.com/zclconf/go-cty/cty/msgpack/doc.go
generated
vendored
@ -1,14 +0,0 @@
|
||||
// Package msgpack provides functions for serializing cty values in the
|
||||
// msgpack encoding, and decoding them again.
|
||||
//
|
||||
// If the same type information is provided both at encoding and decoding time
|
||||
// then values can be round-tripped without loss, except for capsule types
|
||||
// which are not currently supported.
|
||||
//
|
||||
// If any unknown values are passed to Marshal then they will be represented
|
||||
// using a msgpack extension with type code zero, which is understood by
|
||||
// the Unmarshal function within this package but will not be understood by
|
||||
// a generic (non-cty-aware) msgpack decoder. Ensure that no unknown values
|
||||
// are used if interoperability with other msgpack implementations is
|
||||
// required.
|
||||
package msgpack
|
31
vendor/github.com/zclconf/go-cty/cty/msgpack/dynamic.go
generated
vendored
31
vendor/github.com/zclconf/go-cty/cty/msgpack/dynamic.go
generated
vendored
@ -1,31 +0,0 @@
|
||||
package msgpack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/vmihailenco/msgpack/v4"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
type dynamicVal struct {
|
||||
Value cty.Value
|
||||
Path cty.Path
|
||||
}
|
||||
|
||||
func (dv *dynamicVal) MarshalMsgpack() ([]byte, error) {
|
||||
// Rather than defining a msgpack-specific serialization of types,
|
||||
// instead we use the existing JSON serialization.
|
||||
typeJSON, err := dv.Value.Type().MarshalJSON()
|
||||
if err != nil {
|
||||
return nil, dv.Path.NewErrorf("failed to serialize type: %s", err)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
enc := msgpack.NewEncoder(&buf)
|
||||
enc.EncodeArrayLen(2)
|
||||
enc.EncodeBytes(typeJSON)
|
||||
err = marshal(dv.Value, dv.Value.Type(), dv.Path, enc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
8
vendor/github.com/zclconf/go-cty/cty/msgpack/infinity.go
generated
vendored
8
vendor/github.com/zclconf/go-cty/cty/msgpack/infinity.go
generated
vendored
@ -1,8 +0,0 @@
|
||||
package msgpack
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
var negativeInfinity = math.Inf(-1)
|
||||
var positiveInfinity = math.Inf(1)
|
212
vendor/github.com/zclconf/go-cty/cty/msgpack/marshal.go
generated
vendored
212
vendor/github.com/zclconf/go-cty/cty/msgpack/marshal.go
generated
vendored
@ -1,212 +0,0 @@
|
||||
package msgpack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math/big"
|
||||
"sort"
|
||||
|
||||
"github.com/vmihailenco/msgpack/v4"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
"github.com/zclconf/go-cty/cty/convert"
|
||||
)
|
||||
|
||||
// Marshal produces a msgpack serialization of the given value that
|
||||
// can be decoded into the given type later using Unmarshal.
|
||||
//
|
||||
// The given value must conform to the given type, or an error will
|
||||
// be returned.
|
||||
func Marshal(val cty.Value, ty cty.Type) ([]byte, error) {
|
||||
errs := val.Type().TestConformance(ty)
|
||||
if errs != nil {
|
||||
// Attempt a conversion
|
||||
var err error
|
||||
val, err = convert.Convert(val, ty)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// From this point onward, val can be assumed to be conforming to t.
|
||||
|
||||
var path cty.Path
|
||||
var buf bytes.Buffer
|
||||
enc := msgpack.NewEncoder(&buf)
|
||||
enc.UseCompactEncoding(true)
|
||||
|
||||
err := marshal(val, ty, path, enc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func marshal(val cty.Value, ty cty.Type, path cty.Path, enc *msgpack.Encoder) error {
|
||||
if val.IsMarked() {
|
||||
return path.NewErrorf("value has marks, so it cannot be serialized")
|
||||
}
|
||||
|
||||
// If we're going to decode as DynamicPseudoType then we need to save
|
||||
// dynamic type information to recover the real type.
|
||||
if ty == cty.DynamicPseudoType && val.Type() != cty.DynamicPseudoType {
|
||||
return marshalDynamic(val, path, enc)
|
||||
}
|
||||
|
||||
if !val.IsKnown() {
|
||||
err := enc.Encode(unknownVal)
|
||||
if err != nil {
|
||||
return path.NewError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if val.IsNull() {
|
||||
err := enc.EncodeNil()
|
||||
if err != nil {
|
||||
return path.NewError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// The caller should've guaranteed that the given val is conformant with
|
||||
// the given type ty, so we'll proceed under that assumption here.
|
||||
switch {
|
||||
case ty.IsPrimitiveType():
|
||||
switch ty {
|
||||
case cty.String:
|
||||
err := enc.EncodeString(val.AsString())
|
||||
if err != nil {
|
||||
return path.NewError(err)
|
||||
}
|
||||
return nil
|
||||
case cty.Number:
|
||||
var err error
|
||||
switch {
|
||||
case val.RawEquals(cty.PositiveInfinity):
|
||||
err = enc.EncodeFloat64(positiveInfinity)
|
||||
case val.RawEquals(cty.NegativeInfinity):
|
||||
err = enc.EncodeFloat64(negativeInfinity)
|
||||
default:
|
||||
bf := val.AsBigFloat()
|
||||
if iv, acc := bf.Int64(); acc == big.Exact {
|
||||
err = enc.EncodeInt(iv)
|
||||
} else if fv, acc := bf.Float64(); acc == big.Exact {
|
||||
err = enc.EncodeFloat64(fv)
|
||||
} else {
|
||||
err = enc.EncodeString(bf.Text('f', -1))
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return path.NewError(err)
|
||||
}
|
||||
return nil
|
||||
case cty.Bool:
|
||||
err := enc.EncodeBool(val.True())
|
||||
if err != nil {
|
||||
return path.NewError(err)
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
panic("unsupported primitive type")
|
||||
}
|
||||
case ty.IsListType(), ty.IsSetType():
|
||||
enc.EncodeArrayLen(val.LengthInt())
|
||||
ety := ty.ElementType()
|
||||
it := val.ElementIterator()
|
||||
path := append(path, nil) // local override of 'path' with extra element
|
||||
for it.Next() {
|
||||
ek, ev := it.Element()
|
||||
path[len(path)-1] = cty.IndexStep{
|
||||
Key: ek,
|
||||
}
|
||||
err := marshal(ev, ety, path, enc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case ty.IsMapType():
|
||||
enc.EncodeMapLen(val.LengthInt())
|
||||
ety := ty.ElementType()
|
||||
it := val.ElementIterator()
|
||||
path := append(path, nil) // local override of 'path' with extra element
|
||||
for it.Next() {
|
||||
ek, ev := it.Element()
|
||||
path[len(path)-1] = cty.IndexStep{
|
||||
Key: ek,
|
||||
}
|
||||
var err error
|
||||
err = marshal(ek, ek.Type(), path, enc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = marshal(ev, ety, path, enc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case ty.IsTupleType():
|
||||
etys := ty.TupleElementTypes()
|
||||
it := val.ElementIterator()
|
||||
path := append(path, nil) // local override of 'path' with extra element
|
||||
i := 0
|
||||
enc.EncodeArrayLen(len(etys))
|
||||
for it.Next() {
|
||||
ety := etys[i]
|
||||
ek, ev := it.Element()
|
||||
path[len(path)-1] = cty.IndexStep{
|
||||
Key: ek,
|
||||
}
|
||||
err := marshal(ev, ety, path, enc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i++
|
||||
}
|
||||
return nil
|
||||
case ty.IsObjectType():
|
||||
atys := ty.AttributeTypes()
|
||||
path := append(path, nil) // local override of 'path' with extra element
|
||||
|
||||
names := make([]string, 0, len(atys))
|
||||
for k := range atys {
|
||||
names = append(names, k)
|
||||
}
|
||||
sort.Strings(names)
|
||||
|
||||
enc.EncodeMapLen(len(names))
|
||||
|
||||
for _, k := range names {
|
||||
aty := atys[k]
|
||||
av := val.GetAttr(k)
|
||||
path[len(path)-1] = cty.GetAttrStep{
|
||||
Name: k,
|
||||
}
|
||||
var err error
|
||||
err = marshal(cty.StringVal(k), cty.String, path, enc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = marshal(av, aty, path, enc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case ty.IsCapsuleType():
|
||||
return path.NewErrorf("capsule types not supported for msgpack encoding")
|
||||
default:
|
||||
// should never happen
|
||||
return path.NewErrorf("cannot msgpack-serialize %s", ty.FriendlyName())
|
||||
}
|
||||
}
|
||||
|
||||
// marshalDynamic adds an extra wrapping object containing dynamic type
|
||||
// information for the given value.
|
||||
func marshalDynamic(val cty.Value, path cty.Path, enc *msgpack.Encoder) error {
|
||||
dv := dynamicVal{
|
||||
Value: val,
|
||||
Path: path,
|
||||
}
|
||||
return enc.Encode(&dv)
|
||||
}
|
167
vendor/github.com/zclconf/go-cty/cty/msgpack/type_implied.go
generated
vendored
167
vendor/github.com/zclconf/go-cty/cty/msgpack/type_implied.go
generated
vendored
@ -1,167 +0,0 @@
|
||||
package msgpack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/vmihailenco/msgpack/v4"
|
||||
msgpackcodes "github.com/vmihailenco/msgpack/v4/codes"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
// ImpliedType returns the cty Type implied by the structure of the given
|
||||
// msgpack-compliant buffer. This function implements the default type mapping
|
||||
// behavior used when decoding arbitrary msgpack without explicit cty Type
|
||||
// information.
|
||||
//
|
||||
// The rules are as follows:
|
||||
//
|
||||
// msgpack strings, numbers and bools map to their equivalent primitive type in
|
||||
// cty.
|
||||
//
|
||||
// msgpack maps become cty object types, with the attributes defined by the
|
||||
// map keys and the types of their values.
|
||||
//
|
||||
// msgpack arrays become cty tuple types, with the elements defined by the
|
||||
// types of the array members.
|
||||
//
|
||||
// Any nulls are typed as DynamicPseudoType, so callers of this function
|
||||
// must be prepared to deal with this. Callers that do not wish to deal with
|
||||
// dynamic typing should not use this function and should instead describe
|
||||
// their required types explicitly with a cty.Type instance when decoding.
|
||||
//
|
||||
// Any unknown values are similarly typed as DynamicPseudoType, because these
|
||||
// do not carry type information on the wire.
|
||||
//
|
||||
// Any parse errors will be returned as an error, and the type will be the
|
||||
// invalid value cty.NilType.
|
||||
func ImpliedType(buf []byte) (cty.Type, error) {
|
||||
r := bytes.NewReader(buf)
|
||||
dec := msgpack.NewDecoder(r)
|
||||
|
||||
ty, err := impliedType(dec)
|
||||
if err != nil {
|
||||
return cty.NilType, err
|
||||
}
|
||||
|
||||
// We must now be at the end of the buffer
|
||||
err = dec.Skip()
|
||||
if err != io.EOF {
|
||||
return ty, fmt.Errorf("extra bytes after msgpack value")
|
||||
}
|
||||
|
||||
return ty, nil
|
||||
}
|
||||
|
||||
func impliedType(dec *msgpack.Decoder) (cty.Type, error) {
|
||||
// If this function returns with a nil error then it must have already
|
||||
// consumed the next value from the decoder, since when called recursively
|
||||
// the caller will be expecting to find a following value here.
|
||||
|
||||
code, err := dec.PeekCode()
|
||||
if err != nil {
|
||||
return cty.NilType, err
|
||||
}
|
||||
|
||||
switch {
|
||||
|
||||
case code == msgpackcodes.Nil || msgpackcodes.IsExt(code):
|
||||
err := dec.Skip()
|
||||
return cty.DynamicPseudoType, err
|
||||
|
||||
case code == msgpackcodes.True || code == msgpackcodes.False:
|
||||
_, err := dec.DecodeBool()
|
||||
return cty.Bool, err
|
||||
|
||||
case msgpackcodes.IsFixedNum(code):
|
||||
_, err := dec.DecodeInt64()
|
||||
return cty.Number, err
|
||||
|
||||
case code == msgpackcodes.Int8 || code == msgpackcodes.Int16 || code == msgpackcodes.Int32 || code == msgpackcodes.Int64:
|
||||
_, err := dec.DecodeInt64()
|
||||
return cty.Number, err
|
||||
|
||||
case code == msgpackcodes.Uint8 || code == msgpackcodes.Uint16 || code == msgpackcodes.Uint32 || code == msgpackcodes.Uint64:
|
||||
_, err := dec.DecodeUint64()
|
||||
return cty.Number, err
|
||||
|
||||
case code == msgpackcodes.Float || code == msgpackcodes.Double:
|
||||
_, err := dec.DecodeFloat64()
|
||||
return cty.Number, err
|
||||
|
||||
case msgpackcodes.IsString(code):
|
||||
_, err := dec.DecodeString()
|
||||
return cty.String, err
|
||||
|
||||
case msgpackcodes.IsFixedMap(code) || code == msgpackcodes.Map16 || code == msgpackcodes.Map32:
|
||||
return impliedObjectType(dec)
|
||||
|
||||
case msgpackcodes.IsFixedArray(code) || code == msgpackcodes.Array16 || code == msgpackcodes.Array32:
|
||||
return impliedTupleType(dec)
|
||||
|
||||
default:
|
||||
return cty.NilType, fmt.Errorf("unsupported msgpack code %#v", code)
|
||||
}
|
||||
}
|
||||
|
||||
func impliedObjectType(dec *msgpack.Decoder) (cty.Type, error) {
|
||||
// If we get in here then we've already peeked the next code and know
|
||||
// it's some sort of map.
|
||||
l, err := dec.DecodeMapLen()
|
||||
if err != nil {
|
||||
return cty.DynamicPseudoType, nil
|
||||
}
|
||||
|
||||
var atys map[string]cty.Type
|
||||
|
||||
for i := 0; i < l; i++ {
|
||||
// Read the map key first. We require maps to be strings, but msgpack
|
||||
// doesn't so we're prepared to error here if not.
|
||||
k, err := dec.DecodeString()
|
||||
if err != nil {
|
||||
return cty.DynamicPseudoType, err
|
||||
}
|
||||
|
||||
aty, err := impliedType(dec)
|
||||
if err != nil {
|
||||
return cty.DynamicPseudoType, err
|
||||
}
|
||||
|
||||
if atys == nil {
|
||||
atys = make(map[string]cty.Type)
|
||||
}
|
||||
atys[k] = aty
|
||||
}
|
||||
|
||||
if len(atys) == 0 {
|
||||
return cty.EmptyObject, nil
|
||||
}
|
||||
|
||||
return cty.Object(atys), nil
|
||||
}
|
||||
|
||||
func impliedTupleType(dec *msgpack.Decoder) (cty.Type, error) {
|
||||
// If we get in here then we've already peeked the next code and know
|
||||
// it's some sort of array.
|
||||
l, err := dec.DecodeArrayLen()
|
||||
if err != nil {
|
||||
return cty.DynamicPseudoType, nil
|
||||
}
|
||||
|
||||
if l == 0 {
|
||||
return cty.EmptyTuple, nil
|
||||
}
|
||||
|
||||
etys := make([]cty.Type, l)
|
||||
|
||||
for i := 0; i < l; i++ {
|
||||
ety, err := impliedType(dec)
|
||||
if err != nil {
|
||||
return cty.DynamicPseudoType, err
|
||||
}
|
||||
etys[i] = ety
|
||||
}
|
||||
|
||||
return cty.Tuple(etys), nil
|
||||
}
|
16
vendor/github.com/zclconf/go-cty/cty/msgpack/unknown.go
generated
vendored
16
vendor/github.com/zclconf/go-cty/cty/msgpack/unknown.go
generated
vendored
@ -1,16 +0,0 @@
|
||||
package msgpack
|
||||
|
||||
type unknownType struct{}
|
||||
|
||||
var unknownVal = unknownType{}
|
||||
|
||||
// unknownValBytes is the raw bytes of the msgpack fixext1 value we
|
||||
// write to represent an unknown value. It's an extension value of
|
||||
// type zero whose value is irrelevant. Since it's irrelevant, we
|
||||
// set it to a single byte whose value is also zero, since that's
|
||||
// the most compact possible representation.
|
||||
var unknownValBytes = []byte{0xd4, 0, 0}
|
||||
|
||||
func (uv unknownType) MarshalMsgpack() ([]byte, error) {
|
||||
return unknownValBytes, nil
|
||||
}
|
334
vendor/github.com/zclconf/go-cty/cty/msgpack/unmarshal.go
generated
vendored
334
vendor/github.com/zclconf/go-cty/cty/msgpack/unmarshal.go
generated
vendored
@ -1,334 +0,0 @@
|
||||
package msgpack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/vmihailenco/msgpack/v4"
|
||||
msgpackCodes "github.com/vmihailenco/msgpack/v4/codes"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
// Unmarshal interprets the given bytes as a msgpack-encoded cty Value of
|
||||
// the given type, returning the result.
|
||||
//
|
||||
// If an error is returned, the error is written with a hypothetical
|
||||
// end-user that wrote the msgpack file as its audience, using cty type
|
||||
// system concepts rather than Go type system concepts.
|
||||
func Unmarshal(b []byte, ty cty.Type) (cty.Value, error) {
|
||||
r := bytes.NewReader(b)
|
||||
dec := msgpack.NewDecoder(r)
|
||||
|
||||
var path cty.Path
|
||||
return unmarshal(dec, ty, path)
|
||||
}
|
||||
|
||||
func unmarshal(dec *msgpack.Decoder, ty cty.Type, path cty.Path) (cty.Value, error) {
|
||||
peek, err := dec.PeekCode()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewError(err)
|
||||
}
|
||||
if msgpackCodes.IsExt(peek) {
|
||||
// We just assume _all_ extensions are unknown values,
|
||||
// since we don't have any other extensions.
|
||||
dec.Skip() // skip what we've peeked
|
||||
return cty.UnknownVal(ty), nil
|
||||
}
|
||||
if ty == cty.DynamicPseudoType {
|
||||
return unmarshalDynamic(dec, path)
|
||||
}
|
||||
if peek == msgpackCodes.Nil {
|
||||
dec.Skip() // skip what we've peeked
|
||||
return cty.NullVal(ty), nil
|
||||
}
|
||||
|
||||
switch {
|
||||
case ty.IsPrimitiveType():
|
||||
val, err := unmarshalPrimitive(dec, ty, path)
|
||||
if err != nil {
|
||||
return cty.NilVal, err
|
||||
}
|
||||
return val, nil
|
||||
case ty.IsListType():
|
||||
return unmarshalList(dec, ty.ElementType(), path)
|
||||
case ty.IsSetType():
|
||||
return unmarshalSet(dec, ty.ElementType(), path)
|
||||
case ty.IsMapType():
|
||||
return unmarshalMap(dec, ty.ElementType(), path)
|
||||
case ty.IsTupleType():
|
||||
return unmarshalTuple(dec, ty.TupleElementTypes(), path)
|
||||
case ty.IsObjectType():
|
||||
return unmarshalObject(dec, ty.AttributeTypes(), path)
|
||||
default:
|
||||
return cty.NilVal, path.NewErrorf("unsupported type %s", ty.FriendlyName())
|
||||
}
|
||||
}
|
||||
|
||||
func unmarshalPrimitive(dec *msgpack.Decoder, ty cty.Type, path cty.Path) (cty.Value, error) {
|
||||
switch ty {
|
||||
case cty.Bool:
|
||||
rv, err := dec.DecodeBool()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("bool is required")
|
||||
}
|
||||
return cty.BoolVal(rv), nil
|
||||
case cty.Number:
|
||||
// Marshal will try int and float first, if the value can be
|
||||
// losslessly represented in these encodings, and then fall
|
||||
// back on a string if the number is too large or too precise.
|
||||
peek, err := dec.PeekCode()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("number is required")
|
||||
}
|
||||
|
||||
if msgpackCodes.IsFixedNum(peek) {
|
||||
rv, err := dec.DecodeInt64()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("number is required")
|
||||
}
|
||||
return cty.NumberIntVal(rv), nil
|
||||
}
|
||||
|
||||
switch peek {
|
||||
case msgpackCodes.Int8, msgpackCodes.Int16, msgpackCodes.Int32, msgpackCodes.Int64:
|
||||
rv, err := dec.DecodeInt64()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("number is required")
|
||||
}
|
||||
return cty.NumberIntVal(rv), nil
|
||||
case msgpackCodes.Uint8, msgpackCodes.Uint16, msgpackCodes.Uint32, msgpackCodes.Uint64:
|
||||
rv, err := dec.DecodeUint64()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("number is required")
|
||||
}
|
||||
return cty.NumberUIntVal(rv), nil
|
||||
case msgpackCodes.Float, msgpackCodes.Double:
|
||||
rv, err := dec.DecodeFloat64()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("number is required")
|
||||
}
|
||||
return cty.NumberFloatVal(rv), nil
|
||||
default:
|
||||
rv, err := dec.DecodeString()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("number is required")
|
||||
}
|
||||
v, err := cty.ParseNumberVal(rv)
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("number is required")
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
case cty.String:
|
||||
rv, err := dec.DecodeString()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("string is required")
|
||||
}
|
||||
return cty.StringVal(rv), nil
|
||||
default:
|
||||
// should never happen
|
||||
panic("unsupported primitive type")
|
||||
}
|
||||
}
|
||||
|
||||
func unmarshalList(dec *msgpack.Decoder, ety cty.Type, path cty.Path) (cty.Value, error) {
|
||||
length, err := dec.DecodeArrayLen()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("a list is required")
|
||||
}
|
||||
|
||||
switch {
|
||||
case length < 0:
|
||||
return cty.NullVal(cty.List(ety)), nil
|
||||
case length == 0:
|
||||
return cty.ListValEmpty(ety), nil
|
||||
}
|
||||
|
||||
vals := make([]cty.Value, 0, length)
|
||||
path = append(path, nil)
|
||||
for i := 0; i < length; i++ {
|
||||
path[len(path)-1] = cty.IndexStep{
|
||||
Key: cty.NumberIntVal(int64(i)),
|
||||
}
|
||||
|
||||
val, err := unmarshal(dec, ety, path)
|
||||
if err != nil {
|
||||
return cty.DynamicVal, err
|
||||
}
|
||||
|
||||
vals = append(vals, val)
|
||||
}
|
||||
|
||||
return cty.ListVal(vals), nil
|
||||
}
|
||||
|
||||
func unmarshalSet(dec *msgpack.Decoder, ety cty.Type, path cty.Path) (cty.Value, error) {
|
||||
length, err := dec.DecodeArrayLen()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("a set is required")
|
||||
}
|
||||
|
||||
switch {
|
||||
case length < 0:
|
||||
return cty.NullVal(cty.Set(ety)), nil
|
||||
case length == 0:
|
||||
return cty.SetValEmpty(ety), nil
|
||||
}
|
||||
|
||||
vals := make([]cty.Value, 0, length)
|
||||
path = append(path, nil)
|
||||
for i := 0; i < length; i++ {
|
||||
path[len(path)-1] = cty.IndexStep{
|
||||
Key: cty.NumberIntVal(int64(i)),
|
||||
}
|
||||
|
||||
val, err := unmarshal(dec, ety, path)
|
||||
if err != nil {
|
||||
return cty.DynamicVal, err
|
||||
}
|
||||
|
||||
vals = append(vals, val)
|
||||
}
|
||||
|
||||
return cty.SetVal(vals), nil
|
||||
}
|
||||
|
||||
func unmarshalMap(dec *msgpack.Decoder, ety cty.Type, path cty.Path) (cty.Value, error) {
|
||||
length, err := dec.DecodeMapLen()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("a map is required")
|
||||
}
|
||||
|
||||
switch {
|
||||
case length < 0:
|
||||
return cty.NullVal(cty.Map(ety)), nil
|
||||
case length == 0:
|
||||
return cty.MapValEmpty(ety), nil
|
||||
}
|
||||
|
||||
vals := make(map[string]cty.Value, length)
|
||||
path = append(path, nil)
|
||||
for i := 0; i < length; i++ {
|
||||
key, err := dec.DecodeString()
|
||||
if err != nil {
|
||||
path[:len(path)-1].NewErrorf("non-string key in map")
|
||||
}
|
||||
|
||||
path[len(path)-1] = cty.IndexStep{
|
||||
Key: cty.StringVal(key),
|
||||
}
|
||||
|
||||
val, err := unmarshal(dec, ety, path)
|
||||
if err != nil {
|
||||
return cty.DynamicVal, err
|
||||
}
|
||||
|
||||
vals[key] = val
|
||||
}
|
||||
|
||||
return cty.MapVal(vals), nil
|
||||
}
|
||||
|
||||
func unmarshalTuple(dec *msgpack.Decoder, etys []cty.Type, path cty.Path) (cty.Value, error) {
|
||||
length, err := dec.DecodeArrayLen()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("a tuple is required")
|
||||
}
|
||||
|
||||
switch {
|
||||
case length < 0:
|
||||
return cty.NullVal(cty.Tuple(etys)), nil
|
||||
case length == 0:
|
||||
return cty.TupleVal(nil), nil
|
||||
case length != len(etys):
|
||||
return cty.DynamicVal, path.NewErrorf("a tuple of length %d is required", len(etys))
|
||||
}
|
||||
|
||||
vals := make([]cty.Value, 0, length)
|
||||
path = append(path, nil)
|
||||
for i := 0; i < length; i++ {
|
||||
path[len(path)-1] = cty.IndexStep{
|
||||
Key: cty.NumberIntVal(int64(i)),
|
||||
}
|
||||
ety := etys[i]
|
||||
|
||||
val, err := unmarshal(dec, ety, path)
|
||||
if err != nil {
|
||||
return cty.DynamicVal, err
|
||||
}
|
||||
|
||||
vals = append(vals, val)
|
||||
}
|
||||
|
||||
return cty.TupleVal(vals), nil
|
||||
}
|
||||
|
||||
func unmarshalObject(dec *msgpack.Decoder, atys map[string]cty.Type, path cty.Path) (cty.Value, error) {
|
||||
length, err := dec.DecodeMapLen()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewErrorf("an object is required")
|
||||
}
|
||||
|
||||
switch {
|
||||
case length < 0:
|
||||
return cty.NullVal(cty.Object(atys)), nil
|
||||
case length == 0:
|
||||
return cty.ObjectVal(nil), nil
|
||||
case length != len(atys):
|
||||
return cty.DynamicVal, path.NewErrorf("an object with %d attributes is required (%d given)",
|
||||
len(atys), length)
|
||||
}
|
||||
|
||||
vals := make(map[string]cty.Value, length)
|
||||
path = append(path, nil)
|
||||
for i := 0; i < length; i++ {
|
||||
key, err := dec.DecodeString()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path[:len(path)-1].NewErrorf("all keys must be strings")
|
||||
}
|
||||
|
||||
path[len(path)-1] = cty.IndexStep{
|
||||
Key: cty.StringVal(key),
|
||||
}
|
||||
aty, exists := atys[key]
|
||||
if !exists {
|
||||
return cty.DynamicVal, path.NewErrorf("unsupported attribute")
|
||||
}
|
||||
|
||||
val, err := unmarshal(dec, aty, path)
|
||||
if err != nil {
|
||||
return cty.DynamicVal, err
|
||||
}
|
||||
|
||||
vals[key] = val
|
||||
}
|
||||
|
||||
return cty.ObjectVal(vals), nil
|
||||
}
|
||||
|
||||
func unmarshalDynamic(dec *msgpack.Decoder, path cty.Path) (cty.Value, error) {
|
||||
length, err := dec.DecodeArrayLen()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewError(err)
|
||||
}
|
||||
|
||||
switch {
|
||||
case length == -1:
|
||||
return cty.NullVal(cty.DynamicPseudoType), nil
|
||||
case length != 2:
|
||||
return cty.DynamicVal, path.NewErrorf(
|
||||
"dynamic value array must have exactly two elements",
|
||||
)
|
||||
}
|
||||
|
||||
typeJSON, err := dec.DecodeBytes()
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewError(err)
|
||||
}
|
||||
var ty cty.Type
|
||||
err = (&ty).UnmarshalJSON(typeJSON)
|
||||
if err != nil {
|
||||
return cty.DynamicVal, path.NewError(err)
|
||||
}
|
||||
|
||||
return unmarshal(dec, ty, path)
|
||||
}
|
Reference in New Issue
Block a user