forked from TrueCloudLab/frostfs-node
40 lines
1 KiB
Go
40 lines
1 KiB
Go
|
package session
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"sync/atomic"
|
||
|
|
||
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
||
|
sessionGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/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,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Create implements Server.
|
||
|
func (a *auditService) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error) {
|
||
|
res, err := a.next.Create(ctx, req)
|
||
|
if !a.enabled.Load() {
|
||
|
return res, err
|
||
|
}
|
||
|
audit.LogRequest(a.log, sessionGRPC.SessionService_Create_FullMethodName, req,
|
||
|
audit.TargetFromRef(req.GetBody().GetOwnerID(), &user.ID{}), err == nil)
|
||
|
return res, err
|
||
|
}
|