Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract ValidateResources from FileLinter into ResourceLinter, update…
… SecurityGroupLinter to use it
- Loading branch information
Larry Hitchon
committed
Mar 31, 2018
1 parent
f7d8f7e
commit e46323b
Showing
4 changed files
with
44 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stelligent/config-lint/assertion" | ||
) | ||
|
||
// ResourceLinter provides the basic validation logic used by all linters | ||
type ResourceLinter struct { | ||
Log assertion.LoggingFunction | ||
} | ||
|
||
// ValidateResources evaluates a list of Rule objects to a list of Resource objects | ||
func (r ResourceLinter) ValidateResources(resources []assertion.Resource, rules []assertion.Rule) ([]assertion.Violation, error) { | ||
|
||
valueSource := assertion.StandardValueSource{Log: r.Log} | ||
resolvedRules := assertion.ResolveRules(rules, valueSource, r.Log) | ||
externalRules := assertion.StandardExternalRuleInvoker{Log: r.Log} | ||
|
||
allViolations := make([]assertion.Violation, 0) | ||
for _, rule := range resolvedRules { | ||
r.Log(fmt.Sprintf("Rule %s: %s", rule.ID, rule.Message)) | ||
for _, resource := range assertion.FilterResourcesByType(resources, rule.Resource) { | ||
if assertion.ExcludeResource(rule, resource) { | ||
r.Log(fmt.Sprintf("Ignoring resource %s", resource.ID)) | ||
} else { | ||
_, violations, err := assertion.CheckRule(rule, resource, externalRules, r.Log) | ||
if err != nil { | ||
return allViolations, err | ||
} | ||
allViolations = append(allViolations, violations...) | ||
} | ||
} | ||
} | ||
return allViolations, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters