2020-08-24 14:07:08 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util"
|
2020-08-24 14:07:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type signService struct {
|
2020-08-26 09:43:39 +00:00
|
|
|
sigSvc *util.SignService
|
2020-08-26 09:20:26 +00:00
|
|
|
|
2021-03-15 10:53:08 +00:00
|
|
|
svc Server
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 10:53:08 +00:00
|
|
|
func NewSignService(key *ecdsa.PrivateKey, svc Server) Server {
|
2020-08-24 14:07:08 +00:00
|
|
|
return &signService{
|
2020-08-26 09:43:39 +00:00
|
|
|
sigSvc: util.NewUnarySignService(key),
|
|
|
|
svc: svc,
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signService) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) {
|
2022-12-30 15:26:43 +00:00
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(container.PutResponse)
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
2022-12-30 15:26:43 +00:00
|
|
|
resp, err := util.EnsureNonNilResponse(s.svc.Put(ctx, req))
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signService) Delete(ctx context.Context, req *container.DeleteRequest) (*container.DeleteResponse, error) {
|
2022-12-30 15:26:43 +00:00
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(container.DeleteResponse)
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
2022-12-30 15:26:43 +00:00
|
|
|
resp, err := util.EnsureNonNilResponse(s.svc.Delete(ctx, req))
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signService) Get(ctx context.Context, req *container.GetRequest) (*container.GetResponse, error) {
|
2022-12-30 15:26:43 +00:00
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(container.GetResponse)
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
2022-12-30 15:26:43 +00:00
|
|
|
resp, err := util.EnsureNonNilResponse(s.svc.Get(ctx, req))
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signService) List(ctx context.Context, req *container.ListRequest) (*container.ListResponse, error) {
|
2022-12-30 15:26:43 +00:00
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(container.ListResponse)
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
2022-12-30 15:26:43 +00:00
|
|
|
resp, err := util.EnsureNonNilResponse(s.svc.List(ctx, req))
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signService) SetExtendedACL(ctx context.Context, req *container.SetExtendedACLRequest) (*container.SetExtendedACLResponse, error) {
|
2022-12-30 15:26:43 +00:00
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(container.SetExtendedACLResponse)
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
2022-12-30 15:26:43 +00:00
|
|
|
resp, err := util.EnsureNonNilResponse(s.svc.SetExtendedACL(ctx, req))
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signService) GetExtendedACL(ctx context.Context, req *container.GetExtendedACLRequest) (*container.GetExtendedACLResponse, error) {
|
2022-12-30 15:26:43 +00:00
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(container.GetExtendedACLResponse)
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
2022-12-30 15:26:43 +00:00
|
|
|
resp, err := util.EnsureNonNilResponse(s.svc.GetExtendedACL(ctx, req))
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2020-08-24 14:07:08 +00:00
|
|
|
}
|
2021-02-01 12:43:09 +00:00
|
|
|
|
|
|
|
func (s *signService) AnnounceUsedSpace(ctx context.Context, req *container.AnnounceUsedSpaceRequest) (*container.AnnounceUsedSpaceResponse, error) {
|
2022-12-30 15:26:43 +00:00
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(container.AnnounceUsedSpaceResponse)
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2021-02-01 12:43:09 +00:00
|
|
|
}
|
2022-12-30 15:26:43 +00:00
|
|
|
resp, err := util.EnsureNonNilResponse(s.svc.AnnounceUsedSpace(ctx, req))
|
|
|
|
return resp, s.sigSvc.SignResponse(req, resp, err)
|
2021-02-01 12:43:09 +00:00
|
|
|
}
|