frostfs-node/pkg/services/netmap/audit.go

61 lines
1.7 KiB
Go
Raw Normal View History

package netmap
import (
"context"
"sync/atomic"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
netmapGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/audit"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
)
var _ Server = (*auditService)(nil)
type auditService struct {
next Server
log *logger.Logger
enabled *atomic.Bool
}
func NewAuditService(next Server, log *logger.Logger, enabled *atomic.Bool) Server {
return &auditService{
next: next,
log: log,
enabled: enabled,
}
}
// LocalNodeInfo implements Server.
func (a *auditService) LocalNodeInfo(ctx context.Context, req *netmap.LocalNodeInfoRequest) (*netmap.LocalNodeInfoResponse, error) {
res, err := a.next.LocalNodeInfo(ctx, req)
if !a.enabled.Load() {
return res, err
}
audit.LogRequest(a.log, netmapGRPC.NetmapService_LocalNodeInfo_FullMethodName, req,
nil, err == nil)
return res, err
}
// NetworkInfo implements Server.
func (a *auditService) NetworkInfo(ctx context.Context, req *netmap.NetworkInfoRequest) (*netmap.NetworkInfoResponse, error) {
res, err := a.next.NetworkInfo(ctx, req)
if !a.enabled.Load() {
return res, err
}
audit.LogRequest(a.log, netmapGRPC.NetmapService_NetworkInfo_FullMethodName, req,
nil, err == nil)
return res, err
}
// Snapshot implements Server.
func (a *auditService) Snapshot(ctx context.Context, req *netmap.SnapshotRequest) (*netmap.SnapshotResponse, error) {
res, err := a.next.Snapshot(ctx, req)
if !a.enabled.Load() {
return res, err
}
audit.LogRequest(a.log, netmapGRPC.NetmapService_NetmapSnapshot_FullMethodName, req,
nil, err == nil)
return res, err
}