forked from TrueCloudLab/frostfs-http-gw
[#18] Add fetching owner variously on file uploading
Signed-off-by: Pavel Korotkov <pavel@nspcc.ru>
This commit is contained in:
parent
237c247ec4
commit
f77c4e49dc
1 changed files with 11 additions and 1 deletions
12
upload.go
12
upload.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -9,6 +10,7 @@ import (
|
||||||
sdk "github.com/nspcc-dev/cdn-sdk"
|
sdk "github.com/nspcc-dev/cdn-sdk"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
"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/object"
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
@ -33,6 +35,14 @@ func (pr *putResponse) Encode(w io.Writer) error {
|
||||||
return enc.Encode(pr)
|
return enc.Encode(pr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *app) fetchOwner(ctx context.Context) *owner.ID {
|
||||||
|
if tkn, err := sdk.BearerToken(ctx); err == nil && tkn != nil {
|
||||||
|
return tkn.Issuer()
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.cli.Owner()
|
||||||
|
}
|
||||||
|
|
||||||
func (a *app) upload(c *fasthttp.RequestCtx) {
|
func (a *app) upload(c *fasthttp.RequestCtx) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
@ -109,7 +119,7 @@ func (a *app) upload(c *fasthttp.RequestCtx) {
|
||||||
// prepares new object and fill it
|
// prepares new object and fill it
|
||||||
raw := object.NewRaw()
|
raw := object.NewRaw()
|
||||||
raw.SetContainerID(cid)
|
raw.SetContainerID(cid)
|
||||||
raw.SetOwnerID(a.cli.Owner()) // should be various: from sdk / BearerToken
|
raw.SetOwnerID(a.fetchOwner(c))
|
||||||
raw.SetAttributes(attributes...)
|
raw.SetAttributes(attributes...)
|
||||||
|
|
||||||
// tries to put file into NeoFS or throw error
|
// tries to put file into NeoFS or throw error
|
||||||
|
|
Loading…
Reference in a new issue