forked from TrueCloudLab/frostfs-s3-gw
Merge pull request #84 from KirillovDenis/bugfix/82-pass_bearer_to_request
[#82] Using bearer token
This commit is contained in:
commit
473536372a
3 changed files with 26 additions and 14 deletions
|
@ -33,9 +33,10 @@ type (
|
|||
|
||||
func (n *layer) containerInfo(ctx context.Context, cid *cid.ID) (*BucketInfo, error) {
|
||||
var (
|
||||
err error
|
||||
res *container.Container
|
||||
rid = api.GetRequestID(ctx)
|
||||
err error
|
||||
res *container.Container
|
||||
rid = api.GetRequestID(ctx)
|
||||
bearerOpt = n.BearerOpt(ctx)
|
||||
|
||||
info = &BucketInfo{
|
||||
CID: cid,
|
||||
|
@ -50,7 +51,7 @@ func (n *layer) containerInfo(ctx context.Context, cid *cid.ID) (*BucketInfo, er
|
|||
zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
res, err = conn.GetContainer(ctx, cid)
|
||||
res, err = conn.GetContainer(ctx, cid, bearerOpt)
|
||||
if err != nil {
|
||||
n.log.Error("could not fetch container",
|
||||
zap.Stringer("cid", cid),
|
||||
|
@ -87,10 +88,11 @@ func (n *layer) containerInfo(ctx context.Context, cid *cid.ID) (*BucketInfo, er
|
|||
|
||||
func (n *layer) containerList(ctx context.Context) ([]*BucketInfo, error) {
|
||||
var (
|
||||
err error
|
||||
own = n.Owner(ctx)
|
||||
res []*cid.ID
|
||||
rid = api.GetRequestID(ctx)
|
||||
err error
|
||||
own = n.Owner(ctx)
|
||||
bearerOpt = n.BearerOpt(ctx)
|
||||
res []*cid.ID
|
||||
rid = api.GetRequestID(ctx)
|
||||
)
|
||||
|
||||
conn, _, err := n.pool.Connection()
|
||||
|
@ -100,7 +102,7 @@ func (n *layer) containerList(ctx context.Context) ([]*BucketInfo, error) {
|
|||
zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
res, err = conn.ListContainers(ctx, own)
|
||||
res, err = conn.ListContainers(ctx, own, bearerOpt)
|
||||
if err != nil {
|
||||
n.log.Error("could not fetch container",
|
||||
zap.String("request_id", rid),
|
||||
|
|
|
@ -113,10 +113,19 @@ func (n *layer) Owner(ctx context.Context) *owner.ID {
|
|||
return n.pool.OwnerID()
|
||||
}
|
||||
|
||||
// BearerOpt returns client.WithBearer call option with token from context or with nil token.
|
||||
func (n *layer) BearerOpt(ctx context.Context) client.CallOption {
|
||||
if tkn, ok := ctx.Value(api.BearerTokenKey).(*token.BearerToken); ok && tkn != nil {
|
||||
return client.WithBearer(tkn)
|
||||
}
|
||||
|
||||
return client.WithBearer(nil)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
ops := new(client.GetObjectParams).WithAddress(address)
|
||||
return n.pool.GetObject(ctx, ops)
|
||||
return n.pool.GetObject(ctx, ops, n.BearerOpt(ctx))
|
||||
}
|
||||
|
||||
// GetBucketInfo returns bucket info by name.
|
||||
|
|
|
@ -42,7 +42,7 @@ func (n *layer) objectSearch(ctx context.Context, p *findParams) ([]*object.ID,
|
|||
} else if filename != "" {
|
||||
opts.AddFilter(object.AttributeFileName, filename, object.MatchStringEqual)
|
||||
}
|
||||
return n.pool.SearchObject(ctx, new(client.SearchObjectParams).WithContainerID(p.cid).WithSearchFilters(opts))
|
||||
return n.pool.SearchObject(ctx, new(client.SearchObjectParams).WithContainerID(p.cid).WithSearchFilters(opts), n.BearerOpt(ctx))
|
||||
}
|
||||
|
||||
// objectFindID returns object id (uuid) based on it's nice name in s3. If
|
||||
|
@ -62,7 +62,7 @@ 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) {
|
||||
ops := new(client.ObjectHeaderParams).WithAddress(address).WithAllFields()
|
||||
return n.pool.GetObjectHeader(ctx, ops)
|
||||
return n.pool.GetObjectHeader(ctx, ops, n.BearerOpt(ctx))
|
||||
}
|
||||
|
||||
// objectGet and write it into provided io.Reader.
|
||||
|
@ -70,7 +70,7 @@ func (n *layer) objectGet(ctx context.Context, p *getParams) (*object.Object, er
|
|||
// prepare length/offset writer
|
||||
w := newWriter(p.Writer, p.offset, p.length)
|
||||
ops := new(client.GetObjectParams).WithAddress(p.address).WithPayloadWriter(w)
|
||||
return n.pool.GetObject(ctx, ops)
|
||||
return n.pool.GetObject(ctx, ops, n.BearerOpt(ctx))
|
||||
}
|
||||
|
||||
// objectPut into NeoFS, took payload from io.Reader.
|
||||
|
@ -128,6 +128,7 @@ func (n *layer) objectPut(ctx context.Context, p *PutObjectParams) (*ObjectInfo,
|
|||
oid, err := n.pool.PutObject(
|
||||
ctx,
|
||||
ops,
|
||||
n.BearerOpt(ctx),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -150,5 +151,5 @@ func (n *layer) objectPut(ctx context.Context, p *PutObjectParams) (*ObjectInfo,
|
|||
func (n *layer) objectDelete(ctx context.Context, address *object.Address) error {
|
||||
dop := new(client.DeleteObjectParams)
|
||||
dop.WithAddress(address)
|
||||
return n.pool.DeleteObject(ctx, dop)
|
||||
return n.pool.DeleteObject(ctx, dop, n.BearerOpt(ctx))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue