[#7] Fix container service according to APIv2 contracts
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
2ab855b2ec
commit
da92f2944f
4 changed files with 11 additions and 38 deletions
|
@ -7,17 +7,9 @@ import "github.com/pkg/errors"
|
||||||
type DeleteArgs struct {
|
type DeleteArgs struct {
|
||||||
cid []byte // container identifier
|
cid []byte // container identifier
|
||||||
|
|
||||||
ownerID []byte // container owner identifier
|
|
||||||
|
|
||||||
sig []byte // container identifier signature
|
sig []byte // container identifier signature
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOwnerID sets the container owner identifier
|
|
||||||
// in a binary format.
|
|
||||||
func (p *DeleteArgs) SetOwnerID(v []byte) {
|
|
||||||
p.ownerID = v
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetCID sets the container identifier
|
// SetCID sets the container identifier
|
||||||
// in a binary format.
|
// in a binary format.
|
||||||
func (p *DeleteArgs) SetCID(v []byte) {
|
func (p *DeleteArgs) SetCID(v []byte) {
|
||||||
|
@ -36,7 +28,6 @@ func (c *Client) Delete(args DeleteArgs) error {
|
||||||
return errors.Wrapf(c.client.Invoke(
|
return errors.Wrapf(c.client.Invoke(
|
||||||
c.deleteMethod,
|
c.deleteMethod,
|
||||||
args.cid,
|
args.cid,
|
||||||
args.ownerID,
|
|
||||||
args.sig,
|
args.sig,
|
||||||
), "could not invoke method (%s)", c.deleteMethod)
|
), "could not invoke method (%s)", c.deleteMethod)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,17 @@ import (
|
||||||
// PutArgs groups the arguments
|
// PutArgs groups the arguments
|
||||||
// of put container invocation call.
|
// of put container invocation call.
|
||||||
type PutArgs struct {
|
type PutArgs struct {
|
||||||
ownerID []byte // container owner identifier
|
|
||||||
|
|
||||||
cnr []byte // container in a binary format
|
cnr []byte // container in a binary format
|
||||||
|
|
||||||
sig []byte // binary container signature
|
sig []byte // binary container signature
|
||||||
|
|
||||||
|
publicKey []byte // public key of container owner
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOwnerID sets the container owner identifier
|
// SetPublicKey sets the public key of container owner
|
||||||
// in a binary format.
|
// in a binary format.
|
||||||
func (p *PutArgs) SetOwnerID(v []byte) {
|
func (p *PutArgs) SetPublicKey(v []byte) {
|
||||||
p.ownerID = v
|
p.publicKey = v
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetContainer sets the container structure
|
// SetContainer sets the container structure
|
||||||
|
@ -37,8 +37,8 @@ func (p *PutArgs) SetSignature(v []byte) {
|
||||||
func (c *Client) Put(args PutArgs) error {
|
func (c *Client) Put(args PutArgs) error {
|
||||||
return errors.Wrapf(c.client.Invoke(
|
return errors.Wrapf(c.client.Invoke(
|
||||||
c.putMethod,
|
c.putMethod,
|
||||||
args.ownerID,
|
|
||||||
args.cnr,
|
args.cnr,
|
||||||
args.sig,
|
args.sig,
|
||||||
|
args.publicKey,
|
||||||
), "could not invoke method (%s)", c.putMethod)
|
), "could not invoke method (%s)", c.putMethod)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,6 @@ func NewExecutor(client *containerMorph.Client) containerSvc.ServiceExecutor {
|
||||||
func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody) (*container.PutResponseBody, error) {
|
func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody) (*container.PutResponseBody, error) {
|
||||||
cnr := body.GetContainer()
|
cnr := body.GetContainer()
|
||||||
|
|
||||||
// marshal owner ID of the container
|
|
||||||
ownerBytes, err := cnr.GetOwnerID().StableMarshal(nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not marshal owner ID")
|
|
||||||
}
|
|
||||||
|
|
||||||
// marshal the container
|
// marshal the container
|
||||||
cnrBytes, err := cnr.StableMarshal(nil)
|
cnrBytes, err := cnr.StableMarshal(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -41,9 +35,9 @@ func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
args := containerMorph.PutArgs{}
|
args := containerMorph.PutArgs{}
|
||||||
args.SetOwnerID(ownerBytes)
|
|
||||||
args.SetContainer(cnrBytes)
|
args.SetContainer(cnrBytes)
|
||||||
args.SetSignature(body.GetSignature().GetSign())
|
args.SetSignature(body.GetSignature().GetSign())
|
||||||
|
args.SetPublicKey(body.GetSignature().GetKey())
|
||||||
|
|
||||||
if err := s.client.Put(args); err != nil {
|
if err := s.client.Put(args); err != nil {
|
||||||
return nil, errors.Wrap(err, "could not call Put method")
|
return nil, errors.Wrap(err, "could not call Put method")
|
||||||
|
@ -61,14 +55,8 @@ func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *morphExecutor) Delete(ctx context.Context, body *container.DeleteRequestBody) (*container.DeleteResponseBody, error) {
|
func (s *morphExecutor) Delete(ctx context.Context, body *container.DeleteRequestBody) (*container.DeleteResponseBody, error) {
|
||||||
// marshal container identifier
|
|
||||||
cidBytes, err := body.GetContainerID().StableMarshal(nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not marshal container ID")
|
|
||||||
}
|
|
||||||
|
|
||||||
args := containerMorph.DeleteArgs{}
|
args := containerMorph.DeleteArgs{}
|
||||||
args.SetCID(cidBytes)
|
args.SetCID(body.GetContainerID().GetValue())
|
||||||
args.SetSignature(body.GetSignature().GetSign())
|
args.SetSignature(body.GetSignature().GetSign())
|
||||||
|
|
||||||
if err := s.client.Delete(args); err != nil {
|
if err := s.client.Delete(args); err != nil {
|
||||||
|
@ -100,14 +88,8 @@ func (s *morphExecutor) Get(ctx context.Context, body *container.GetRequestBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *morphExecutor) List(ctx context.Context, body *container.ListRequestBody) (*container.ListResponseBody, error) {
|
func (s *morphExecutor) List(ctx context.Context, body *container.ListRequestBody) (*container.ListResponseBody, error) {
|
||||||
// marshal owner ID
|
|
||||||
ownerBytes, err := body.GetOwnerID().StableMarshal(nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not marshal owner ID")
|
|
||||||
}
|
|
||||||
|
|
||||||
args := containerMorph.ListArgs{}
|
args := containerMorph.ListArgs{}
|
||||||
args.SetOwnerID(ownerBytes)
|
args.SetOwnerID(body.GetOwnerID().GetValue())
|
||||||
|
|
||||||
val, err := s.client.List(args)
|
val, err := s.client.List(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -37,7 +37,7 @@ func (s *signService) Put(ctx context.Context, req *container.PutRequest) (*cont
|
||||||
func (s *signService) Delete(ctx context.Context, req *container.DeleteRequest) (*container.DeleteResponse, error) {
|
func (s *signService) Delete(ctx context.Context, req *container.DeleteRequest) (*container.DeleteResponse, error) {
|
||||||
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
|
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
|
||||||
func(ctx context.Context, req interface{}) (interface{}, error) {
|
func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
return s.svc.Get(ctx, req.(*container.GetRequest))
|
return s.svc.Delete(ctx, req.(*container.DeleteRequest))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,7 +50,7 @@ func (s *signService) Delete(ctx context.Context, req *container.DeleteRequest)
|
||||||
func (s *signService) Get(ctx context.Context, req *container.GetRequest) (*container.GetResponse, error) {
|
func (s *signService) Get(ctx context.Context, req *container.GetRequest) (*container.GetResponse, error) {
|
||||||
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
|
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
|
||||||
func(ctx context.Context, req interface{}) (interface{}, error) {
|
func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
return s.svc.Delete(ctx, req.(*container.DeleteRequest))
|
return s.svc.Get(ctx, req.(*container.GetRequest))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue