forked from TrueCloudLab/frostfs-s3-gw
[#53] *: Remove external pkg/errors dependency
Replaced functions from pkg/errors by functions from errors, fixed not fully correct comment Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
b595f04ce0
commit
9d496d70a7
6 changed files with 26 additions and 23 deletions
|
@ -2,6 +2,7 @@ package auth
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -17,7 +18,6 @@ import (
|
|||
"github.com/nspcc-dev/cdn-sdk/creds/s3"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -85,14 +85,14 @@ func (c *center) Authenticate(r *http.Request) (*token.BearerToken, error) {
|
|||
|
||||
signatureDateTime, err := time.Parse("20060102T150405Z", r.Header.Get("X-Amz-Date"))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to parse x-amz-date header field")
|
||||
return nil, fmt.Errorf("failed to parse x-amz-date header field: %w", err)
|
||||
}
|
||||
|
||||
accessKeyID := fmt.Sprintf("%s/%s", sms1["access_key_id_cid"], sms1["access_key_id_oid"])
|
||||
|
||||
address := object.NewAddress()
|
||||
if err = address.Parse(accessKeyID); err != nil {
|
||||
return nil, errors.Wrapf(err, "could not parse AccessBox address: %s", accessKeyID)
|
||||
return nil, fmt.Errorf("could not parse AccessBox address: %s : %w", accessKeyID, err)
|
||||
}
|
||||
|
||||
tkn, err := c.cli.Get(r.Context(), address)
|
||||
|
@ -122,7 +122,7 @@ func (c *center) Authenticate(r *http.Request) (*token.BearerToken, error) {
|
|||
|
||||
// body not required
|
||||
if _, err := signer.Sign(otherRequest, nil, sms1["service"], sms1["region"], signatureDateTime); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to sign temporary HTTP request")
|
||||
return nil, fmt.Errorf("failed to sign temporary HTTP request: %w", err)
|
||||
}
|
||||
|
||||
sms2 := c.reg.getSubmatches(otherRequest.Header.Get("Authorization"))
|
||||
|
|
|
@ -2,6 +2,8 @@ package layer
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"time"
|
||||
|
@ -13,7 +15,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/api"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
@ -116,7 +117,7 @@ func (n *layer) Get(ctx context.Context, address *object.Address) (*object.Objec
|
|||
return n.cli.Object().Get(ctx, address)
|
||||
}
|
||||
|
||||
// GetBucketInfo returns bucket name.
|
||||
// GetBucketInfo returns bucket info by name.
|
||||
func (n *layer) GetBucketInfo(ctx context.Context, name string) (*BucketInfo, error) {
|
||||
name, err := url.QueryUnescape(name)
|
||||
if err != nil {
|
||||
|
@ -227,9 +228,9 @@ func (n *layer) GetObject(ctx context.Context, p *GetObjectParams) error {
|
|||
)
|
||||
|
||||
if bkt, err = n.GetBucketInfo(ctx, p.Bucket); err != nil {
|
||||
return errors.Wrapf(err, "bucket = %s", p.Bucket)
|
||||
return fmt.Errorf("couldn't find bucket: %s : %w", p.Bucket, err)
|
||||
} else if oid, err = n.objectFindID(ctx, &findParams{cid: bkt.CID, val: p.Object}); err != nil {
|
||||
return errors.Wrapf(err, "cid: %s, val: %s", bkt.CID, p.Object)
|
||||
return fmt.Errorf("search of the object failed: cid: %s, val: %s : %w", bkt.CID, p.Object, err)
|
||||
}
|
||||
|
||||
addr := object.NewAddress()
|
||||
|
@ -245,7 +246,11 @@ func (n *layer) GetObject(ctx context.Context, p *GetObjectParams) error {
|
|||
length: p.Length,
|
||||
})
|
||||
|
||||
return errors.Wrapf(err, "cid: %s", bkt.CID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get object, cid: %s : %w", bkt.CID, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *layer) checkObject(ctx context.Context, cid *container.ID, filename string) error {
|
||||
|
@ -300,7 +305,7 @@ func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*ObjectInfo,
|
|||
func (n *layer) CopyObject(ctx context.Context, p *CopyObjectParams) (*ObjectInfo, error) {
|
||||
info, err := n.GetObjectInfo(ctx, p.SrcBucket, p.SrcObject)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "get-object-info")
|
||||
return nil, fmt.Errorf("couldn't get object info: %w", err)
|
||||
}
|
||||
|
||||
pr, pw := io.Pipe()
|
||||
|
|
|
@ -2,6 +2,7 @@ package layer
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
@ -11,7 +12,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/api"
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"crypto/ecdsa"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"strconv"
|
||||
|
@ -21,7 +22,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/policy"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -78,7 +78,7 @@ func (a *Agent) checkContainer(ctx context.Context, cid *container.ID, friendlyN
|
|||
|
||||
pp, err := buildPlacementPolicy("")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to build placement policy")
|
||||
return nil, fmt.Errorf("failed to build placement policy: %w", err)
|
||||
}
|
||||
|
||||
cnr := container.New(
|
||||
|
@ -108,12 +108,12 @@ func (a *Agent) IssueSecret(ctx context.Context, w io.Writer, options *IssueSecr
|
|||
|
||||
table, err := buildEACLTable(cid, options.EACLRules)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to build eacl table")
|
||||
return fmt.Errorf("failed to build eacl table: %w", err)
|
||||
}
|
||||
|
||||
tkn, err := buildBearerToken(options.NEOFSCreds.PrivateKey(), options.NEOFSCreds.Owner(), table)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to build bearer token")
|
||||
return fmt.Errorf("failed to build bearer token: %w", err)
|
||||
}
|
||||
|
||||
a.log.Info("store bearer token into NeoFS",
|
||||
|
@ -124,12 +124,12 @@ func (a *Agent) IssueSecret(ctx context.Context, w io.Writer, options *IssueSecr
|
|||
New(a.cli.Object(), options.OwnerPrivateKey).
|
||||
Put(ctx, cid, tkn, options.GatesPublicKeys...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to put bearer token")
|
||||
return fmt.Errorf("failed to put bearer token: %w", err)
|
||||
}
|
||||
|
||||
secret, err := s3.SecretAccessKey(tkn)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get bearer token secret key")
|
||||
return fmt.Errorf("failed to get bearer token secret key: %w", err)
|
||||
}
|
||||
|
||||
ir := &issuingResult{
|
||||
|
@ -149,17 +149,17 @@ func (a *Agent) ObtainSecret(ctx context.Context, w io.Writer, options *ObtainSe
|
|||
bearerCreds := bearer.New(a.cli.Object(), options.GatePrivateKey)
|
||||
address := object.NewAddress()
|
||||
if err := address.Parse(options.SecretAddress); err != nil {
|
||||
return errors.Wrap(err, "failed to parse secret address")
|
||||
return fmt.Errorf("failed to parse secret address: %w", err)
|
||||
}
|
||||
|
||||
tkn, err := bearerCreds.Get(ctx, address)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get bearer token")
|
||||
return fmt.Errorf("failed to get bearer token: %w", err)
|
||||
}
|
||||
|
||||
secret, err := s3.SecretAccessKey(tkn)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to get bearer token secret key")
|
||||
return fmt.Errorf("failed to get bearer token secret key: %w", err)
|
||||
}
|
||||
|
||||
or := &obtainingResult{
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
"github.com/nspcc-dev/cdn-sdk/pool"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/authmate"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
@ -379,7 +378,7 @@ func createSDKClient(ctx context.Context, log *zap.Logger, neofsCreds neofs.Cred
|
|||
pool.WithConnectTimeout(poolConnectTimeout),
|
||||
pool.WithRequestTimeout(poolRequestTimeout))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create connection pool")
|
||||
return nil, fmt.Errorf("failed to create connection pool: %w", err)
|
||||
}
|
||||
|
||||
log.Debug("prepare sdk client")
|
||||
|
|
1
go.mod
1
go.mod
|
@ -9,7 +9,6 @@ require (
|
|||
github.com/nspcc-dev/cdn-sdk v0.3.4
|
||||
github.com/nspcc-dev/neofs-api-go v1.23.0
|
||||
github.com/nspcc-dev/neofs-node v1.22.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/client_golang v1.9.0
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/spf13/viper v1.7.1
|
||||
|
|
Loading…
Reference in a new issue