From bae9f6d2fd5eb5bc80929bd393932b23f14d7c93 Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Tue, 6 Jun 2017 12:40:07 -0400 Subject: Initial transfer of provider code --- vendor/github.com/hashicorp/hil/transform_fixed.go | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 vendor/github.com/hashicorp/hil/transform_fixed.go (limited to 'vendor/github.com/hashicorp/hil/transform_fixed.go') diff --git a/vendor/github.com/hashicorp/hil/transform_fixed.go b/vendor/github.com/hashicorp/hil/transform_fixed.go new file mode 100644 index 0000000..e69df29 --- /dev/null +++ b/vendor/github.com/hashicorp/hil/transform_fixed.go @@ -0,0 +1,29 @@ +package hil + +import ( + "github.com/hashicorp/hil/ast" +) + +// FixedValueTransform transforms an AST to return a fixed value for +// all interpolations. i.e. you can make "hi ${anything}" always +// turn into "hi foo". +// +// The primary use case for this is for config validations where you can +// verify that interpolations result in a certain type of string. +func FixedValueTransform(root ast.Node, Value *ast.LiteralNode) ast.Node { + // We visit the nodes in top-down order + result := root + switch n := result.(type) { + case *ast.Output: + for i, v := range n.Exprs { + n.Exprs[i] = FixedValueTransform(v, Value) + } + case *ast.LiteralNode: + // We keep it as-is + default: + // Anything else we replace + result = Value + } + + return result +} -- cgit v1.2.3