2020-09-26 07:54:03 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
2020-12-08 16:18:24 +00:00
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
2020-12-08 16:18:24 +00:00
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
|
|
objectSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object"
|
|
|
|
getsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/get"
|
|
|
|
objutil "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2020-09-26 07:54:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Service implements Get operation of Object service v2.
|
|
|
|
type Service struct {
|
2022-12-30 11:19:42 +00:00
|
|
|
cfg
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Option represents Service constructor option.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
|
|
|
svc *getsvc.Service
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
keyStorage *objutil.KeyStorage
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewService constructs Service instance from provided options.
|
|
|
|
func NewService(opts ...Option) *Service {
|
2022-12-30 11:19:42 +00:00
|
|
|
var s Service
|
2020-09-26 07:54:03 +00:00
|
|
|
|
|
|
|
for i := range opts {
|
2022-12-30 11:19:42 +00:00
|
|
|
opts[i](&s.cfg)
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 11:19:42 +00:00
|
|
|
return &s
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get calls internal service and returns v2 object stream.
|
2020-12-02 23:45:25 +00:00
|
|
|
func (s *Service) Get(req *objectV2.GetRequest, stream objectSvc.GetObjectStream) error {
|
|
|
|
p, err := s.toPrm(req, stream)
|
2020-09-26 07:54:03 +00:00
|
|
|
if err != nil {
|
2020-12-02 23:45:25 +00:00
|
|
|
return err
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
err = s.svc.Get(stream.Context(), *p)
|
|
|
|
|
|
|
|
var splitErr *object.SplitInfoError
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case errors.As(err, &splitErr):
|
|
|
|
return stream.Send(splitInfoResponse(splitErr.SplitInfo()))
|
|
|
|
default:
|
|
|
|
return err
|
|
|
|
}
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
// GetRange calls internal service and returns v2 payload range stream.
|
|
|
|
func (s *Service) GetRange(req *objectV2.GetRangeRequest, stream objectSvc.GetObjectRangeStream) error {
|
|
|
|
p, err := s.toRangePrm(req, stream)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.svc.GetRange(stream.Context(), *p)
|
|
|
|
|
|
|
|
var splitErr *object.SplitInfoError
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case errors.As(err, &splitErr):
|
|
|
|
return stream.Send(splitInfoRangeResponse(splitErr.SplitInfo()))
|
|
|
|
default:
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 16:18:24 +00:00
|
|
|
// GetRangeHash calls internal service and returns v2 response.
|
|
|
|
func (s *Service) GetRangeHash(ctx context.Context, req *objectV2.GetRangeHashRequest) (*objectV2.GetRangeHashResponse, error) {
|
|
|
|
p, err := s.toHashRangePrm(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := s.svc.GetRangeHash(ctx, *p)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return toHashResponse(req.GetBody().GetType(), res), nil
|
|
|
|
}
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// Head serves ForstFS API v2 compatible HEAD requests.
|
2020-12-09 10:32:33 +00:00
|
|
|
func (s *Service) Head(ctx context.Context, req *objectV2.HeadRequest) (*objectV2.HeadResponse, error) {
|
|
|
|
resp := new(objectV2.HeadResponse)
|
|
|
|
resp.SetBody(new(objectV2.HeadResponseBody))
|
|
|
|
|
2021-04-29 12:18:29 +00:00
|
|
|
p, err := s.toHeadPrm(ctx, req, resp)
|
2020-12-09 10:32:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.svc.Head(ctx, *p)
|
|
|
|
|
|
|
|
var splitErr *object.SplitInfoError
|
|
|
|
|
|
|
|
if errors.As(err, &splitErr) {
|
|
|
|
setSplitInfoHeadResponse(splitErr.SplitInfo(), resp)
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
|
2020-09-26 07:54:03 +00:00
|
|
|
func WithInternalService(v *getsvc.Service) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.svc = v
|
|
|
|
}
|
|
|
|
}
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
// WithKeyStorage returns option to set local private key storage.
|
|
|
|
func WithKeyStorage(ks *objutil.KeyStorage) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.keyStorage = ks
|
|
|
|
}
|
|
|
|
}
|