From 017a9836ce8d90ae26d9bc4f26454ab794020f99 Mon Sep 17 00:00:00 2001 From: nazemu Date: Wed, 29 Nov 2017 18:31:55 +0200 Subject: [PATCH] Result structure changes Changes to the json structure and field names --- check/check.go | 9 +++++---- check/controls.go | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/check/check.go b/check/check.go index 16c3984..fdcd886 100644 --- a/check/check.go +++ b/check/check.go @@ -60,15 +60,16 @@ func handleError(err error, context string) (errmsg string) { // Check contains information about a recommendation in the // CIS Kubernetes 1.6+ document. type Check struct { - ID string `yaml:"id" json:"id"` - Text string + ID string `yaml:"id" json:"test_number"` + Text string `json:"test_desc"` Audit string `json:"omit"` Type string `json:"type"` Commands []*exec.Cmd `json:"omit"` Tests *tests `json:"omit"` Set bool `json:"omit"` - Remediation string - State + Remediation string `json:"-"` + TestInfo []string `json:"test_info"` + State `json:"status"` } // Run executes the audit commands specified in a check and outputs diff --git a/check/controls.go b/check/controls.go index 8660e81..a246791 100644 --- a/check/controls.go +++ b/check/controls.go @@ -23,26 +23,29 @@ import ( // Controls holds all controls to check for master nodes. type Controls struct { - ID string `yaml:"id"` - Version string - Text string - Type NodeType - Groups []*Group + ID string `yaml:"id" json:"id"` + Version string `json:"version"` + Text string `json:"text"` + Type NodeType `json:"node_type"` + Groups []*Group `json:"tests"` Summary } // Group is a collection of similar checks. type Group struct { - ID string `yaml:"id"` - Text string - Checks []*Check + ID string `yaml:"id" json:"section"` + Pass int `json:"pass"` + 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. type Summary struct { - Pass int - Fail int - Warn int + Pass int `json:"total_pass"` + Fail int `json:"total_fail"` + Warn int `json:"total_warn"` } // NewControls instantiates a new master Controls object. @@ -84,7 +87,9 @@ func (controls *Controls) RunGroup(gids ...string) Summary { if gid == group.ID { for _, check := range group.Checks { check.Run() + check.TestInfo = append(check.TestInfo, check.Remediation) summarize(controls, check) + summarizeGroup(group, check) } g = append(g, group) @@ -112,6 +117,7 @@ func (controls *Controls) RunChecks(ids ...string) Summary { for _, id := range ids { if id == check.ID { check.Run() + check.TestInfo = append(check.TestInfo, check.Remediation) summarize(controls, check) // Check if we have already added this checks group. @@ -178,3 +184,14 @@ func summarize(controls *Controls, check *Check) { controls.Summary.Warn++ } } + +func summarizeGroup(group *Group, check *Check) { + switch check.State { + case PASS: + group.Pass++ + case FAIL: + group.Fail++ + case WARN: + group.Warn++ + } +}