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

43 lines
1.1 KiB
Go
Raw Normal View History

package accounting
import (
"context"
"sync/atomic"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting"
acc_grpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/audit"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
)
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,
}
}
// Balance implements Server.
func (l *auditService) Balance(ctx context.Context, req *accounting.BalanceRequest) (*accounting.BalanceResponse, error) {
res, err := l.next.Balance(ctx, req)
if !l.enabled.Load() {
return res, err
}
audit.LogRequest(l.log, acc_grpc.AccountingService_Balance_FullMethodName, req,
audit.TargetFromRef(req.GetBody().GetOwnerID(), &user.ID{}), err == nil)
return res, err
}