Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial quick fix for loading builtin terraform rules #198

Merged
merged 2 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions cli/app.go
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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