frostfs-node/pkg/network/transport/container/grpc/acl.go

71 lines
1.9 KiB
Go
Raw Normal View History

package container
import (
"context"
2020-07-24 13:54:03 +00:00
eacl "github.com/nspcc-dev/neofs-api-go/acl/extended"
"github.com/nspcc-dev/neofs-api-go/container"
2020-07-24 13:54:03 +00:00
"github.com/pkg/errors"
"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-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(),
)
}
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())
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(),
)
}
// 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.
return res, nil
}