-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
terraform.go
56 lines (45 loc) · 1.24 KB
/
terraform.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package terraform
import (
"context"
"io"
"os"
"path/filepath"
"golang.org/x/exp/slices"
"golang.org/x/xerrors"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
"github.com/aquasecurity/trivy/pkg/fanal/types"
)
func init() {
analyzer.RegisterAnalyzer(&terraformConfigAnalyzer{})
}
const version = 1
var requiredExts = []string{".tf", ".tf.json"}
type terraformConfigAnalyzer struct{}
// Analyze returns a name of Terraform file
func (a terraformConfigAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
b, err := io.ReadAll(input.Content)
if err != nil {
return nil, xerrors.Errorf("read error (%s): %w", input.FilePath, err)
}
return &analyzer.AnalysisResult{
Files: map[types.HandlerType][]types.File{
// It will be passed to misconf post handler
types.MisconfPostHandler: {
{
Type: types.Terraform,
Path: input.FilePath,
Content: b,
},
},
},
}, nil
}
func (a terraformConfigAnalyzer) Required(filePath string, _ os.FileInfo) bool {
return slices.Contains(requiredExts, filepath.Ext(filePath))
}
func (terraformConfigAnalyzer) Type() analyzer.Type {
return analyzer.TypeTerraform
}
func (terraformConfigAnalyzer) Version() int {
return version
}