diff --git a/upload.go b/upload.go index 3124e26..1360ec5 100644 --- a/upload.go +++ b/upload.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "io" "strconv" @@ -9,6 +10,7 @@ import ( sdk "github.com/nspcc-dev/cdn-sdk" "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/valyala/fasthttp" "go.uber.org/zap" ) @@ -33,6 +35,14 @@ func (pr *putResponse) Encode(w io.Writer) error { 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) { var ( err error @@ -109,7 +119,7 @@ func (a *app) upload(c *fasthttp.RequestCtx) { // prepares new object and fill it raw := object.NewRaw() raw.SetContainerID(cid) - raw.SetOwnerID(a.cli.Owner()) // should be various: from sdk / BearerToken + raw.SetOwnerID(a.fetchOwner(c)) raw.SetAttributes(attributes...) // tries to put file into NeoFS or throw error