forked from TrueCloudLab/frostfs-node
[#13] services/util: Rename UnarySignService to SingService
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
75162d1f8d
commit
d54a5d4f66
5 changed files with 31 additions and 31 deletions
|
@ -9,20 +9,20 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type signService struct {
|
type signService struct {
|
||||||
unarySigService *util.UnarySignService
|
sigSvc *util.SignService
|
||||||
|
|
||||||
svc accounting.Service
|
svc accounting.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSignService(key *ecdsa.PrivateKey, svc accounting.Service) accounting.Service {
|
func NewSignService(key *ecdsa.PrivateKey, svc accounting.Service) accounting.Service {
|
||||||
return &signService{
|
return &signService{
|
||||||
unarySigService: util.NewUnarySignService(key),
|
sigSvc: util.NewUnarySignService(key),
|
||||||
svc: svc,
|
svc: svc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) Balance(ctx context.Context, req *accounting.BalanceRequest) (*accounting.BalanceResponse, error) {
|
func (s *signService) Balance(ctx context.Context, req *accounting.BalanceRequest) (*accounting.BalanceResponse, error) {
|
||||||
resp, err := s.unarySigService.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.Balance(ctx, req.(*accounting.BalanceRequest))
|
return s.svc.Balance(ctx, req.(*accounting.BalanceRequest))
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,20 +9,20 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type signService struct {
|
type signService struct {
|
||||||
unarySigService *util.UnarySignService
|
sigSvc *util.SignService
|
||||||
|
|
||||||
svc container.Service
|
svc container.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSignService(key *ecdsa.PrivateKey, svc container.Service) container.Service {
|
func NewSignService(key *ecdsa.PrivateKey, svc container.Service) container.Service {
|
||||||
return &signService{
|
return &signService{
|
||||||
unarySigService: util.NewUnarySignService(key),
|
sigSvc: util.NewUnarySignService(key),
|
||||||
svc: svc,
|
svc: svc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) {
|
func (s *signService) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) {
|
||||||
resp, err := s.unarySigService.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.Put(ctx, req.(*container.PutRequest))
|
return s.svc.Put(ctx, req.(*container.PutRequest))
|
||||||
},
|
},
|
||||||
|
@ -35,7 +35,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.unarySigService.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.Get(ctx, req.(*container.GetRequest))
|
||||||
},
|
},
|
||||||
|
@ -48,7 +48,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.unarySigService.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.Delete(ctx, req.(*container.DeleteRequest))
|
||||||
},
|
},
|
||||||
|
@ -61,7 +61,7 @@ func (s *signService) Get(ctx context.Context, req *container.GetRequest) (*cont
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) List(ctx context.Context, req *container.ListRequest) (*container.ListResponse, error) {
|
func (s *signService) List(ctx context.Context, req *container.ListRequest) (*container.ListResponse, error) {
|
||||||
resp, err := s.unarySigService.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.List(ctx, req.(*container.ListRequest))
|
return s.svc.List(ctx, req.(*container.ListRequest))
|
||||||
},
|
},
|
||||||
|
@ -74,7 +74,7 @@ func (s *signService) List(ctx context.Context, req *container.ListRequest) (*co
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) SetExtendedACL(ctx context.Context, req *container.SetExtendedACLRequest) (*container.SetExtendedACLResponse, error) {
|
func (s *signService) SetExtendedACL(ctx context.Context, req *container.SetExtendedACLRequest) (*container.SetExtendedACLResponse, error) {
|
||||||
resp, err := s.unarySigService.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.SetExtendedACL(ctx, req.(*container.SetExtendedACLRequest))
|
return s.svc.SetExtendedACL(ctx, req.(*container.SetExtendedACLRequest))
|
||||||
},
|
},
|
||||||
|
@ -87,7 +87,7 @@ func (s *signService) SetExtendedACL(ctx context.Context, req *container.SetExte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) GetExtendedACL(ctx context.Context, req *container.GetExtendedACLRequest) (*container.GetExtendedACLResponse, error) {
|
func (s *signService) GetExtendedACL(ctx context.Context, req *container.GetExtendedACLRequest) (*container.GetExtendedACLResponse, error) {
|
||||||
resp, err := s.unarySigService.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.GetExtendedACL(ctx, req.(*container.GetExtendedACLRequest))
|
return s.svc.GetExtendedACL(ctx, req.(*container.GetExtendedACLRequest))
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
type signService struct {
|
type signService struct {
|
||||||
key *ecdsa.PrivateKey
|
key *ecdsa.PrivateKey
|
||||||
|
|
||||||
unarySigService *util.UnarySignService
|
sigSvc *util.SignService
|
||||||
|
|
||||||
svc object.Service
|
svc object.Service
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ type getRangeStreamSigner struct {
|
||||||
func NewSignService(key *ecdsa.PrivateKey, svc object.Service) object.Service {
|
func NewSignService(key *ecdsa.PrivateKey, svc object.Service) object.Service {
|
||||||
return &signService{
|
return &signService{
|
||||||
key: key,
|
key: key,
|
||||||
unarySigService: util.NewUnarySignService(key),
|
sigSvc: util.NewUnarySignService(key),
|
||||||
svc: svc,
|
svc: svc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func (s *getStreamSigner) Recv() (*object.GetResponse, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) Get(ctx context.Context, req *object.GetRequest) (object.GetObjectStreamer, error) {
|
func (s *signService) Get(ctx context.Context, req *object.GetRequest) (object.GetObjectStreamer, error) {
|
||||||
stream, err := s.unarySigService.HandleServerStreamRequest(ctx, req,
|
stream, err := s.sigSvc.HandleServerStreamRequest(ctx, req,
|
||||||
func(ctx context.Context, req interface{}) (util.MessageReader, error) {
|
func(ctx context.Context, req interface{}) (util.MessageReader, error) {
|
||||||
stream, err := s.svc.Get(ctx, req.(*object.GetRequest))
|
stream, err := s.svc.Get(ctx, req.(*object.GetRequest))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -109,7 +109,7 @@ func (s *signService) Put(ctx context.Context) (object.PutObjectStreamer, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) Head(ctx context.Context, req *object.HeadRequest) (*object.HeadResponse, error) {
|
func (s *signService) Head(ctx context.Context, req *object.HeadRequest) (*object.HeadResponse, error) {
|
||||||
resp, err := s.unarySigService.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.Head(ctx, req.(*object.HeadRequest))
|
return s.svc.Head(ctx, req.(*object.HeadRequest))
|
||||||
},
|
},
|
||||||
|
@ -131,7 +131,7 @@ func (s *searchStreamSigner) Recv() (*object.SearchResponse, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) Search(ctx context.Context, req *object.SearchRequest) (object.SearchObjectStreamer, error) {
|
func (s *signService) Search(ctx context.Context, req *object.SearchRequest) (object.SearchObjectStreamer, error) {
|
||||||
stream, err := s.unarySigService.HandleServerStreamRequest(ctx, req,
|
stream, err := s.sigSvc.HandleServerStreamRequest(ctx, req,
|
||||||
func(ctx context.Context, req interface{}) (util.MessageReader, error) {
|
func(ctx context.Context, req interface{}) (util.MessageReader, error) {
|
||||||
stream, err := s.svc.Search(ctx, req.(*object.SearchRequest))
|
stream, err := s.svc.Search(ctx, req.(*object.SearchRequest))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -153,7 +153,7 @@ func (s *signService) Search(ctx context.Context, req *object.SearchRequest) (ob
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) Delete(ctx context.Context, req *object.DeleteRequest) (*object.DeleteResponse, error) {
|
func (s *signService) Delete(ctx context.Context, req *object.DeleteRequest) (*object.DeleteResponse, error) {
|
||||||
resp, err := s.unarySigService.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.(*object.DeleteRequest))
|
return s.svc.Delete(ctx, req.(*object.DeleteRequest))
|
||||||
},
|
},
|
||||||
|
@ -175,7 +175,7 @@ func (s *getRangeStreamSigner) Recv() (*object.GetRangeResponse, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) GetRange(ctx context.Context, req *object.GetRangeRequest) (object.GetRangeObjectStreamer, error) {
|
func (s *signService) GetRange(ctx context.Context, req *object.GetRangeRequest) (object.GetRangeObjectStreamer, error) {
|
||||||
stream, err := s.unarySigService.HandleServerStreamRequest(ctx, req,
|
stream, err := s.sigSvc.HandleServerStreamRequest(ctx, req,
|
||||||
func(ctx context.Context, req interface{}) (util.MessageReader, error) {
|
func(ctx context.Context, req interface{}) (util.MessageReader, error) {
|
||||||
stream, err := s.svc.GetRange(ctx, req.(*object.GetRangeRequest))
|
stream, err := s.svc.GetRange(ctx, req.(*object.GetRangeRequest))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -197,7 +197,7 @@ func (s *signService) GetRange(ctx context.Context, req *object.GetRangeRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) GetRangeHash(ctx context.Context, req *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
|
func (s *signService) GetRangeHash(ctx context.Context, req *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
|
||||||
resp, err := s.unarySigService.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.GetRangeHash(ctx, req.(*object.GetRangeHashRequest))
|
return s.svc.GetRangeHash(ctx, req.(*object.GetRangeHashRequest))
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,19 +9,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type signService struct {
|
type signService struct {
|
||||||
unarySigService *util.UnarySignService
|
sigSvc *util.SignService
|
||||||
|
|
||||||
svc session.Service
|
svc session.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSignService(key *ecdsa.PrivateKey, svc session.Service) session.Service {
|
func NewSignService(key *ecdsa.PrivateKey, svc session.Service) session.Service {
|
||||||
return &signService{
|
return &signService{
|
||||||
unarySigService: util.NewUnarySignService(key),
|
sigSvc: util.NewUnarySignService(key),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signService) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error) {
|
func (s *signService) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error) {
|
||||||
resp, err := s.unarySigService.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.Create(ctx, req.(*session.CreateRequest))
|
return s.svc.Create(ctx, req.(*session.CreateRequest))
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
type UnaryHandler func(context.Context, interface{}) (interface{}, error)
|
type UnaryHandler func(context.Context, interface{}) (interface{}, error)
|
||||||
|
|
||||||
type UnarySignService struct {
|
type SignService struct {
|
||||||
key *ecdsa.PrivateKey
|
key *ecdsa.PrivateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ type MessageStreamer struct {
|
||||||
recv MessageReader
|
recv MessageReader
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUnarySignService(key *ecdsa.PrivateKey) *UnarySignService {
|
func NewUnarySignService(key *ecdsa.PrivateKey) *SignService {
|
||||||
return &UnarySignService{
|
return &SignService{
|
||||||
key: key,
|
key: key,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ func (s *MessageStreamer) Recv() (interface{}, error) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UnarySignService) HandleServerStreamRequest(ctx context.Context, req interface{}, handler ServerStreamHandler) (*MessageStreamer, error) {
|
func (s *SignService) HandleServerStreamRequest(ctx context.Context, req interface{}, handler ServerStreamHandler) (*MessageStreamer, error) {
|
||||||
// verify request signatures
|
// verify request signatures
|
||||||
if err := signature.VerifyServiceMessage(req); err != nil {
|
if err := signature.VerifyServiceMessage(req); err != nil {
|
||||||
return nil, errors.Wrap(err, "could not verify request")
|
return nil, errors.Wrap(err, "could not verify request")
|
||||||
|
@ -60,7 +60,7 @@ func (s *UnarySignService) HandleServerStreamRequest(ctx context.Context, req in
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UnarySignService) HandleUnaryRequest(ctx context.Context, req interface{}, handler UnaryHandler) (interface{}, error) {
|
func (s *SignService) HandleUnaryRequest(ctx context.Context, req interface{}, handler UnaryHandler) (interface{}, error) {
|
||||||
// verify request signatures
|
// verify request signatures
|
||||||
if err := signature.VerifyServiceMessage(req); err != nil {
|
if err := signature.VerifyServiceMessage(req); err != nil {
|
||||||
return nil, errors.Wrap(err, "could not verify request")
|
return nil, errors.Wrap(err, "could not verify request")
|
||||||
|
|
Loading…
Reference in a new issue