2020-07-10 14:17:51 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
eacl "github.com/nspcc-dev/neofs-api-go/acl/extended"
|
2020-07-10 14:17:51 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/container"
|
2020-07-24 13:54:03 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-07-10 14:17:51 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s cnrService) SetExtendedACL(ctx context.Context, req *container.SetExtendedACLRequest) (*container.SetExtendedACLResponse, error) {
|
|
|
|
// check healthiness
|
|
|
|
if err := s.healthy.Healthy(); err != nil {
|
|
|
|
return nil, status.Error(codes.Unavailable, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify request structure
|
|
|
|
if err := requestVerifyFunc(req); err != nil {
|
|
|
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
// unmarshal eACL table
|
|
|
|
table, err := eacl.UnmarshalTable(req.GetEACL())
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Error(
|
|
|
|
codes.InvalidArgument,
|
|
|
|
errors.Wrap(err, "could not decode eACL table").Error(),
|
|
|
|
)
|
|
|
|
}
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
// store eACL table
|
|
|
|
if err := s.aclStore.PutEACL(req.GetID(), table, req.GetSignature()); err != nil {
|
|
|
|
return nil, status.Error(
|
|
|
|
codes.Aborted,
|
|
|
|
errors.Wrap(err, "could not save eACL in storage").Error(),
|
|
|
|
)
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return new(container.SetExtendedACLResponse), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s cnrService) GetExtendedACL(ctx context.Context, req *container.GetExtendedACLRequest) (*container.GetExtendedACLResponse, error) {
|
|
|
|
// check healthiness
|
|
|
|
if err := s.healthy.Healthy(); err != nil {
|
|
|
|
return nil, status.Error(codes.Unavailable, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify request structure
|
|
|
|
if err := requestVerifyFunc(req); err != nil {
|
|
|
|
return nil, status.Error(codes.InvalidArgument, err.Error())
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
// receive binary eACL
|
|
|
|
table, err := s.aclStore.GetEACL(req.GetID())
|
2020-07-10 14:17:51 +00:00
|
|
|
if err != nil {
|
2020-07-24 13:54:03 +00:00
|
|
|
return nil, status.Error(
|
|
|
|
codes.NotFound,
|
|
|
|
errors.Wrap(err, "could not get eACL from storage").Error(),
|
|
|
|
)
|
2020-07-10 14:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fill the response
|
|
|
|
res := new(container.GetExtendedACLResponse)
|
2020-07-24 13:54:03 +00:00
|
|
|
res.SetEACL(eacl.MarshalTable(table))
|
|
|
|
res.SetSignature(nil) // TODO: set signature when will appear.
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|