2020-08-24 14:07:08 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2021-05-19 12:04:38 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg"
|
2020-10-07 16:17:50 +00:00
|
|
|
eaclSDK "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
|
|
|
|
containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
2020-08-24 14:07:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
2020-10-07 16:17:50 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
2020-08-24 14:07:08 +00:00
|
|
|
containerSvc "github.com/nspcc-dev/neofs-node/pkg/services/container"
|
|
|
|
)
|
|
|
|
|
|
|
|
type morphExecutor struct {
|
2020-10-07 16:17:50 +00:00
|
|
|
wrapper *wrapper.Wrapper
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
2021-05-21 11:02:46 +00:00
|
|
|
func NewExecutor(w *wrapper.Wrapper) containerSvc.ServiceExecutor {
|
2020-08-24 14:07:08 +00:00
|
|
|
return &morphExecutor{
|
2020-10-07 16:17:50 +00:00
|
|
|
wrapper: w,
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody) (*container.PutResponseBody, error) {
|
2020-12-24 10:20:20 +00:00
|
|
|
cnr, err := containerSDK.NewVerifiedFromV2(body.GetContainer())
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("invalid format of the container structure: %w", err)
|
2020-11-03 09:08:24 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 15:25:34 +00:00
|
|
|
cnr.SetSignature(
|
|
|
|
pkg.NewSignatureFromV2(body.GetSignature()),
|
|
|
|
)
|
2020-12-24 10:20:20 +00:00
|
|
|
|
2021-05-25 15:25:34 +00:00
|
|
|
cid, err := wrapper.Put(s.wrapper, cnr)
|
2020-08-24 14:07:08 +00:00
|
|
|
if err != nil {
|
2020-10-07 16:17:50 +00:00
|
|
|
return nil, err
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res := new(container.PutResponseBody)
|
2020-10-07 16:17:50 +00:00
|
|
|
res.SetContainerID(cid.ToV2())
|
2020-08-24 14:07:08 +00:00
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *morphExecutor) Delete(ctx context.Context, body *container.DeleteRequestBody) (*container.DeleteResponseBody, error) {
|
2020-10-07 16:17:50 +00:00
|
|
|
cid := containerSDK.NewIDFromV2(body.GetContainerID())
|
2021-05-19 15:57:08 +00:00
|
|
|
sig := pkg.NewSignatureFromV2(body.GetSignature())
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2021-05-19 15:57:08 +00:00
|
|
|
err := wrapper.Delete(s.wrapper, cid, sig)
|
2020-10-07 16:17:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new(container.DeleteResponseBody), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *morphExecutor) Get(ctx context.Context, body *container.GetRequestBody) (*container.GetResponseBody, error) {
|
2020-10-07 16:17:50 +00:00
|
|
|
cid := containerSDK.NewIDFromV2(body.GetContainerID())
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2021-05-19 16:32:25 +00:00
|
|
|
cnr, err := wrapper.Get(s.wrapper, cid)
|
2020-08-24 14:07:08 +00:00
|
|
|
if err != nil {
|
2020-10-07 16:17:50 +00:00
|
|
|
return nil, err
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res := new(container.GetResponseBody)
|
2020-10-07 16:17:50 +00:00
|
|
|
res.SetContainer(cnr.ToV2())
|
2021-05-25 15:10:34 +00:00
|
|
|
res.SetSignature(cnr.Signature().ToV2())
|
|
|
|
res.SetSessionToken(cnr.SessionToken().ToV2())
|
2020-08-24 14:07:08 +00:00
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *morphExecutor) List(ctx context.Context, body *container.ListRequestBody) (*container.ListResponseBody, error) {
|
2020-10-07 16:17:50 +00:00
|
|
|
oid := owner.NewIDFromV2(body.GetOwnerID())
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2020-10-07 16:17:50 +00:00
|
|
|
cnrs, err := s.wrapper.List(oid)
|
2020-08-24 14:07:08 +00:00
|
|
|
if err != nil {
|
2020-10-07 16:17:50 +00:00
|
|
|
return nil, err
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 16:17:50 +00:00
|
|
|
cidList := make([]*refs.ContainerID, 0, len(cnrs))
|
|
|
|
for i := range cnrs {
|
|
|
|
cidList = append(cidList, cnrs[i].ToV2())
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res := new(container.ListResponseBody)
|
|
|
|
res.SetContainerIDs(cidList)
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *morphExecutor) SetExtendedACL(ctx context.Context, body *container.SetExtendedACLRequestBody) (*container.SetExtendedACLResponseBody, error) {
|
2020-10-07 16:17:50 +00:00
|
|
|
table := eaclSDK.NewTableFromV2(body.GetEACL())
|
2021-05-19 12:04:38 +00:00
|
|
|
sign := pkg.NewSignatureFromV2(body.GetSignature())
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2021-05-19 12:04:38 +00:00
|
|
|
err := wrapper.PutEACL(s.wrapper, table, sign)
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2020-10-07 16:17:50 +00:00
|
|
|
return new(container.SetExtendedACLResponseBody), err
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 16:17:50 +00:00
|
|
|
func (s *morphExecutor) GetExtendedACL(ctx context.Context, body *container.GetExtendedACLRequestBody) (*container.GetExtendedACLResponseBody, error) {
|
|
|
|
cid := containerSDK.NewIDFromV2(body.GetContainerID())
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2021-05-25 15:18:32 +00:00
|
|
|
table, err := s.wrapper.GetEACL(cid)
|
2020-08-24 14:07:08 +00:00
|
|
|
if err != nil {
|
2020-10-07 16:17:50 +00:00
|
|
|
return nil, err
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
res := new(container.GetExtendedACLResponseBody)
|
2020-10-07 16:17:50 +00:00
|
|
|
res.SetEACL(table.ToV2())
|
2021-05-25 15:18:32 +00:00
|
|
|
res.SetSignature(table.Signature().ToV2())
|
2021-05-25 15:12:23 +00:00
|
|
|
res.SetSessionToken(table.SessionToken().ToV2())
|
2020-09-04 12:18:47 +00:00
|
|
|
|
2020-08-24 14:07:08 +00:00
|
|
|
return res, nil
|
|
|
|
}
|