2024-04-24 17:23:15 +00:00
|
|
|
package apemanager
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util"
|
2024-11-07 14:32:10 +00:00
|
|
|
apemanager_v2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/apemanager"
|
2024-04-24 17:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type signService struct {
|
|
|
|
sigSvc *util.SignService
|
|
|
|
|
|
|
|
next Server
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSignService(key *ecdsa.PrivateKey, next Server) Server {
|
|
|
|
return &signService{
|
|
|
|
sigSvc: util.NewUnarySignService(key),
|
|
|
|
next: next,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signService) AddChain(ctx context.Context, req *apemanager_v2.AddChainRequest) (*apemanager_v2.AddChainResponse, error) {
|
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(apemanager_v2.AddChainResponse)
|
|
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
|
|
}
|
|
|
|
resp, err := util.EnsureNonNilResponse(s.next.AddChain(ctx, req))
|
|
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signService) RemoveChain(ctx context.Context, req *apemanager_v2.RemoveChainRequest) (*apemanager_v2.RemoveChainResponse, error) {
|
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(apemanager_v2.RemoveChainResponse)
|
|
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
|
|
}
|
|
|
|
resp, err := util.EnsureNonNilResponse(s.next.RemoveChain(ctx, req))
|
|
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *signService) ListChains(ctx context.Context, req *apemanager_v2.ListChainsRequest) (*apemanager_v2.ListChainsResponse, error) {
|
|
|
|
if err := s.sigSvc.VerifyRequest(req); err != nil {
|
|
|
|
resp := new(apemanager_v2.ListChainsResponse)
|
|
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
|
|
}
|
|
|
|
resp, err := util.EnsureNonNilResponse(s.next.ListChains(ctx, req))
|
|
|
|
return resp, s.sigSvc.SignResponse(resp, err)
|
|
|
|
}
|