frostfs-s3-gw/api/handler/api.go

71 lines
1.7 KiB
Go
Raw Normal View History

2020-07-24 16:10:41 +00:00
package handler
import (
2020-08-06 10:49:25 +00:00
"errors"
2020-07-24 16:10:41 +00:00
"github.com/nspcc-dev/neofs-s3-gw/api"
"github.com/nspcc-dev/neofs-s3-gw/api/layer"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
2020-07-24 16:10:41 +00:00
"go.uber.org/zap"
)
type (
handler struct {
log *zap.Logger
obj layer.Client
notificator Notificator
cfg *Config
}
Notificator interface {
SendNotifications(topics map[string]string, p *SendNotificationParams) error
SendTestNotification(topic, bucketName, requestID, HostID string) error
}
// Config contains data which handler needs to keep.
Config struct {
Policy PlacementPolicy
DefaultMaxAge int
NotificatorEnabled bool
TLSEnabled bool
CopiesNumber uint32
2020-07-24 16:10:41 +00:00
}
PlacementPolicy struct {
Default netmap.PlacementPolicy
RegionMap map[string]netmap.PlacementPolicy
}
2020-07-24 16:10:41 +00:00
)
const (
// DefaultPolicy is a default policy of placing containers in NeoFS if it's not set at the request.
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
)
2020-07-24 16:10:41 +00:00
var _ api.Handler = (*handler)(nil)
// New creates new api.Handler using given logger and client.
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:
return nil, errors.New("empty NeoFS Object Layer")
case log == nil:
2020-07-24 16:10:41 +00:00
return nil, errors.New("empty logger")
}
if !cfg.NotificatorEnabled {
log.Warn("notificator is disabled, s3 won't produce notification events")
} else if notificator == nil {
return nil, errors.New("empty notificator")
}
2020-07-24 16:10:41 +00:00
return &handler{
log: log,
obj: obj,
cfg: cfg,
notificator: notificator,
2020-07-24 16:10:41 +00:00
}, nil
}