Skip to content

Commit

Permalink
last minute fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Devang Gaur committed Nov 13, 2020
1 parent 09d81f8 commit 25f258c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/spf13/cobra v1.0.0
github.com/zclconf/go-cty v1.2.1
go.uber.org/zap v1.13.0
golang.org/x/tools v0.0.0-20201110030525-169ad6d6ecb2 // indirect
golang.org/x/tools v0.0.0-20201111224557-41a3a589386c // indirect
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
helm.sh/helm/v3 v3.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,8 @@ golang.org/x/tools v0.0.0-20201110030525-169ad6d6ecb2 h1:5GmCe1Mc5HsGGl6E0kOVQRz
golang.org/x/tools v0.0.0-20201110030525-169ad6d6ecb2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201110201400-7099162a900a h1:5E6TPwSBG74zT8xSrVc8W59K4ch4NFobVTnh2BYzHyU=
golang.org/x/tools v0.0.0-20201110201400-7099162a900a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201111224557-41a3a589386c h1:o4Kpkl2kZqc7n22gkunVhOJ+Ys5u3NrnXKAr2OgO5s0=
golang.org/x/tools v0.0.0-20201111224557-41a3a589386c/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
5 changes: 3 additions & 2 deletions pkg/iac-providers/kustomize/v3/load-dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kustomizev3

import (
"errors"
"fmt"
"path/filepath"

k8sv1 "github.com/accurics/terrascan/pkg/iac-providers/kubernetes/v1"
Expand All @@ -13,7 +14,7 @@ import (
)

const (
kustomizedirectory string = "kustomization_directory"
kustomizedirectory string = "kustomization"
)

// LoadIacDir loads the kustomize directory and returns the ResourceConfig mapping which is evaluated by the policy engine
Expand Down Expand Up @@ -43,7 +44,7 @@ func (k *KustomizeV3) LoadIacDir(absRootDir string) (output.AllResourceConfigs,
yamlkustomizeobj, err := utils.ReadYamlFile(filepath.Join(absRootDir, kustomizeFileName))

if len(yamlkustomizeobj) == 0 {
err := errors.New("unable to read any kustomization file in the directory")
err = fmt.Errorf("unable to read any kustomization file in the directory : %v", err)
zap.S().Error("error while searching for iac files", zap.String("root dir", absRootDir), zap.Error(err))
return allResourcesConfig, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/iac-providers/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestRegisterIacProvider(t *testing.T) {
if _, present := supportedIacProviders[iacType]; !present {
t.Errorf("mockIacType not registered")
}
got, present := supportedIacProviders[iacType][iacDefaultVersion]
got, present := supportedIacProviders[iacType][defaultIacVersion]
if !present {
t.Errorf("defaultIacVersion not registered")
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/utils/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ func LoadYAML(filePath string) ([]*IacDocument, error) {
return iacDocumentList, err
}

return getIacDocumentList(bufio.NewScanner(file), fileBytes, filePath)
return ScanIacDocumentsFromYaml(bufio.NewScanner(file), fileBytes, filePath)
}

// LoadYAMLString loads a YAML String. Can return one or more IaC Documents.
// Besides reading in file data, its main purpose is to determine and store line number and filename metadata
func LoadYAMLString(data, absFilePath string) ([]*IacDocument, error) {
return getIacDocumentList(bufio.NewScanner(strings.NewReader(data)), []byte(data), absFilePath)
return ScanIacDocumentsFromYaml(bufio.NewScanner(strings.NewReader(data)), []byte(data), absFilePath)
}

// ReadYamlFile reads a yaml file and load content in a map[string]interface{} type
Expand All @@ -60,9 +60,9 @@ func ReadYamlFile(path string) (map[string]interface{}, error) {
return output, nil
}

// getIacDocumentList provides one or more IaC Documents.
// ScanIacDocumentsFromYaml provides one or more IaC Documents.
// Besides reading in file data, its main purpose is to determine and store line number and filename metadata
func getIacDocumentList(scanner *bufio.Scanner, bytearray []byte, filePath string) ([]*IacDocument, error) {
func ScanIacDocumentsFromYaml(scanner *bufio.Scanner, byteArray []byte, filePath string) ([]*IacDocument, error) {
iacDocumentList := make([]*IacDocument, 0)

// First pass determines line number data
Expand Down Expand Up @@ -94,7 +94,7 @@ func getIacDocumentList(scanner *bufio.Scanner, bytearray []byte, filePath strin
return iacDocumentList, err
}

dec := yaml.NewDecoder(bytes.NewReader(bytearray))
dec := yaml.NewDecoder(bytes.NewReader(byteArray))

i := 0
for {
Expand Down

0 comments on commit 25f258c

Please sign in to comment.