Skip to content

Commit

Permalink
covert rules for -validate option to also use go-bindata
Browse files Browse the repository at this point in the history
  • Loading branch information
Larry Hitchon committed Apr 14, 2018
1 parent a7d2a25 commit fa7d283
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
11 changes: 5 additions & 6 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {
}

if *validate {
validateRules(flag.Args(), LintRules)
validateRules(flag.Args())
return
}

Expand All @@ -74,14 +74,13 @@ func main() {
applyRules(ruleSets, flag.Args(), applyOptions)
}

func validateRules(filenames []string, rules string) {
ruleSet, err := assertion.ParseRules(rules)
func validateRules(filenames []string) {
builtInRuleSet, err := loadBuiltInRuleSet("assets/lint-rules.yml")
if err != nil {
fmt.Println("Unable to parse validation rules")
fmt.Println(err.Error())
fmt.Printf("Unable to load build-in rules for validation: %v\n", err)
return
}
ruleSets := []assertion.RuleSet{ruleSet}
ruleSets := []assertion.RuleSet{builtInRuleSet}
applyOptions := ApplyOptions{
QueryExpression: "Violations[]",
}
Expand Down
12 changes: 4 additions & 8 deletions cli/lint-rules.go → cli/assets/lint-rules.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
package main

// LintRules string containing YAML for -validate option
var LintRules = `---
---
version: 1
description: Rules for config-lint
type: LintRules
Expand Down Expand Up @@ -54,7 +51,7 @@ rules:
assertions:
- every:
key: rules
assertions:
expressions:
- key: id
op: present

Expand Down Expand Up @@ -88,13 +85,13 @@ rules:
op: present

- id: VALID_EXPRESSION
message: "There are mutually exclusive in the same expression: key,or,xor,and,not,every,some,none"
message: "These are mutually exclusive in the same expression: key,or,xor,and,not,every,some,none"
resource: LintRule
severity: FAILURE
assertions:
- every:
key: "assertions[]"
assertions:
expressions:
- xor:
- key: "@"
op: has-properties
Expand All @@ -120,4 +117,3 @@ rules:
- key: "@"
op: has-properties
value: none
`

0 comments on commit fa7d283

Please sign in to comment.