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
|
|
|
|
2021-05-18 11:10:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api"
|
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api/layer"
|
2021-11-15 12:56:16 +00:00
|
|
|
"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
|
2020-08-06 10:49:25 +00:00
|
|
|
obj layer.Client
|
2021-08-23 18:39:15 +00:00
|
|
|
cfg *Config
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
DefaultPolicy *netmap.PlacementPolicy
|
2021-10-04 14:32:35 +00:00
|
|
|
DefaultMaxAge int
|
2020-07-24 16:10:41 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-04-13 16:56:58 +00:00
|
|
|
// DefaultPolicy is a default policy of placing containers in NeoFS if it's not set at the request.
|
2021-08-23 18:39:15 +00:00
|
|
|
const DefaultPolicy = "REP 3"
|
|
|
|
|
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.
|
2021-08-23 18:39:15 +00:00
|
|
|
func New(log *zap.Logger, obj layer.Client, 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")
|
|
|
|
}
|
|
|
|
|
|
|
|
return &handler{
|
2020-08-06 10:49:25 +00:00
|
|
|
log: log,
|
|
|
|
obj: obj,
|
2021-08-23 18:39:15 +00:00
|
|
|
cfg: cfg,
|
2020-07-24 16:10:41 +00:00
|
|
|
}, nil
|
|
|
|
}
|