From 33804e024d9433401969ad0546c123aa5cd571b1 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 22 Dec 2020 11:08:31 +0300 Subject: [PATCH] [#255] services/audit: Complete audit report after the last check Signed-off-by: Leonard Lyubich --- pkg/services/audit/auditor/context.go | 4 ++++ pkg/services/audit/auditor/exec.go | 14 ++++++++++---- pkg/services/audit/report.go | 5 +++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pkg/services/audit/auditor/context.go b/pkg/services/audit/auditor/context.go index 3a236199c..52b56e6e4 100644 --- a/pkg/services/audit/auditor/context.go +++ b/pkg/services/audit/auditor/context.go @@ -71,6 +71,10 @@ func (c *Context) expired() bool { } } +func (c *Context) complete() { + c.report.Complete() +} + func (c *Context) writeReport() { c.log.Debug("writing audit report...") diff --git a/pkg/services/audit/auditor/exec.go b/pkg/services/audit/auditor/exec.go index 90d6d76fd..5ed605b74 100644 --- a/pkg/services/audit/auditor/exec.go +++ b/pkg/services/audit/auditor/exec.go @@ -8,21 +8,27 @@ import ( func (c *Context) Execute() { c.init() - for _, check := range []struct { + checks := []struct { name string exec func() }{ {name: "PoR", exec: c.executePoR}, {name: "PoP", exec: c.executePoP}, {name: "PDP", exec: c.executePDP}, - } { - c.log.Debug(fmt.Sprintf("executing %s check...", check.name)) + } + + for i := range checks { + c.log.Debug(fmt.Sprintf("executing %s check...", checks[i].name)) if c.expired() { break } - check.exec() + checks[i].exec() + + if i == len(checks)-1 { + c.complete() + } } c.writeReport() diff --git a/pkg/services/audit/report.go b/pkg/services/audit/report.go index 1d39442ff..2989604a2 100644 --- a/pkg/services/audit/report.go +++ b/pkg/services/audit/report.go @@ -31,3 +31,8 @@ func NewReport(cid *container.ID) *Report { func (r *Report) Result() *audit.Result { return r.res } + +// Complete completes audit report. +func (r *Report) Complete() { + r.res.SetComplete(true) +}