Merge pull request #75 from nuwaida/master

Result structure changes
pull/77/head
Liz Rice 7 years ago committed by GitHub
commit 94b960cfad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -60,15 +60,16 @@ func handleError(err error, context string) (errmsg string) {
// Check contains information about a recommendation in the // Check contains information about a recommendation in the
// CIS Kubernetes 1.6+ document. // CIS Kubernetes 1.6+ document.
type Check struct { type Check struct {
ID string `yaml:"id" json:"id"` ID string `yaml:"id" json:"test_number"`
Text string Text string `json:"test_desc"`
Audit string `json:"omit"` Audit string `json:"omit"`
Type string `json:"type"` Type string `json:"type"`
Commands []*exec.Cmd `json:"omit"` Commands []*exec.Cmd `json:"omit"`
Tests *tests `json:"omit"` Tests *tests `json:"omit"`
Set bool `json:"omit"` Set bool `json:"omit"`
Remediation string Remediation string `json:"-"`
State TestInfo []string `json:"test_info"`
State `json:"status"`
} }
// Run executes the audit commands specified in a check and outputs // Run executes the audit commands specified in a check and outputs

@ -23,26 +23,29 @@ import (
// Controls holds all controls to check for master nodes. // Controls holds all controls to check for master nodes.
type Controls struct { type Controls struct {
ID string `yaml:"id"` ID string `yaml:"id" json:"id"`
Version string Version string `json:"version"`
Text string Text string `json:"text"`
Type NodeType Type NodeType `json:"node_type"`
Groups []*Group Groups []*Group `json:"tests"`
Summary Summary
} }
// Group is a collection of similar checks. // Group is a collection of similar checks.
type Group struct { type Group struct {
ID string `yaml:"id"` ID string `yaml:"id" json:"section"`
Text string Pass int `json:"pass"`
Checks []*Check Fail int `json:"fail"`
Warn int `json:"warn"`
Text string `json:"desc"`
Checks []*Check `json:"results"`
} }
// Summary is a summary of the results of control checks run. // Summary is a summary of the results of control checks run.
type Summary struct { type Summary struct {
Pass int Pass int `json:"total_pass"`
Fail int Fail int `json:"total_fail"`
Warn int Warn int `json:"total_warn"`
} }
// NewControls instantiates a new master Controls object. // NewControls instantiates a new master Controls object.
@ -84,7 +87,9 @@ func (controls *Controls) RunGroup(gids ...string) Summary {
if gid == group.ID { if gid == group.ID {
for _, check := range group.Checks { for _, check := range group.Checks {
check.Run() check.Run()
check.TestInfo = append(check.TestInfo, check.Remediation)
summarize(controls, check) summarize(controls, check)
summarizeGroup(group, check)
} }
g = append(g, group) g = append(g, group)
@ -112,6 +117,7 @@ func (controls *Controls) RunChecks(ids ...string) Summary {
for _, id := range ids { for _, id := range ids {
if id == check.ID { if id == check.ID {
check.Run() check.Run()
check.TestInfo = append(check.TestInfo, check.Remediation)
summarize(controls, check) summarize(controls, check)
// Check if we have already added this checks group. // Check if we have already added this checks group.
@ -178,3 +184,14 @@ func summarize(controls *Controls, check *Check) {
controls.Summary.Warn++ controls.Summary.Warn++
} }
} }
func summarizeGroup(group *Group, check *Check) {
switch check.State {
case PASS:
group.Pass++
case FAIL:
group.Fail++
case WARN:
group.Warn++
}
}

Loading…
Cancel
Save