All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 2m54s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m27s
Tests and linters / gopls check (pull_request) Successful in 3m49s
Tests and linters / Run gofumpt (pull_request) Successful in 3m49s
DCO action / DCO (pull_request) Successful in 4m8s
Build / Build Components (pull_request) Successful in 4m54s
Tests and linters / Staticcheck (pull_request) Successful in 5m28s
Tests and linters / Tests (pull_request) Successful in 5m40s
Tests and linters / Lint (pull_request) Successful in 6m10s
Tests and linters / Tests with -race (pull_request) Successful in 6m49s
* Added new method for listing containers to container service. It opens stream and sends containers in batches. * Added TransportSplitter wrapper around ExecutionService to split container ID list read from contract in parts that are smaller than grpc max message size. Batch size can be changed in node configuration file (as in example config file). * Changed `container list` implementaion in cli: now ListStream is called by default. Old List is called only if ListStream is not implemented. Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
86 lines
2.7 KiB
Go
86 lines
2.7 KiB
Go
package container
|
|
|
|
import (
|
|
"context"
|
|
"sync/atomic"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/audit"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/container"
|
|
container_grpc "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/container/grpc"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
"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,
|
|
}
|
|
}
|
|
|
|
// Delete implements Server.
|
|
func (a *auditService) Delete(ctx context.Context, req *container.DeleteRequest) (*container.DeleteResponse, error) {
|
|
res, err := a.next.Delete(ctx, req)
|
|
if !a.enabled.Load() {
|
|
return res, err
|
|
}
|
|
|
|
audit.LogRequest(ctx, a.log, container_grpc.ContainerService_Delete_FullMethodName, req,
|
|
audit.TargetFromRef(req.GetBody().GetContainerID(), &cid.ID{}), err == nil)
|
|
|
|
return res, err
|
|
}
|
|
|
|
// Get implements Server.
|
|
func (a *auditService) Get(ctx context.Context, req *container.GetRequest) (*container.GetResponse, error) {
|
|
res, err := a.next.Get(ctx, req)
|
|
if !a.enabled.Load() {
|
|
return res, err
|
|
}
|
|
audit.LogRequest(ctx, a.log, container_grpc.ContainerService_Get_FullMethodName, req,
|
|
audit.TargetFromRef(req.GetBody().GetContainerID(), &cid.ID{}), err == nil)
|
|
return res, err
|
|
}
|
|
|
|
// List implements Server.
|
|
func (a *auditService) List(ctx context.Context, req *container.ListRequest) (*container.ListResponse, error) {
|
|
res, err := a.next.List(ctx, req)
|
|
if !a.enabled.Load() {
|
|
return res, err
|
|
}
|
|
audit.LogRequest(ctx, a.log, container_grpc.ContainerService_List_FullMethodName, req,
|
|
audit.TargetFromRef(req.GetBody().GetOwnerID(), &user.ID{}), err == nil)
|
|
return res, err
|
|
}
|
|
|
|
// ListStream implements Server.
|
|
func (a *auditService) ListStream(req *container.ListStreamRequest, stream ListStream) error {
|
|
err := a.next.ListStream(req, stream)
|
|
if !a.enabled.Load() {
|
|
return err
|
|
}
|
|
audit.LogRequest(stream.Context(), a.log, container_grpc.ContainerService_ListStream_FullMethodName, req,
|
|
audit.TargetFromRef(req.GetBody().GetOwnerID(), &user.ID{}), err == nil)
|
|
return err
|
|
}
|
|
|
|
// Put implements Server.
|
|
func (a *auditService) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) {
|
|
res, err := a.next.Put(ctx, req)
|
|
if !a.enabled.Load() {
|
|
return res, err
|
|
}
|
|
audit.LogRequest(ctx, a.log, container_grpc.ContainerService_Put_FullMethodName, req,
|
|
audit.TargetFromRef(res.GetBody().GetContainerID(), &cid.ID{}), err == nil)
|
|
return res, err
|
|
}
|