forked from TrueCloudLab/frostfs-node
[#255] services/audit: Implement audit executor without checks
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
babfbc18f2
commit
0f0be2377b
2 changed files with 121 additions and 0 deletions
80
pkg/services/audit/auditor/context.go
Normal file
80
pkg/services/audit/auditor/context.go
Normal file
|
@ -0,0 +1,80 @@
|
|||
package auditor
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/audit"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Context represents container data audit execution context.
|
||||
type Context struct {
|
||||
ContextPrm
|
||||
|
||||
task *audit.Task
|
||||
|
||||
report *audit.Report
|
||||
}
|
||||
|
||||
// ContextPrm groups components required to conduct data audit checks.
|
||||
type ContextPrm struct {
|
||||
log *logger.Logger
|
||||
}
|
||||
|
||||
// NewContext creates, initializes and returns Context.
|
||||
func NewContext(prm ContextPrm) *Context {
|
||||
return &Context{
|
||||
ContextPrm: prm,
|
||||
}
|
||||
}
|
||||
|
||||
// SetLogger sets logging component.
|
||||
func (p *ContextPrm) SetLogger(l *logger.Logger) {
|
||||
if p != nil {
|
||||
p.log = l
|
||||
}
|
||||
}
|
||||
|
||||
// WithTask sets container audit parameters.
|
||||
func (c *Context) WithTask(t *audit.Task) *Context {
|
||||
if c != nil {
|
||||
c.task = t
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Context) containerID() *container.ID {
|
||||
return c.task.ContainerID()
|
||||
}
|
||||
|
||||
func (c *Context) init() {
|
||||
c.report = audit.NewReport(c.containerID())
|
||||
|
||||
c.log = c.log.With(
|
||||
zap.Stringer("container ID", c.task.ContainerID()),
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Context) expired() bool {
|
||||
ctx := c.task.AuditContext()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
c.log.Debug("audit context is done",
|
||||
zap.String("error", ctx.Err().Error()),
|
||||
)
|
||||
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) writeReport() {
|
||||
c.log.Debug("writing audit report...")
|
||||
|
||||
if err := c.task.Reporter().WriteReport(c.report); err != nil {
|
||||
c.log.Error("could not write audit report")
|
||||
}
|
||||
}
|
41
pkg/services/audit/auditor/exec.go
Normal file
41
pkg/services/audit/auditor/exec.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package auditor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Execute audits container data.
|
||||
func (c *Context) Execute() {
|
||||
c.init()
|
||||
|
||||
for _, check := range []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))
|
||||
|
||||
if c.expired() {
|
||||
break
|
||||
}
|
||||
|
||||
check.exec()
|
||||
}
|
||||
|
||||
c.writeReport()
|
||||
}
|
||||
|
||||
func (c *Context) executePoR() {
|
||||
// TODO: implement me
|
||||
}
|
||||
|
||||
func (c *Context) executePoP() {
|
||||
// TODO: implement me
|
||||
}
|
||||
|
||||
func (c *Context) executePDP() {
|
||||
// TODO: implement me
|
||||
}
|
Loading…
Reference in a new issue