forked from TrueCloudLab/frostfs-s3-gw
*: drop old sdk dependecies, bump neofs-api-go version
I'm not sure it works, but it's enough code-wise for now. We're reusing some http-gw components here that are to be moved into sdk-go in future. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
dbe65ae602
commit
d19ce03072
15 changed files with 263 additions and 163 deletions
|
@ -12,12 +12,12 @@ import (
|
|||
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
v4 "github.com/aws/aws-sdk-go/aws/signer/v4"
|
||||
sdk "github.com/nspcc-dev/cdn-sdk"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/creds/bearer"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/creds/hcs"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||
sdk "github.com/nspcc-dev/neofs-http-gw/neofs"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/authmate"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/creds/bearer"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/creds/hcs"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -36,7 +36,7 @@ type (
|
|||
|
||||
// Params stores node connection parameters.
|
||||
Params struct {
|
||||
Client sdk.Client
|
||||
Client sdk.ClientPlant
|
||||
Logger *zap.Logger
|
||||
Credential hcs.Credentials
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func (p prs) Seek(_ int64, _ int) (int64, error) {
|
|||
var _ io.ReadSeeker = prs(0)
|
||||
|
||||
// New creates an instance of AuthCenter.
|
||||
func New(obj sdk.ObjectClient, key hcs.PrivateKey) Center {
|
||||
func New(obj sdk.ClientPlant, key hcs.PrivateKey) Center {
|
||||
return ¢er{
|
||||
cli: bearer.New(obj, key),
|
||||
reg: ®expSubmatcher{re: authorizationFieldRegexp},
|
||||
|
|
|
@ -42,7 +42,15 @@ func (n *layer) containerInfo(ctx context.Context, cid *container.ID) (*BucketIn
|
|||
}
|
||||
)
|
||||
|
||||
if res, err = n.cli.Container().Get(ctx, cid); err != nil {
|
||||
conn, _, err := n.cli.ConnectionArtifacts()
|
||||
if err != nil {
|
||||
n.log.Error("failed to get connection from the pool",
|
||||
zap.String("request_id", rid),
|
||||
zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
res, err = conn.GetContainer(ctx, cid)
|
||||
if err != nil {
|
||||
n.log.Error("could not fetch container",
|
||||
zap.Stringer("cid", cid),
|
||||
zap.String("request_id", rid),
|
||||
|
@ -84,7 +92,15 @@ func (n *layer) containerList(ctx context.Context) ([]*BucketInfo, error) {
|
|||
rid = api.GetRequestID(ctx)
|
||||
)
|
||||
|
||||
if res, err = n.cli.Container().List(ctx, own); err != nil {
|
||||
conn, _, err := n.cli.ConnectionArtifacts()
|
||||
if err != nil {
|
||||
n.log.Error("failed to get connection from the pool",
|
||||
zap.String("request_id", rid),
|
||||
zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
res, err = conn.ListContainers(ctx, own)
|
||||
if err != nil {
|
||||
n.log.Error("could not fetch container",
|
||||
zap.String("request_id", rid),
|
||||
zap.Error(err))
|
||||
|
|
|
@ -8,13 +8,15 @@ import (
|
|||
"net/url"
|
||||
"time"
|
||||
|
||||
sdk "github.com/nspcc-dev/cdn-sdk"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/creds/neofs"
|
||||
"github.com/nspcc-dev/cdn-sdk/pool"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||
"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/connections"
|
||||
sdk "github.com/nspcc-dev/neofs-http-gw/neofs"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/api"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/creds/neofs"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
@ -22,13 +24,13 @@ import (
|
|||
|
||||
type (
|
||||
layer struct {
|
||||
cli sdk.Client
|
||||
cli sdk.ClientPlant
|
||||
log *zap.Logger
|
||||
}
|
||||
|
||||
// Params stores basic API parameters.
|
||||
Params struct {
|
||||
Pool pool.Client
|
||||
Pool connections.Pool
|
||||
Logger *zap.Logger
|
||||
Timeout time.Duration
|
||||
Credential neofs.Credentials
|
||||
|
@ -96,7 +98,7 @@ var (
|
|||
|
||||
// NewLayer creates instance of layer. It checks credentials
|
||||
// and establishes gRPC connection with node.
|
||||
func NewLayer(log *zap.Logger, cli sdk.Client) Client {
|
||||
func NewLayer(log *zap.Logger, cli sdk.ClientPlant) Client {
|
||||
return &layer{
|
||||
cli: cli,
|
||||
log: log,
|
||||
|
@ -105,16 +107,21 @@ func NewLayer(log *zap.Logger, cli sdk.Client) Client {
|
|||
|
||||
// Owner returns owner id from BearerToken (context) or from client owner.
|
||||
func (n *layer) Owner(ctx context.Context) *owner.ID {
|
||||
if tkn, err := sdk.BearerToken(ctx); err != nil && tkn != nil {
|
||||
if tkn, ok := ctx.Value(api.BearerTokenKey).(*token.BearerToken); ok && tkn != nil {
|
||||
return tkn.Issuer()
|
||||
}
|
||||
|
||||
return n.cli.Owner()
|
||||
return n.cli.OwnerID()
|
||||
}
|
||||
|
||||
// Get NeoFS Object by refs.Address (should be used by auth.Center).
|
||||
func (n *layer) Get(ctx context.Context, address *object.Address) (*object.Object, error) {
|
||||
return n.cli.Object().Get(ctx, address)
|
||||
conn, tok, err := n.cli.ConnectionArtifacts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ops := new(client.GetObjectParams).WithAddress(address)
|
||||
return conn.GetObject(ctx, ops, client.WithSession(tok))
|
||||
}
|
||||
|
||||
// GetBucketInfo returns bucket info by name.
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
sdk "github.com/nspcc-dev/cdn-sdk"
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||
"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"
|
||||
|
@ -33,16 +33,20 @@ type (
|
|||
|
||||
// objectSearch returns all available objects by search params.
|
||||
func (n *layer) objectSearch(ctx context.Context, p *findParams) ([]*object.ID, error) {
|
||||
opts := []sdk.ObjectSearchOption{
|
||||
sdk.SearchRootObjects(),
|
||||
}
|
||||
var opts object.SearchFilters
|
||||
|
||||
opts.AddRootFilter()
|
||||
|
||||
if filename, err := url.QueryUnescape(p.val); err != nil {
|
||||
return nil, err
|
||||
} else if filename != "" {
|
||||
opts = append(opts, sdk.SearchByFilename(filename))
|
||||
opts.AddFilter(object.AttributeFileName, filename, object.MatchStringEqual)
|
||||
}
|
||||
return n.cli.Object().Search(ctx, p.cid, opts...)
|
||||
conn, _, err := n.cli.ConnectionArtifacts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return conn.SearchObject(ctx, new(client.SearchObjectParams).WithContainerID(p.cid).WithSearchFilters(opts))
|
||||
}
|
||||
|
||||
// objectFindID returns object id (uuid) based on it's nice name in s3. If
|
||||
|
@ -61,14 +65,24 @@ func (n *layer) objectFindID(ctx context.Context, p *findParams) (*object.ID, er
|
|||
|
||||
// objectHead returns all object's headers.
|
||||
func (n *layer) objectHead(ctx context.Context, address *object.Address) (*object.Object, error) {
|
||||
return n.cli.Object().Head(ctx, address, sdk.WithFullHeaders())
|
||||
conn, _, err := n.cli.ConnectionArtifacts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ops := new(client.ObjectHeaderParams).WithAddress(address).WithAllFields()
|
||||
return conn.GetObjectHeader(ctx, ops)
|
||||
}
|
||||
|
||||
// objectGet and write it into provided io.Reader.
|
||||
func (n *layer) objectGet(ctx context.Context, p *getParams) (*object.Object, error) {
|
||||
conn, tok, err := n.cli.ConnectionArtifacts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// prepare length/offset writer
|
||||
w := newWriter(p.Writer, p.offset, p.length)
|
||||
return n.cli.Object().Get(ctx, p.address, sdk.WithGetWriter(w))
|
||||
ops := new(client.GetObjectParams).WithAddress(p.address).WithPayloadWriter(w)
|
||||
return conn.GetObject(ctx, ops, client.WithSession(tok))
|
||||
}
|
||||
|
||||
// objectPut into NeoFS, took payload from io.Reader.
|
||||
|
@ -78,8 +92,6 @@ func (n *layer) objectPut(ctx context.Context, p *PutObjectParams) (*ObjectInfo,
|
|||
obj string
|
||||
bkt *BucketInfo
|
||||
own = n.Owner(ctx)
|
||||
|
||||
address *object.Address
|
||||
)
|
||||
|
||||
if obj, err = url.QueryUnescape(p.Object); err != nil {
|
||||
|
@ -123,12 +135,23 @@ func (n *layer) objectPut(ctx context.Context, p *PutObjectParams) (*ObjectInfo,
|
|||
raw.SetAttributes(attributes...)
|
||||
|
||||
r := newDetector(p.Reader)
|
||||
if address, err = n.cli.Object().Put(ctx, raw.Object(), sdk.WithPutReader(r)); err != nil {
|
||||
conn, tok, err := n.cli.ConnectionArtifacts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ops := new(client.PutObjectParams).WithObject(raw.Object()).WithPayloadReader(r)
|
||||
oid, err := conn.PutObject(
|
||||
ctx,
|
||||
ops,
|
||||
client.WithSession(tok),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ObjectInfo{
|
||||
id: address.ObjectID(),
|
||||
id: oid,
|
||||
|
||||
Owner: own,
|
||||
Bucket: p.Bucket,
|
||||
|
@ -142,5 +165,11 @@ func (n *layer) objectPut(ctx context.Context, p *PutObjectParams) (*ObjectInfo,
|
|||
|
||||
// objectDelete puts tombstone object into neofs.
|
||||
func (n *layer) objectDelete(ctx context.Context, address *object.Address) error {
|
||||
return n.cli.Object().Delete(ctx, address)
|
||||
conn, _, err := n.cli.ConnectionArtifacts()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dop := new(client.DeleteObjectParams)
|
||||
dop.WithAddress(address)
|
||||
return conn.DeleteObject(ctx, dop)
|
||||
}
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
sdk "github.com/nspcc-dev/cdn-sdk"
|
||||
"github.com/nspcc-dev/neofs-s3-gw/api/auth"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const BearerTokenKey = "__context_bearer_token_key"
|
||||
|
||||
// AttachUserAuth adds user authentication via center to router using log for logging.
|
||||
func AttachUserAuth(router *mux.Router, center auth.Center, log *zap.Logger) {
|
||||
router.Use(func(h http.Handler) http.Handler {
|
||||
|
@ -21,7 +23,7 @@ func AttachUserAuth(router *mux.Router, center auth.Center, log *zap.Logger) {
|
|||
}
|
||||
|
||||
h.ServeHTTP(w, r.WithContext(
|
||||
sdk.SetBearerToken(r.Context(), token)))
|
||||
context.WithValue(r.Context(), BearerTokenKey, token)))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue