Skip to content

Commit

Permalink
Merge pull request #198 from stelligent/bug/builtin_rules_wont_load
Browse files Browse the repository at this point in the history
initial quick fix for loading builtin terraform rules
  • Loading branch information
Keith Monihen committed Apr 17, 2020
2 parents 9fadc51 + 99f1b71 commit 87e09a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 9 additions & 9 deletions cli/app.go
@@ -1,6 +1,6 @@
package main

//go:generate packr
//go:generate packr -v

import (
"encoding/json"
Expand Down Expand Up @@ -139,7 +139,7 @@ func main() {
// loadBuiltInRuleSet can be called recursively against a directory, as done here,
// or can be called against a single file, as done with lint-rule.yml
if useTerraformBuiltInRules {
builtInRuleSet, err := loadBuiltInRuleSet("terraform")
builtInRuleSet, err := loadBuiltInRuleSet("terraform/")
if err != nil {
fmt.Printf("Failed to load built-in rules for Terraform: %v\n", err)
os.Exit(-1)
Expand Down Expand Up @@ -248,15 +248,14 @@ func loadBuiltInRuleSet(filename string) (assertion.RuleSet, error) {
assertion.Debugf("Failed to add RuleSet: %v\n", err)
return assertion.RuleSet{}, err // returns empty rule set
}
} else {
box = packr.NewBox("./assets/" + filename)
assertion.Debugf("New Box: %v\n", box)
} else if strings.HasSuffix(filename, "/") {
filesInBox := box.List()
if len(filesInBox) > 0 {
// Get each file in that box
for _, fileInBox := range filesInBox {
// Check if file is YAML
if isYamlFile(fileInBox) {
// Check if file is YAML and starts with the folder name
assertion.Debugf("Box File: %v\n", fileInBox)
if isYamlFile(fileInBox) && strings.HasPrefix(fileInBox, filename) {
assertion.Debugf("Adding rule set: %v\n", fileInBox)
ruleSet, err = addRuleSet(ruleSet, box, fileInBox)
if err != nil {
Expand All @@ -265,10 +264,11 @@ func loadBuiltInRuleSet(filename string) (assertion.RuleSet, error) {
}
}
}
} else {
return assertion.RuleSet{}, errors.New("File or directory doesnt exist")
}
} else {
return assertion.RuleSet{}, errors.New("File or directory doesnt exist")
}

return ruleSet, nil
}

Expand Down
5 changes: 3 additions & 2 deletions cli/app_test.go
Expand Up @@ -2,15 +2,16 @@ package main

import (
"bytes"
"testing"

"github.com/gobuffalo/packr"
"github.com/stelligent/config-lint/assertion"
"github.com/stelligent/config-lint/linter"
"github.com/stretchr/testify/assert"
"testing"
)

func TestLoadTerraformRules(t *testing.T) {
_, err := loadBuiltInRuleSet("terraform")
_, err := loadBuiltInRuleSet("terraform/")
if err != nil {
t.Errorf("Cannot load built-in Terraform rules")
}
Expand Down

0 comments on commit 87e09a0

Please sign in to comment.