forked from TrueCloudLab/frostfs-http-gw
*: drop github.com/pkg/errors dependency
Use standard error wrapping/unwrapping instead. The conversion is mostly straightforward, but see grpc/grpc-go#2934 for GRPC `status.FromError`, it doesn't currently support unwrapping/errors.As(), so we're unwrapping manually here.
This commit is contained in:
parent
ba293a3ff9
commit
afbb9d51f1
4 changed files with 17 additions and 11 deletions
|
@ -3,13 +3,14 @@ package connections
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -91,7 +92,7 @@ func new(ctx context.Context, options *PoolBuilderOptions) (Pool, error) {
|
||||||
if epi, err := c.EndpointInfo(ctx); err == nil {
|
if epi, err := c.EndpointInfo(ctx); err == nil {
|
||||||
address = epi.NodeInfo().Address()
|
address = epi.NodeInfo().Address()
|
||||||
}
|
}
|
||||||
return nil, errors.Wrapf(err, "failed to create neofs session token for client %s", address)
|
return nil, fmt.Errorf("failed to create neofs session token for client %s: %w", address, err)
|
||||||
}
|
}
|
||||||
clientPacks[i] = &clientPack{client: c, sessionToken: st, healthy: true}
|
clientPacks[i] = &clientPack{client: c, sessionToken: st, healthy: true}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package downloader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
|
@ -14,7 +16,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||||
"github.com/nspcc-dev/neofs-http-gate/neofs"
|
"github.com/nspcc-dev/neofs-http-gate/neofs"
|
||||||
"github.com/nspcc-dev/neofs-http-gate/tokens"
|
"github.com/nspcc-dev/neofs-http-gate/tokens"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
@ -84,10 +85,14 @@ func (r *request) receiveFile(options *neofs.GetOptions) {
|
||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
)
|
)
|
||||||
var (
|
var (
|
||||||
msg = errors.Wrap(err, "could not receive object").Error()
|
msg = fmt.Sprintf("could not receive object: %v", err)
|
||||||
code = fasthttp.StatusBadRequest
|
code = fasthttp.StatusBadRequest
|
||||||
|
cause = err
|
||||||
)
|
)
|
||||||
if st, ok := status.FromError(errors.Cause(err)); ok && st != nil {
|
for unwrap := errors.Unwrap(err); unwrap != nil; unwrap = errors.Unwrap(cause) {
|
||||||
|
cause = unwrap
|
||||||
|
}
|
||||||
|
if st, ok := status.FromError(cause); ok && st != nil {
|
||||||
if st.Code() == codes.NotFound {
|
if st.Code() == codes.NotFound {
|
||||||
code = fasthttp.StatusNotFound
|
code = fasthttp.StatusNotFound
|
||||||
}
|
}
|
||||||
|
@ -144,7 +149,7 @@ func New(ctx context.Context, log *zap.Logger, plant neofs.ClientPlant) (*Downlo
|
||||||
var err error
|
var err error
|
||||||
d := &Downloader{log: log, plant: plant}
|
d := &Downloader{log: log, plant: plant}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to get neofs client's reusable artifacts")
|
return nil, fmt.Errorf("failed to get neofs client's reusable artifacts: %w", err)
|
||||||
}
|
}
|
||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -8,7 +8,6 @@ require (
|
||||||
github.com/nspcc-dev/neo-go v0.94.0 // indirect
|
github.com/nspcc-dev/neo-go v0.94.0 // indirect
|
||||||
github.com/nspcc-dev/neofs-api-go v1.25.0
|
github.com/nspcc-dev/neofs-api-go v1.25.0
|
||||||
github.com/nspcc-dev/neofs-crypto v0.3.0
|
github.com/nspcc-dev/neofs-crypto v0.3.0
|
||||||
github.com/pkg/errors v0.9.1
|
|
||||||
github.com/prometheus/client_golang v1.9.0
|
github.com/prometheus/client_golang v1.9.0
|
||||||
github.com/prometheus/common v0.15.0
|
github.com/prometheus/common v0.15.0
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
|
|
|
@ -4,9 +4,10 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -77,10 +78,10 @@ func fetchBearerToken(ctx *fasthttp.RequestCtx) (*token.BearerToken, error) {
|
||||||
if buf = parse(&ctx.Request.Header); buf == nil {
|
if buf = parse(&ctx.Request.Header); buf == nil {
|
||||||
continue
|
continue
|
||||||
} else if data, err := base64.StdEncoding.DecodeString(string(buf)); err != nil {
|
} else if data, err := base64.StdEncoding.DecodeString(string(buf)); err != nil {
|
||||||
lastErr = errors.Wrap(err, "could not fetch marshaled from base64")
|
lastErr = fmt.Errorf("can't base64-decode bearer token: %w", err)
|
||||||
continue
|
continue
|
||||||
} else if err = tkn.Unmarshal(data); err != nil {
|
} else if err = tkn.Unmarshal(data); err != nil {
|
||||||
lastErr = errors.Wrap(err, "could not unmarshal bearer token")
|
lastErr = fmt.Errorf("can't unmarshal bearer token: %w", err)
|
||||||
continue
|
continue
|
||||||
} else if tkn == nil {
|
} else if tkn == nil {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue