govendor fetch github.com/zclconf/go-cty/cty/...
This includes upstream fixes, and in particular a converter for going between map types with different element types.
This commit is contained in:
parent
d9a26bae26
commit
f8a8f26c0d
|
@ -93,6 +93,15 @@ func getConversionKnown(in cty.Type, out cty.Type, unsafe bool) conversion {
|
|||
}
|
||||
return conversionCollectionToSet(outEty, convEty)
|
||||
|
||||
case out.IsMapType() && in.IsMapType():
|
||||
inEty := in.ElementType()
|
||||
outEty := out.ElementType()
|
||||
convEty := getConversion(inEty, outEty, unsafe)
|
||||
if convEty == nil {
|
||||
return nil
|
||||
}
|
||||
return conversionCollectionToMap(outEty, convEty)
|
||||
|
||||
case out.IsListType() && in.IsTupleType():
|
||||
outEty := out.ElementType()
|
||||
return conversionTupleToList(in, outEty, unsafe)
|
||||
|
|
|
@ -84,6 +84,50 @@ func conversionCollectionToSet(ety cty.Type, conv conversion) conversion {
|
|||
}
|
||||
}
|
||||
|
||||
// conversionCollectionToMap returns a conversion that will apply the given
|
||||
// conversion to all of the elements of a collection (something that supports
|
||||
// ForEachElement and LengthInt) and then returns the result as a map.
|
||||
//
|
||||
// "conv" can be nil if the elements are expected to already be of the
|
||||
// correct type and just need to be re-wrapped into a map.
|
||||
func conversionCollectionToMap(ety cty.Type, conv conversion) conversion {
|
||||
return func(val cty.Value, path cty.Path) (cty.Value, error) {
|
||||
elems := make(map[string]cty.Value, 0)
|
||||
path = append(path, nil)
|
||||
it := val.ElementIterator()
|
||||
for it.Next() {
|
||||
key, val := it.Element()
|
||||
var err error
|
||||
|
||||
path[len(path)-1] = cty.IndexStep{
|
||||
Key: key,
|
||||
}
|
||||
|
||||
keyStr, err := Convert(key, cty.String)
|
||||
if err != nil {
|
||||
// Should never happen, because keys can only be numbers or
|
||||
// strings and both can convert to string.
|
||||
return cty.DynamicVal, path.NewErrorf("cannot convert key type %s to string for map", key.Type().FriendlyName())
|
||||
}
|
||||
|
||||
if conv != nil {
|
||||
val, err = conv(val, path)
|
||||
if err != nil {
|
||||
return cty.NilVal, err
|
||||
}
|
||||
}
|
||||
|
||||
elems[keyStr.AsString()] = val
|
||||
}
|
||||
|
||||
if len(elems) == 0 {
|
||||
return cty.MapValEmpty(ety), nil
|
||||
}
|
||||
|
||||
return cty.MapVal(elems), nil
|
||||
}
|
||||
}
|
||||
|
||||
// conversionTupleToList returns a conversion that will take a value of the
|
||||
// given tuple type and return a list of the given element type.
|
||||
//
|
||||
|
|
|
@ -351,7 +351,7 @@ func formatFSM(format string, a []cty.Value) (string, error) {
|
|||
// be impossible (the scanner matches all bytes _somehow_) but we'll
|
||||
// flag it anyway rather than just losing data from the end.
|
||||
if cs < formatfsm_first_final {
|
||||
return buf.String(), fmt.Errorf("extraneous characters beginning at offset %i", p)
|
||||
return buf.String(), fmt.Errorf("extraneous characters beginning at offset %d", p)
|
||||
}
|
||||
|
||||
return buf.String(), nil
|
||||
|
|
|
@ -175,7 +175,7 @@ func formatFSM(format string, a []cty.Value) (string, error) {
|
|||
// be impossible (the scanner matches all bytes _somehow_) but we'll
|
||||
// flag it anyway rather than just losing data from the end.
|
||||
if cs < formatfsm_first_final {
|
||||
return buf.String(), fmt.Errorf("extraneous characters beginning at offset %i", p)
|
||||
return buf.String(), fmt.Errorf("extraneous characters beginning at offset %d", p)
|
||||
}
|
||||
|
||||
return buf.String(), nil
|
||||
|
|
|
@ -2430,44 +2430,44 @@
|
|||
{
|
||||
"checksumSHA1": "4REWNRi5Dg7Kxj1US72+/oVii3Q=",
|
||||
"path": "github.com/zclconf/go-cty/cty",
|
||||
"revision": "b7d1e828d86e99040528ce06ce970382c7813f96",
|
||||
"revisionTime": "2018-03-26T23:07:54Z"
|
||||
"revision": "ba988ce11d9994867838957d4c40bb1ad78b433d",
|
||||
"revisionTime": "2018-05-24T00:26:36Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "gDpi8g5VxCRM3JKm/kaYlGdFUdQ=",
|
||||
"checksumSHA1": "g3pPIVGKkD4gt8TasyLxSX+qdP0=",
|
||||
"path": "github.com/zclconf/go-cty/cty/convert",
|
||||
"revision": "b7d1e828d86e99040528ce06ce970382c7813f96",
|
||||
"revisionTime": "2018-03-26T23:07:54Z"
|
||||
"revision": "ba988ce11d9994867838957d4c40bb1ad78b433d",
|
||||
"revisionTime": "2018-05-24T00:26:36Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "MyyLCGg3RREMllTJyK6ehZl/dHk=",
|
||||
"path": "github.com/zclconf/go-cty/cty/function",
|
||||
"revision": "b7d1e828d86e99040528ce06ce970382c7813f96",
|
||||
"revisionTime": "2018-03-26T23:07:54Z"
|
||||
"revision": "ba988ce11d9994867838957d4c40bb1ad78b433d",
|
||||
"revisionTime": "2018-05-24T00:26:36Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "4R+DQqBew6i9a4lYiLZW1OXVwTI=",
|
||||
"checksumSHA1": "kcTJOuL131/stXJ4U9tC3SASQLs=",
|
||||
"path": "github.com/zclconf/go-cty/cty/function/stdlib",
|
||||
"revision": "b7d1e828d86e99040528ce06ce970382c7813f96",
|
||||
"revisionTime": "2018-03-26T23:07:54Z"
|
||||
"revision": "ba988ce11d9994867838957d4c40bb1ad78b433d",
|
||||
"revisionTime": "2018-05-24T00:26:36Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "tmCzwfNXOEB1sSO7TKVzilb2vjA=",
|
||||
"path": "github.com/zclconf/go-cty/cty/gocty",
|
||||
"revision": "b7d1e828d86e99040528ce06ce970382c7813f96",
|
||||
"revisionTime": "2018-03-26T23:07:54Z"
|
||||
"revision": "ba988ce11d9994867838957d4c40bb1ad78b433d",
|
||||
"revisionTime": "2018-05-24T00:26:36Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "1ApmO+Q33+Oem/3f6BU6sztJWNc=",
|
||||
"path": "github.com/zclconf/go-cty/cty/json",
|
||||
"revision": "b7d1e828d86e99040528ce06ce970382c7813f96",
|
||||
"revisionTime": "2018-03-26T23:07:54Z"
|
||||
"revision": "ba988ce11d9994867838957d4c40bb1ad78b433d",
|
||||
"revisionTime": "2018-05-24T00:26:36Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "y5Sk+n6SOspFj8mlyb8swr4DMIs=",
|
||||
"path": "github.com/zclconf/go-cty/cty/set",
|
||||
"revision": "b7d1e828d86e99040528ce06ce970382c7813f96",
|
||||
"revisionTime": "2018-03-26T23:07:54Z"
|
||||
"revision": "ba988ce11d9994867838957d4c40bb1ad78b433d",
|
||||
"revisionTime": "2018-05-24T00:26:36Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "vE43s37+4CJ2CDU6TlOUOYE0K9c=",
|
||||
|
|
Loading…
Reference in New Issue