diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hil/transform_fixed.go')
-rw-r--r-- | vendor/github.com/hashicorp/hil/transform_fixed.go | 29 |
1 files changed, 29 insertions, 0 deletions
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 @@ | |||
1 | package hil | ||
2 | |||
3 | import ( | ||
4 | "github.com/hashicorp/hil/ast" | ||
5 | ) | ||
6 | |||
7 | // FixedValueTransform transforms an AST to return a fixed value for | ||
8 | // all interpolations. i.e. you can make "hi ${anything}" always | ||
9 | // turn into "hi foo". | ||
10 | // | ||
11 | // The primary use case for this is for config validations where you can | ||
12 | // verify that interpolations result in a certain type of string. | ||
13 | func FixedValueTransform(root ast.Node, Value *ast.LiteralNode) ast.Node { | ||
14 | // We visit the nodes in top-down order | ||
15 | result := root | ||
16 | switch n := result.(type) { | ||
17 | case *ast.Output: | ||
18 | for i, v := range n.Exprs { | ||
19 | n.Exprs[i] = FixedValueTransform(v, Value) | ||
20 | } | ||
21 | case *ast.LiteralNode: | ||
22 | // We keep it as-is | ||
23 | default: | ||
24 | // Anything else we replace | ||
25 | result = Value | ||
26 | } | ||
27 | |||
28 | return result | ||
29 | } | ||