2024-06-18 09:40:03 +00:00
|
|
|
package apemanager
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sync/atomic"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/audit"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/apemanager"
|
|
|
|
ape_grpc "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/apemanager/grpc"
|
2024-06-18 09:40:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddChain implements Server.
|
|
|
|
func (a *auditService) AddChain(ctx context.Context, req *apemanager.AddChainRequest) (*apemanager.AddChainResponse, error) {
|
|
|
|
res, err := a.next.AddChain(ctx, req)
|
|
|
|
if !a.enabled.Load() {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
audit.LogRequest(ctx, a.log, ape_grpc.APEManagerService_AddChain_FullMethodName, req,
|
2024-06-18 09:40:03 +00:00
|
|
|
audit.TargetFromChainID(req.GetBody().GetTarget().GetTargetType().String(),
|
|
|
|
req.GetBody().GetTarget().GetName(),
|
|
|
|
res.GetBody().GetChainID()),
|
|
|
|
err == nil)
|
|
|
|
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListChains implements Server.
|
|
|
|
func (a *auditService) ListChains(ctx context.Context, req *apemanager.ListChainsRequest) (*apemanager.ListChainsResponse, error) {
|
|
|
|
res, err := a.next.ListChains(ctx, req)
|
|
|
|
if !a.enabled.Load() {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
audit.LogRequest(ctx, a.log, ape_grpc.APEManagerService_ListChains_FullMethodName, req,
|
2024-06-18 09:40:03 +00:00
|
|
|
audit.TargetFromChainID(req.GetBody().GetTarget().GetTargetType().String(),
|
|
|
|
req.GetBody().GetTarget().GetName(),
|
|
|
|
nil),
|
|
|
|
err == nil)
|
|
|
|
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveChain implements Server.
|
|
|
|
func (a *auditService) RemoveChain(ctx context.Context, req *apemanager.RemoveChainRequest) (*apemanager.RemoveChainResponse, error) {
|
|
|
|
res, err := a.next.RemoveChain(ctx, req)
|
|
|
|
if !a.enabled.Load() {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
audit.LogRequest(ctx, a.log, ape_grpc.APEManagerService_RemoveChain_FullMethodName, req,
|
2024-06-18 09:40:03 +00:00
|
|
|
audit.TargetFromChainID(req.GetBody().GetTarget().GetTargetType().String(),
|
|
|
|
req.GetBody().GetTarget().GetName(),
|
|
|
|
req.GetBody().GetChainID()),
|
|
|
|
err == nil)
|
|
|
|
|
|
|
|
return res, err
|
|
|
|
}
|