forked from TrueCloudLab/frostfs-s3-gw
2299db4e81
Now default policy of placing containers can be set via config/env variable. Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
44 lines
906 B
Go
44 lines
906 B
Go
package handler
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
|
"github.com/nspcc-dev/neofs-s3-gw/api"
|
|
"github.com/nspcc-dev/neofs-s3-gw/api/layer"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type (
|
|
handler struct {
|
|
log *zap.Logger
|
|
obj layer.Client
|
|
cfg *Config
|
|
}
|
|
|
|
// Config contains data which handler need to keep.
|
|
Config struct {
|
|
DefaultPolicy *netmap.PlacementPolicy
|
|
}
|
|
)
|
|
|
|
// DefaultPolicy is a default policy of placing container in NeoFS if it's not set at the request.
|
|
const DefaultPolicy = "REP 3"
|
|
|
|
var _ api.Handler = (*handler)(nil)
|
|
|
|
// New creates new api.Handler using given logger and client.
|
|
func New(log *zap.Logger, obj layer.Client, cfg *Config) (api.Handler, error) {
|
|
switch {
|
|
case obj == nil:
|
|
return nil, errors.New("empty NeoFS Object Layer")
|
|
case log == nil:
|
|
return nil, errors.New("empty logger")
|
|
}
|
|
|
|
return &handler{
|
|
log: log,
|
|
obj: obj,
|
|
cfg: cfg,
|
|
}, nil
|
|
}
|