2020-09-21 14:31:31 +00:00
|
|
|
package putsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2020-09-21 14:31:31 +00:00
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/object"
|
|
|
|
putsvc "github.com/TrueCloudLab/frostfs-node/pkg/services/object/put"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
2020-09-21 14:31:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Service implements Put operation of Object service v2.
|
|
|
|
type Service struct {
|
2022-12-30 11:19:42 +00:00
|
|
|
cfg
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Option represents Service constructor option.
|
|
|
|
type Option func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
2021-05-28 13:26:32 +00:00
|
|
|
svc *putsvc.Service
|
|
|
|
keyStorage *util.KeyStorage
|
2020-09-21 14:31:31 +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-21 14:31:31 +00:00
|
|
|
|
|
|
|
for i := range opts {
|
2022-12-30 11:19:42 +00:00
|
|
|
opts[i](&s.cfg)
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 11:19:42 +00:00
|
|
|
return &s
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put calls internal service and returns v2 object streamer.
|
2021-03-15 10:53:08 +00:00
|
|
|
func (s *Service) Put(ctx context.Context) (object.PutObjectStream, error) {
|
2020-09-21 14:31:31 +00:00
|
|
|
stream, err := s.svc.Put(ctx)
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("(%T) could not open object put stream: %w", s, err)
|
2020-09-21 14:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &streamer{
|
2021-05-28 13:26:32 +00:00
|
|
|
stream: stream,
|
|
|
|
keyStorage: s.keyStorage,
|
2020-09-21 14:31:31 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithInternalService(v *putsvc.Service) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.svc = v
|
|
|
|
}
|
|
|
|
}
|
2021-05-28 13:26:32 +00:00
|
|
|
|
|
|
|
func WithKeyStorage(ks *util.KeyStorage) Option {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.keyStorage = ks
|
|
|
|
}
|
|
|
|
}
|