Aleksey Savchuk
a4fb7f085b
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 2m36s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m3s
Vulncheck / Vulncheck (pull_request) Successful in 2m50s
Tests and linters / Tests (1.22) (pull_request) Successful in 3m3s
DCO action / DCO (pull_request) Successful in 2m47s
Tests and linters / Lint (pull_request) Successful in 3m39s
Tests and linters / Staticcheck (pull_request) Successful in 3m37s
Tests and linters / Tests (1.23) (pull_request) Successful in 3m43s
Build / Build Components (1.22) (pull_request) Successful in 3m32s
Build / Build Components (1.23) (pull_request) Successful in 3m32s
Tests and linters / gopls check (pull_request) Successful in 4m10s
Tests and linters / Tests with -race (pull_request) Successful in 4m16s
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
package container
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util/response"
|
|
)
|
|
|
|
type ServiceExecutor interface {
|
|
Put(context.Context, *session.Token, *container.PutRequestBody) (*container.PutResponseBody, error)
|
|
Delete(context.Context, *session.Token, *container.DeleteRequestBody) (*container.DeleteResponseBody, error)
|
|
Get(context.Context, *container.GetRequestBody) (*container.GetResponseBody, error)
|
|
List(context.Context, *container.ListRequestBody) (*container.ListResponseBody, error)
|
|
}
|
|
|
|
type executorSvc struct {
|
|
Server
|
|
|
|
exec ServiceExecutor
|
|
|
|
respSvc *response.Service
|
|
}
|
|
|
|
// NewExecutionService wraps ServiceExecutor and returns Container Service interface.
|
|
func NewExecutionService(exec ServiceExecutor, respSvc *response.Service) Server {
|
|
return &executorSvc{
|
|
exec: exec,
|
|
respSvc: respSvc,
|
|
}
|
|
}
|
|
|
|
func (s *executorSvc) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) {
|
|
meta := req.GetMetaHeader()
|
|
for origin := meta.GetOrigin(); origin != nil; origin = meta.GetOrigin() {
|
|
meta = origin
|
|
}
|
|
|
|
respBody, err := s.exec.Put(ctx, meta.GetSessionToken(), req.GetBody())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not execute Put request: %w", err)
|
|
}
|
|
|
|
resp := new(container.PutResponse)
|
|
resp.SetBody(respBody)
|
|
|
|
s.respSvc.SetMeta(resp)
|
|
return resp, nil
|
|
}
|
|
|
|
func (s *executorSvc) Delete(ctx context.Context, req *container.DeleteRequest) (*container.DeleteResponse, error) {
|
|
meta := req.GetMetaHeader()
|
|
for origin := meta.GetOrigin(); origin != nil; origin = meta.GetOrigin() {
|
|
meta = origin
|
|
}
|
|
|
|
respBody, err := s.exec.Delete(ctx, meta.GetSessionToken(), req.GetBody())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not execute Delete request: %w", err)
|
|
}
|
|
|
|
resp := new(container.DeleteResponse)
|
|
resp.SetBody(respBody)
|
|
|
|
s.respSvc.SetMeta(resp)
|
|
return resp, nil
|
|
}
|
|
|
|
func (s *executorSvc) Get(ctx context.Context, req *container.GetRequest) (*container.GetResponse, error) {
|
|
respBody, err := s.exec.Get(ctx, req.GetBody())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not execute Get request: %w", err)
|
|
}
|
|
|
|
resp := new(container.GetResponse)
|
|
resp.SetBody(respBody)
|
|
|
|
s.respSvc.SetMeta(resp)
|
|
return resp, nil
|
|
}
|
|
|
|
func (s *executorSvc) List(ctx context.Context, req *container.ListRequest) (*container.ListResponse, error) {
|
|
respBody, err := s.exec.List(ctx, req.GetBody())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not execute List request: %w", err)
|
|
}
|
|
|
|
resp := new(container.ListResponse)
|
|
resp.SetBody(respBody)
|
|
|
|
s.respSvc.SetMeta(resp)
|
|
return resp, nil
|
|
}
|