2020-07-24 16:10:41 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2023-03-02 14:54:33 +00:00
|
|
|
"encoding/xml"
|
2020-08-06 10:49:25 +00:00
|
|
|
"errors"
|
2023-03-02 14:54:33 +00:00
|
|
|
"io"
|
2022-11-08 09:12:55 +00:00
|
|
|
"time"
|
2020-07-24 16:10:41 +00:00
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2020-07-24 16:10:41 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
handler struct {
|
2022-04-29 13:08:22 +00:00
|
|
|
log *zap.Logger
|
|
|
|
obj layer.Client
|
|
|
|
notificator Notificator
|
|
|
|
cfg *Config
|
|
|
|
}
|
|
|
|
|
|
|
|
Notificator interface {
|
|
|
|
SendNotifications(topics map[string]string, p *SendNotificationParams) error
|
2022-11-08 09:12:55 +00:00
|
|
|
SendTestNotification(topic, bucketName, requestID, HostID string, now time.Time) error
|
2021-08-23 18:39:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// Config contains data which handler needs to keep.
|
2021-08-23 18:39:15 +00:00
|
|
|
Config struct {
|
2023-03-20 08:44:35 +00:00
|
|
|
Policy PlacementPolicy
|
|
|
|
XMLDecoder XMLDecoderProvider
|
|
|
|
DefaultMaxAge int
|
|
|
|
NotificatorEnabled bool
|
|
|
|
CopiesNumber uint32
|
|
|
|
ResolveZoneList []string
|
|
|
|
IsResolveListAllow bool // True if ResolveZoneList contains allowed zones
|
|
|
|
CompleteMultipartKeepalive time.Duration
|
2020-07-24 16:10:41 +00:00
|
|
|
}
|
2022-11-03 06:34:18 +00:00
|
|
|
|
2022-11-14 09:37:47 +00:00
|
|
|
PlacementPolicy interface {
|
|
|
|
Default() netmap.PlacementPolicy
|
|
|
|
Get(string) (netmap.PlacementPolicy, bool)
|
2022-11-03 06:34:18 +00:00
|
|
|
}
|
2023-03-02 14:54:33 +00:00
|
|
|
|
|
|
|
XMLDecoderProvider interface {
|
|
|
|
NewCompleteMultipartDecoder(io.Reader) *xml.Decoder
|
|
|
|
}
|
2020-07-24 16:10:41 +00:00
|
|
|
)
|
|
|
|
|
2022-08-11 22:48:56 +00:00
|
|
|
const (
|
2022-12-20 08:38:58 +00:00
|
|
|
// DefaultPolicy is a default policy of placing containers in FrostFS if it's not set at the request.
|
2022-08-11 22:48:56 +00:00
|
|
|
DefaultPolicy = "REP 3"
|
|
|
|
// DefaultCopiesNumber is a default number of object copies that is enough to consider put successful if it's not set in config.
|
|
|
|
DefaultCopiesNumber uint32 = 0
|
|
|
|
)
|
2021-08-23 18:39:15 +00:00
|
|
|
|
2020-07-24 16:10:41 +00:00
|
|
|
var _ api.Handler = (*handler)(nil)
|
|
|
|
|
2021-05-13 20:25:31 +00:00
|
|
|
// New creates new api.Handler using given logger and client.
|
2022-04-29 13:08:22 +00:00
|
|
|
func New(log *zap.Logger, obj layer.Client, notificator Notificator, cfg *Config) (api.Handler, error) {
|
2020-07-24 16:10:41 +00:00
|
|
|
switch {
|
2020-08-06 10:49:25 +00:00
|
|
|
case obj == nil:
|
2022-12-20 08:38:58 +00:00
|
|
|
return nil, errors.New("empty FrostFS Object Layer")
|
2020-08-06 10:49:25 +00:00
|
|
|
case log == nil:
|
2020-07-24 16:10:41 +00:00
|
|
|
return nil, errors.New("empty logger")
|
|
|
|
}
|
|
|
|
|
2022-06-24 14:34:44 +00:00
|
|
|
if !cfg.NotificatorEnabled {
|
|
|
|
log.Warn("notificator is disabled, s3 won't produce notification events")
|
|
|
|
} else if notificator == nil {
|
2022-04-29 13:08:22 +00:00
|
|
|
return nil, errors.New("empty notificator")
|
|
|
|
}
|
|
|
|
|
2020-07-24 16:10:41 +00:00
|
|
|
return &handler{
|
2022-04-29 13:08:22 +00:00
|
|
|
log: log,
|
|
|
|
obj: obj,
|
|
|
|
cfg: cfg,
|
|
|
|
notificator: notificator,
|
2020-07-24 16:10:41 +00:00
|
|
|
}, nil
|
|
|
|
}
|