Skip to content

Commit

Permalink
make current directory as default for scanning IaC
Browse files Browse the repository at this point in the history
  • Loading branch information
Yusuf Kanchwala authored and cesar-rodriguez committed Aug 14, 2020
1 parent 066e21c commit 9571b67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/terrascan/main.go
Expand Up @@ -37,7 +37,7 @@ func main() {
iacType = flag.String("iac", "", "IaC provider (supported values: terraform)")
iacVersion = flag.String("iac-version", "default", "IaC version (supported values: 'v12' for terraform)")
iacFilePath = flag.String("f", "", "IaC file path")
iacDirPath = flag.String("d", "", "IaC directory path")
iacDirPath = flag.String("d", ".", "IaC directory path")
policyPath = flag.String("p", "", "Policy directory path")

// cloud flags
Expand Down
6 changes: 3 additions & 3 deletions pkg/runtime/executor.go
Expand Up @@ -99,10 +99,10 @@ func (e *Executor) Execute() (results policy.EngineOutput, err error) {

// create results output from Iac
var normalized output.AllResourceConfigs
if e.dirPath != "" {
normalized, err = e.iacProvider.LoadIacDir(e.dirPath)
} else {
if e.filePath != "" {
normalized, err = e.iacProvider.LoadIacFile(e.filePath)
} else {
normalized, err = e.iacProvider.LoadIacDir(e.dirPath)
}
if err != nil {
return results, err
Expand Down
31 changes: 13 additions & 18 deletions pkg/runtime/validate.go
Expand Up @@ -44,25 +44,8 @@ func (e *Executor) ValidateInputs() error {
zap.S().Errorf("no IaC path specified; use '-f' for file or '-d' for directory")
return errEmptyIacPath
}
if e.filePath != "" && e.dirPath != "" {
zap.S().Errorf("cannot accept both '-f %s' and '-d %s' options together", e.filePath, e.dirPath)
return errIncorrectIacPath
}

if e.dirPath != "" {
// if directory, check if directory exists
e.dirPath, err = utils.GetAbsPath(e.dirPath)
if err != nil {
return err
}

if _, err := os.Stat(e.dirPath); err != nil {
zap.S().Errorf("directory '%s' does not exist", e.dirPath)
return errDirNotExists
}
zap.S().Debugf("directory '%s' exists", e.dirPath)
} else {

if e.filePath != "" {
// if file path, check if file exists
e.filePath, err = utils.GetAbsPath(e.filePath)
if err != nil {
Expand All @@ -74,6 +57,18 @@ func (e *Executor) ValidateInputs() error {
return errFileNotExists
}
zap.S().Debugf("file '%s' exists", e.filePath)
} else {
// if directory, check if directory exists
e.dirPath, err = utils.GetAbsPath(e.dirPath)
if err != nil {
return err
}

if _, err := os.Stat(e.dirPath); err != nil {
zap.S().Errorf("directory '%s' does not exist", e.dirPath)
return errDirNotExists
}
zap.S().Debugf("directory '%s' exists", e.dirPath)
}

// check if Iac type is supported
Expand Down

0 comments on commit 9571b67

Please sign in to comment.