2020-08-24 14:07:08 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
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"
|
|
|
|
containerMorph "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func NewExecutor(client *containerMorph.Client) containerSvc.ServiceExecutor {
|
2020-10-07 16:17:50 +00:00
|
|
|
w, err := wrapper.New(client)
|
|
|
|
if err != nil {
|
|
|
|
// log there, maybe panic?
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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-10-07 16:17:50 +00:00
|
|
|
cnr := containerSDK.NewContainerFromV2(body.GetContainer())
|
|
|
|
sig := body.GetSignature()
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2020-10-07 16:17:50 +00:00
|
|
|
cid, err := s.wrapper.Put(cnr, sig.GetKey(), sig.GetSign())
|
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())
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2020-10-07 16:17:50 +00:00
|
|
|
err := s.wrapper.Delete(cid, body.GetSignature().GetSign())
|
|
|
|
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
|
|
|
|
2020-10-07 16:17:50 +00:00
|
|
|
cnr, err := s.wrapper.Get(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())
|
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())
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2020-10-07 16:17:50 +00:00
|
|
|
err := s.wrapper.PutEACL(table, body.GetSignature().GetSign())
|
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
|
|
|
|
2020-10-07 16:17:50 +00:00
|
|
|
table, signature, 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())
|
2020-08-24 14:07:08 +00:00
|
|
|
|
2020-09-04 12:18:47 +00:00
|
|
|
// Public key should be obtained by request sender, so we set up only
|
|
|
|
// the signature. Technically, node can make invocation to find container
|
|
|
|
// owner public key, but request sender cannot trust this info.
|
2020-10-07 16:17:50 +00:00
|
|
|
sig := new(refs.Signature)
|
|
|
|
sig.SetSign(signature)
|
|
|
|
|
|
|
|
res.SetSignature(sig)
|
2020-09-04 12:18:47 +00:00
|
|
|
|
2020-08-24 14:07:08 +00:00
|
|
|
return res, nil
|
|
|
|
}
|