Ekaterina Lebedeva
df05057ed4
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 3m5s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m36s
Tests and linters / gopls check (pull_request) Successful in 4m1s
Tests and linters / Run gofumpt (pull_request) Successful in 5m35s
DCO action / DCO (pull_request) Successful in 6m3s
Tests and linters / Tests with -race (pull_request) Successful in 6m35s
Build / Build Components (pull_request) Successful in 7m15s
Tests and linters / Staticcheck (pull_request) Successful in 7m38s
Tests and linters / Tests (pull_request) Successful in 7m56s
Tests and linters / Lint (pull_request) Successful in 8m42s
Tests and linters / Run gofumpt (push) Successful in 3m34s
Tests and linters / Staticcheck (push) Successful in 3m38s
Tests and linters / Lint (push) Successful in 5m12s
Vulncheck / Vulncheck (push) Successful in 6m7s
Build / Build Components (push) Successful in 6m43s
Pre-commit hooks / Pre-commit (push) Successful in 6m54s
Tests and linters / Tests (push) Successful in 7m31s
Tests and linters / Tests with -race (push) Successful in 8m5s
Tests and linters / gopls check (push) Successful in 8m13s
* 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. * Changed `internalclient.ListContainersPrm`.`Account` to `OwnerID` since `client.PrmContainerList`.`Account` was renamed to `OwnerID` in sdk. Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
package container
|
|
|
|
import (
|
|
"context"
|
|
"crypto/ecdsa"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/container"
|
|
)
|
|
|
|
type signService struct {
|
|
sigSvc *util.SignService
|
|
|
|
svc Server
|
|
}
|
|
|
|
func NewSignService(key *ecdsa.PrivateKey, svc Server) Server {
|
|
return &signService{
|
|
sigSvc: util.NewUnarySignService(key),
|
|
svc: svc,
|
|
}
|
|
}
|
|
|
|
func (s *signService) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) {
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
resp := new(container.PutResponse)
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
}
|
|
resp, err := util.EnsureNonNilResponse(s.svc.Put(ctx, req))
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
}
|
|
|
|
func (s *signService) Delete(ctx context.Context, req *container.DeleteRequest) (*container.DeleteResponse, error) {
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
resp := new(container.DeleteResponse)
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
}
|
|
resp, err := util.EnsureNonNilResponse(s.svc.Delete(ctx, req))
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
}
|
|
|
|
func (s *signService) Get(ctx context.Context, req *container.GetRequest) (*container.GetResponse, error) {
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
resp := new(container.GetResponse)
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
}
|
|
resp, err := util.EnsureNonNilResponse(s.svc.Get(ctx, req))
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
}
|
|
|
|
func (s *signService) List(ctx context.Context, req *container.ListRequest) (*container.ListResponse, error) {
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
resp := new(container.ListResponse)
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
}
|
|
resp, err := util.EnsureNonNilResponse(s.svc.List(ctx, req))
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
}
|
|
|
|
func (s *signService) ListStream(req *container.ListStreamRequest, stream ListStream) error {
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
resp := new(container.ListStreamResponse)
|
|
_ = s.sigSvc.SignResponse(resp, err)
|
|
return stream.Send(resp)
|
|
}
|
|
|
|
ss := &listStreamSigner{
|
|
ListStream: stream,
|
|
sigSvc: s.sigSvc,
|
|
}
|
|
err := s.svc.ListStream(req, ss)
|
|
if err != nil || !ss.nonEmptyResp {
|
|
return ss.send(new(container.ListStreamResponse), err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type listStreamSigner struct {
|
|
ListStream
|
|
sigSvc *util.SignService
|
|
|
|
nonEmptyResp bool // set on first Send call
|
|
}
|
|
|
|
func (s *listStreamSigner) Send(resp *container.ListStreamResponse) error {
|
|
s.nonEmptyResp = true
|
|
return s.send(resp, nil)
|
|
}
|
|
|
|
func (s *listStreamSigner) send(resp *container.ListStreamResponse, err error) error {
|
|
if err := s.sigSvc.SignResponse(resp, err); err != nil {
|
|
return err
|
|
}
|
|
return s.ListStream.Send(resp)
|
|
}
|