forked from TrueCloudLab/frostfs-http-gw
*: update to use unneofsed sdk-go
Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
b2cd6d8862
commit
e8b94553c3
5 changed files with 29 additions and 31 deletions
23
app.go
23
app.go
|
@ -2,14 +2,15 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"github.com/fasthttp/router"
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
"github.com/nspcc-dev/neofs-http-gw/downloader"
|
||||
"github.com/nspcc-dev/neofs-http-gw/uploader"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/pkg/logger"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/pkg/neofs"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/pkg/pool"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/valyala/fasthttp"
|
||||
|
@ -20,7 +21,7 @@ import (
|
|||
type (
|
||||
app struct {
|
||||
log *zap.Logger
|
||||
plant neofs.ClientPlant
|
||||
pool pool.Pool
|
||||
cfg *viper.Viper
|
||||
auxiliaryLog logger.Logger
|
||||
webServer *fasthttp.Server
|
||||
|
@ -59,7 +60,7 @@ func WithConfig(c *viper.Viper) Option {
|
|||
|
||||
func newApp(ctx context.Context, opt ...Option) App {
|
||||
var (
|
||||
creds neofs.Credentials
|
||||
key *ecdsa.PrivateKey
|
||||
err error
|
||||
)
|
||||
|
||||
|
@ -92,9 +93,9 @@ func newApp(ctx context.Context, opt ...Option) App {
|
|||
keystring := a.cfg.GetString(cmdNeoFSKey)
|
||||
if len(keystring) == 0 {
|
||||
a.log.Info("no key specified, creating one automatically for this run")
|
||||
creds, err = neofs.NewEphemeralCredentials()
|
||||
key, err = pool.NewEphemeralKey()
|
||||
} else {
|
||||
creds, err = neofs.NewCredentials(keystring)
|
||||
key, err = crypto.LoadPrivateKey(keystring)
|
||||
}
|
||||
if err != nil {
|
||||
a.log.Fatal("failed to get neofs credentials", zap.Error(err))
|
||||
|
@ -113,7 +114,7 @@ func newApp(ctx context.Context, opt ...Option) App {
|
|||
a.log.Info("add connection", zap.String("address", address), zap.Float64("weight", weight))
|
||||
}
|
||||
opts := &pool.BuilderOptions{
|
||||
Key: creds.PrivateKey(),
|
||||
Key: key,
|
||||
NodeConnectionTimeout: a.cfg.GetDuration(cfgConTimeout),
|
||||
NodeRequestTimeout: a.cfg.GetDuration(cfgReqTimeout),
|
||||
ClientRebalanceInterval: a.cfg.GetDuration(cfgRebalance),
|
||||
|
@ -122,14 +123,10 @@ func newApp(ctx context.Context, opt ...Option) App {
|
|||
KeepaliveTimeout: a.cfg.GetDuration(cfgKeepaliveTimeout),
|
||||
KeepalivePermitWoStream: a.cfg.GetBool(cfgKeepalivePermitWithoutStream),
|
||||
}
|
||||
pool, err := pb.Build(ctx, opts)
|
||||
a.pool, err = pb.Build(ctx, opts)
|
||||
if err != nil {
|
||||
a.log.Fatal("failed to create connection pool", zap.Error(err))
|
||||
}
|
||||
a.plant, err = neofs.NewClientPlant(ctx, pool, creds)
|
||||
if err != nil {
|
||||
a.log.Fatal("failed to create neofs client plant")
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
|
@ -145,8 +142,8 @@ func (a *app) Serve(ctx context.Context) {
|
|||
close(a.webDone)
|
||||
}()
|
||||
edts := a.cfg.GetBool(cfgUploaderHeaderEnableDefaultTimestamp)
|
||||
uploader := uploader.New(a.log, a.plant, edts)
|
||||
downloader, err := downloader.New(ctx, a.log, a.plant)
|
||||
uploader := uploader.New(a.log, a.pool, edts)
|
||||
downloader, err := downloader.New(ctx, a.log, a.pool)
|
||||
if err != nil {
|
||||
a.log.Fatal("failed to create downloader", zap.Error(err))
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
"github.com/nspcc-dev/neofs-http-gw/tokens"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/pkg/neofs"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/pkg/pool"
|
||||
"github.com/valyala/fasthttp"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc/codes"
|
||||
|
@ -165,13 +165,13 @@ func (o objectIDs) Slice() []string {
|
|||
// Downloader is a download request handler.
|
||||
type Downloader struct {
|
||||
log *zap.Logger
|
||||
plant neofs.ClientPlant
|
||||
pool pool.Pool
|
||||
}
|
||||
|
||||
// New creates an instance of Downloader using specified options.
|
||||
func New(ctx context.Context, log *zap.Logger, plant neofs.ClientPlant) (*Downloader, error) {
|
||||
func New(ctx context.Context, log *zap.Logger, conns pool.Pool) (*Downloader, error) {
|
||||
var err error
|
||||
d := &Downloader{log: log, plant: plant}
|
||||
d := &Downloader{log: log, pool: conns}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get neofs client's reusable artifacts: %w", err)
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ func (d *Downloader) DownloadByAddress(c *fasthttp.RequestCtx) {
|
|||
return
|
||||
}
|
||||
|
||||
conn, tkn, err = d.plant.ConnectionArtifacts()
|
||||
conn, tkn, err = d.pool.Connection()
|
||||
if err != nil {
|
||||
log.Error("failed to get neofs connection artifacts", zap.Error(err))
|
||||
c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError)
|
||||
|
@ -231,7 +231,7 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) {
|
|||
return
|
||||
}
|
||||
|
||||
conn, tkn, err = d.plant.ConnectionArtifacts()
|
||||
conn, tkn, err = d.pool.Connection()
|
||||
if err != nil {
|
||||
log.Error("failed to get neofs connection artifacts", zap.Error(err))
|
||||
c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError)
|
||||
|
@ -261,7 +261,7 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) {
|
|||
address.SetContainerID(cid)
|
||||
address.SetObjectID(ids[0])
|
||||
|
||||
conn, tkn, err = d.plant.ConnectionArtifacts()
|
||||
conn, tkn, err = d.pool.Connection()
|
||||
if err != nil {
|
||||
log.Error("failed to get neofs connection artifacts", zap.Error(err))
|
||||
c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError)
|
||||
|
|
3
go.mod
3
go.mod
|
@ -6,7 +6,8 @@ require (
|
|||
github.com/fasthttp/router v1.3.5
|
||||
github.com/mr-tron/base58 v1.1.3 // indirect
|
||||
github.com/nspcc-dev/neofs-api-go v1.26.1
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210527182636-cbfc17a1a9a2
|
||||
github.com/nspcc-dev/neofs-crypto v0.3.0
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210531182150-2f63343bda48
|
||||
github.com/prometheus/client_golang v1.9.0
|
||||
github.com/prometheus/common v0.15.0
|
||||
github.com/spf13/pflag v1.0.5
|
||||
|
|
4
go.sum
4
go.sum
|
@ -319,8 +319,8 @@ github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9K
|
|||
github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
||||
github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM=
|
||||
github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210527182636-cbfc17a1a9a2 h1:z8xtKILKi+Dolk3VAyCaFPMroFnT+x8qTqMT/zBRqIc=
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210527182636-cbfc17a1a9a2/go.mod h1:QZE7VaNQRyNFS+3gsrNEQEiLe+d6AR6EteX1M9geh6A=
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210531182150-2f63343bda48 h1:IcgVSj33HSH621/K0Jk9JTFJ/ooIs2d4hd+kww5d/O8=
|
||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210531182150-2f63343bda48/go.mod h1:QZE7VaNQRyNFS+3gsrNEQEiLe+d6AR6EteX1M9geh6A=
|
||||
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
||||
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
|
||||
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
"github.com/nspcc-dev/neofs-http-gw/tokens"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/pkg/neofs"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/pkg/pool"
|
||||
"github.com/valyala/fasthttp"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -26,14 +26,14 @@ const (
|
|||
// Uploader is an upload request handler.
|
||||
type Uploader struct {
|
||||
log *zap.Logger
|
||||
plant neofs.ClientPlant
|
||||
pool pool.Pool
|
||||
enableDefaultTimestamp bool
|
||||
}
|
||||
|
||||
// New creates a new Uploader using specified logger, connection pool and
|
||||
// other options.
|
||||
func New(log *zap.Logger, plant neofs.ClientPlant, enableDefaultTimestamp bool) *Uploader {
|
||||
return &Uploader{log, plant, enableDefaultTimestamp}
|
||||
func New(log *zap.Logger, conns pool.Pool, enableDefaultTimestamp bool) *Uploader {
|
||||
return &Uploader{log, conns, enableDefaultTimestamp}
|
||||
}
|
||||
|
||||
// Upload handles multipart upload request.
|
||||
|
@ -106,7 +106,7 @@ func (u *Uploader) Upload(c *fasthttp.RequestCtx) {
|
|||
oid, bt := u.fetchOwnerAndBearerToken(c)
|
||||
|
||||
// Try to put file into NeoFS or throw an error.
|
||||
conn, tkn, err = u.plant.ConnectionArtifacts()
|
||||
conn, tkn, err = u.pool.Connection()
|
||||
if err != nil {
|
||||
log.Error("failed to get neofs connection artifacts", zap.Error(err))
|
||||
c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError)
|
||||
|
@ -157,7 +157,7 @@ func (u *Uploader) fetchOwnerAndBearerToken(ctx context.Context) (*owner.ID, *to
|
|||
if tkn, err := tokens.LoadBearerToken(ctx); err == nil && tkn != nil {
|
||||
return tkn.Issuer(), tkn
|
||||
}
|
||||
return u.plant.OwnerID(), nil
|
||||
return u.pool.OwnerID(), nil
|
||||
}
|
||||
|
||||
type putResponse struct {
|
||||
|
|
Loading…
Reference in a new issue