File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ package preview
2
+
3
+ import (
4
+ "github.com/aquasecurity/trivy/pkg/iac/scanners/terraform/parser/funcs"
5
+ "github.com/zclconf/go-cty/cty"
6
+ "github.com/zclconf/go-cty/cty/function"
7
+ "golang.org/x/xerrors"
8
+ )
9
+
10
+ // init intends to override some of the default functions afforded by terraform.
11
+ // Specifically, any functions that require the context of the host.
12
+ //
13
+ // This is really unfortunate, but all the functions are globals, and this
14
+ // is the only way to override them.
15
+ func init () {
16
+ // PathExpandFunc looks for references to a home directory on the host. The
17
+ // preview rendering should not have access to the host's home directory path,
18
+ // and will return an error if it is used.
19
+ funcs .PathExpandFunc = function .New (& function.Spec {
20
+ Params : []function.Parameter {
21
+ {
22
+ Name : "path" ,
23
+ Type : cty .String ,
24
+ },
25
+ },
26
+ Type : function .StaticReturnType (cty .String ),
27
+ Impl : func (args []cty.Value , retType cty.Type ) (cty.Value , error ) {
28
+ path := args [0 ].AsString ()
29
+ if len (path ) == 0 {
30
+ return cty .StringVal (path ), nil
31
+ }
32
+
33
+ if path [0 ] != '~' {
34
+ return cty .StringVal (path ), nil
35
+ }
36
+
37
+ return cty .NilVal , xerrors .Errorf ("not allowed to expand paths starting with '~' in this context" )
38
+ },
39
+ })
40
+ }
You can’t perform that action at this time.
0 commit comments