From a0f8e7bd04a7fedd3a8435ca5ca12967e9952872 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Sat, 9 Jul 2016 21:33:12 +0100 Subject: [PATCH] deps: Update github.com/hashicorp/hil --- vendor/github.com/hashicorp/hil/convert.go | 60 ++++++++++++++++++++++ vendor/github.com/hashicorp/hil/eval.go | 44 +++++----------- vendor/vendor.json | 6 +-- 3 files changed, 76 insertions(+), 34 deletions(-) diff --git a/vendor/github.com/hashicorp/hil/convert.go b/vendor/github.com/hashicorp/hil/convert.go index 738e719ff2..b7bff7544b 100644 --- a/vendor/github.com/hashicorp/hil/convert.go +++ b/vendor/github.com/hashicorp/hil/convert.go @@ -42,6 +42,10 @@ func hilMapstructureWeakDecode(m interface{}, rawVal interface{}) error { } func InterfaceToVariable(input interface{}) (ast.Variable, error) { + if inputVariable, ok := input.(ast.Variable); ok { + return inputVariable, nil + } + var stringVal string if err := hilMapstructureWeakDecode(input, &stringVal); err == nil { return ast.Variable{ @@ -86,3 +90,59 @@ func InterfaceToVariable(input interface{}) (ast.Variable, error) { return ast.Variable{}, fmt.Errorf("value for conversion must be a string, interface{} or map[string]interface: got %T", input) } + +func VariableToInterface(input ast.Variable) (interface{}, error) { + if input.Type == ast.TypeString { + if inputStr, ok := input.Value.(string); ok { + return inputStr, nil + } else { + return nil, fmt.Errorf("ast.Variable with type string has value which is not a string") + } + } + + if input.Type == ast.TypeList { + inputList, ok := input.Value.([]ast.Variable) + if !ok { + return nil, fmt.Errorf("ast.Variable with type list has value which is not a []ast.Variable") + } + + result := make([]interface{}, 0) + if len(inputList) == 0 { + return result, nil + } + + for _, element := range inputList { + if convertedElement, err := VariableToInterface(element); err == nil { + result = append(result, convertedElement) + } else { + return nil, err + } + } + + return result, nil + } + + if input.Type == ast.TypeMap { + inputMap, ok := input.Value.(map[string]ast.Variable) + if !ok { + return nil, fmt.Errorf("ast.Variable with type map has value which is not a map[string]ast.Variable") + } + + result := make(map[string]interface{}, 0) + if len(inputMap) == 0 { + return result, nil + } + + for key, value := range inputMap { + if convertedValue, err := VariableToInterface(value); err == nil { + result[key] = convertedValue + } else { + return nil, err + } + } + + return result, nil + } + + return nil, fmt.Errorf("Find") +} diff --git a/vendor/github.com/hashicorp/hil/eval.go b/vendor/github.com/hashicorp/hil/eval.go index f5537312e9..173c67f5ad 100644 --- a/vendor/github.com/hashicorp/hil/eval.go +++ b/vendor/github.com/hashicorp/hil/eval.go @@ -63,15 +63,23 @@ func Eval(root ast.Node, config *EvalConfig) (EvaluationResult, error) { switch outputType { case ast.TypeList: + val, err := VariableToInterface(ast.Variable{ + Type: ast.TypeList, + Value: output, + }) return EvaluationResult{ Type: TypeList, - Value: hilListToGoSlice(output.([]ast.Variable)), - }, nil + Value: val, + }, err case ast.TypeMap: + val, err := VariableToInterface(ast.Variable{ + Type: ast.TypeMap, + Value: output, + }) return EvaluationResult{ - Type: TypeMap, - Value: hilMapToGoMap(output.(map[string]ast.Variable)), - }, nil + Type: TypeMap, + Value: val, + }, err case ast.TypeString: return EvaluationResult{ Type: TypeString, @@ -337,32 +345,6 @@ func (v *evalIndex) evalMapIndex(variableName string, target interface{}, key in return value.Value, value.Type, nil } -// hilListToGoSlice converts an ast.Variable into a []interface{}. We assume that -// the type checking is already done since this is internal and only used in output -// evaluation. -func hilListToGoSlice(variable []ast.Variable) []interface{} { - output := make([]interface{}, len(variable)) - - for index, element := range variable { - output[index] = element.Value - } - - return output -} - -// hilMapToGoMap converts an ast.Variable into a map[string]interface{}. We assume -// that the type checking is already done since this is internal and only used in -// output evaluation. -func hilMapToGoMap(variable map[string]ast.Variable) map[string]interface{} { - output := make(map[string]interface{}) - - for key, element := range variable { - output[key] = element.Value - } - - return output -} - type evalOutput struct{ *ast.Output } func (v *evalOutput) Eval(s ast.Scope, stack *ast.Stack) (interface{}, ast.Type, error) { diff --git a/vendor/vendor.json b/vendor/vendor.json index d9635eb2a0..939ab76c6e 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -890,10 +890,10 @@ "revisionTime": "2016-06-24T12:12:30Z" }, { - "checksumSHA1": "vWW3HXm7OTOMISuZPcCSJODRYkU=", + "checksumSHA1": "o5JhQCQpoSRFcMwD8LxqP8iJ04o=", "path": "github.com/hashicorp/hil", - "revision": "7130f7330953adacbfb4ca0ad4b14b806bce3762", - "revisionTime": "2016-06-12T11:49:46Z" + "revision": "79fc9230647576201673b35c724c58ec034bd21d", + "revisionTime": "2016-07-11T16:29:56Z" }, { "checksumSHA1": "UICubs001+Q4MsUf9zl2vcMzWQQ=",