forked from TrueCloudLab/frostfs-http-gw
Merge pull request #64 from KirillovDenis/feaute/63-using_object_interface
[#63] Using client.Object from sdk
This commit is contained in:
commit
fe899f7304
4 changed files with 8 additions and 44 deletions
|
@ -15,7 +15,6 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||||
"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/session"
|
|
||||||
"github.com/nspcc-dev/neofs-http-gw/tokens"
|
"github.com/nspcc-dev/neofs-http-gw/tokens"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/pkg/pool"
|
"github.com/nspcc-dev/neofs-sdk-go/pkg/pool"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
|
@ -72,9 +71,7 @@ func isValidValue(s string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *request) receiveFile(clnt client.Object,
|
func (r *request) receiveFile(clnt client.Object, objectAddress *object.Address) {
|
||||||
sessionToken *session.Token,
|
|
||||||
objectAddress *object.Address) {
|
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
dis = "inline"
|
dis = "inline"
|
||||||
|
@ -95,7 +92,6 @@ func (r *request) receiveFile(clnt client.Object,
|
||||||
obj, err = clnt.GetObject(
|
obj, err = clnt.GetObject(
|
||||||
r.RequestCtx,
|
r.RequestCtx,
|
||||||
options,
|
options,
|
||||||
client.WithSession(sessionToken),
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.log.Error(
|
r.log.Error(
|
||||||
|
@ -194,8 +190,6 @@ func (d *Downloader) DownloadByAddress(c *fasthttp.RequestCtx) {
|
||||||
oid, _ = c.UserValue("oid").(string)
|
oid, _ = c.UserValue("oid").(string)
|
||||||
val = strings.Join([]string{cid, oid}, "/")
|
val = strings.Join([]string{cid, oid}, "/")
|
||||||
log = d.log.With(zap.String("cid", cid), zap.String("oid", oid))
|
log = d.log.With(zap.String("cid", cid), zap.String("oid", oid))
|
||||||
conn client.Object
|
|
||||||
tkn *session.Token
|
|
||||||
)
|
)
|
||||||
if err = address.Parse(val); err != nil {
|
if err = address.Parse(val); err != nil {
|
||||||
log.Error("wrong object address", zap.Error(err))
|
log.Error("wrong object address", zap.Error(err))
|
||||||
|
@ -203,13 +197,7 @@ func (d *Downloader) DownloadByAddress(c *fasthttp.RequestCtx) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, tkn, err = d.pool.Connection()
|
d.newRequest(c, log).receiveFile(d.pool, address)
|
||||||
if err != nil {
|
|
||||||
log.Error("failed to get neofs connection artifacts", zap.Error(err))
|
|
||||||
c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.newRequest(c, log).receiveFile(conn, tkn, address)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadByAttribute handles attribute-based download requests.
|
// DownloadByAttribute handles attribute-based download requests.
|
||||||
|
@ -221,8 +209,6 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) {
|
||||||
val, _ = c.UserValue("attr_val").(string)
|
val, _ = c.UserValue("attr_val").(string)
|
||||||
log = d.log.With(zap.String("cid", scid), zap.String("attr_key", key), zap.String("attr_val", val))
|
log = d.log.With(zap.String("cid", scid), zap.String("attr_key", key), zap.String("attr_val", val))
|
||||||
ids []*object.ID
|
ids []*object.ID
|
||||||
conn client.Object
|
|
||||||
tkn *session.Token
|
|
||||||
)
|
)
|
||||||
cid := cid.New()
|
cid := cid.New()
|
||||||
if err = cid.Parse(scid); err != nil {
|
if err = cid.Parse(scid); err != nil {
|
||||||
|
@ -231,19 +217,12 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, tkn, err = d.pool.Connection()
|
|
||||||
if err != nil {
|
|
||||||
log.Error("failed to get neofs connection artifacts", zap.Error(err))
|
|
||||||
c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
options := object.NewSearchFilters()
|
options := object.NewSearchFilters()
|
||||||
options.AddRootFilter()
|
options.AddRootFilter()
|
||||||
options.AddFilter(key, val, object.MatchStringEqual)
|
options.AddFilter(key, val, object.MatchStringEqual)
|
||||||
|
|
||||||
sops := new(client.SearchObjectParams).WithContainerID(cid).WithSearchFilters(options)
|
sops := new(client.SearchObjectParams).WithContainerID(cid).WithSearchFilters(options)
|
||||||
if ids, err = conn.SearchObject(c, sops, client.WithSession(tkn)); err != nil {
|
if ids, err = d.pool.SearchObject(c, sops); err != nil {
|
||||||
log.Error("something went wrong", zap.Error(err))
|
log.Error("something went wrong", zap.Error(err))
|
||||||
c.Error("something went wrong", fasthttp.StatusBadRequest)
|
c.Error("something went wrong", fasthttp.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
@ -261,11 +240,5 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) {
|
||||||
address.SetContainerID(cid)
|
address.SetContainerID(cid)
|
||||||
address.SetObjectID(ids[0])
|
address.SetObjectID(ids[0])
|
||||||
|
|
||||||
conn, tkn, err = d.pool.Connection()
|
d.newRequest(c, log).receiveFile(d.pool, address)
|
||||||
if err != nil {
|
|
||||||
log.Error("failed to get neofs connection artifacts", zap.Error(err))
|
|
||||||
c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.newRequest(c, log).receiveFile(conn, tkn, address)
|
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -7,7 +7,7 @@ require (
|
||||||
github.com/mr-tron/base58 v1.1.3 // indirect
|
github.com/mr-tron/base58 v1.1.3 // indirect
|
||||||
github.com/nspcc-dev/neofs-api-go v1.27.0
|
github.com/nspcc-dev/neofs-api-go v1.27.0
|
||||||
github.com/nspcc-dev/neofs-crypto v0.3.0
|
github.com/nspcc-dev/neofs-crypto v0.3.0
|
||||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210609143631-0d3c078a0d9b
|
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210615074944-86a9aa92599b
|
||||||
github.com/prometheus/client_golang v1.9.0
|
github.com/prometheus/client_golang v1.9.0
|
||||||
github.com/prometheus/common v0.15.0
|
github.com/prometheus/common v0.15.0
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -321,6 +321,8 @@ github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnB
|
||||||
github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
github.com/nspcc-dev/neofs-crypto v0.3.0/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
|
||||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210609143631-0d3c078a0d9b h1:2alc6tGPHScEATOxlrYuHCTl+DbhVaqigT5Bo1QXY90=
|
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210609143631-0d3c078a0d9b h1:2alc6tGPHScEATOxlrYuHCTl+DbhVaqigT5Bo1QXY90=
|
||||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210609143631-0d3c078a0d9b/go.mod h1:1djNrOkpTTbNUlJM/MvTmohJUaWKUMy9JHSCCA8rJEc=
|
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210609143631-0d3c078a0d9b/go.mod h1:1djNrOkpTTbNUlJM/MvTmohJUaWKUMy9JHSCCA8rJEc=
|
||||||
|
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210615074944-86a9aa92599b h1:l99sCKR/mt+iFb4p1836qtoXUQEGYlEzqWAeAliEaE8=
|
||||||
|
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210615074944-86a9aa92599b/go.mod h1:1djNrOkpTTbNUlJM/MvTmohJUaWKUMy9JHSCCA8rJEc=
|
||||||
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
||||||
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
|
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
|
||||||
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
|
||||||
"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/nspcc-dev/neofs-api-go/pkg/owner"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/session"
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
||||||
"github.com/nspcc-dev/neofs-http-gw/tokens"
|
"github.com/nspcc-dev/neofs-http-gw/tokens"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/pkg/pool"
|
"github.com/nspcc-dev/neofs-sdk-go/pkg/pool"
|
||||||
|
@ -43,8 +42,6 @@ func (u *Uploader) Upload(c *fasthttp.RequestCtx) {
|
||||||
err error
|
err error
|
||||||
file MultipartFile
|
file MultipartFile
|
||||||
obj *object.ID
|
obj *object.ID
|
||||||
conn client.Object
|
|
||||||
tkn *session.Token
|
|
||||||
addr = object.NewAddress()
|
addr = object.NewAddress()
|
||||||
cid = cid.New()
|
cid = cid.New()
|
||||||
scid, _ = c.UserValue("cid").(string)
|
scid, _ = c.UserValue("cid").(string)
|
||||||
|
@ -106,14 +103,6 @@ func (u *Uploader) Upload(c *fasthttp.RequestCtx) {
|
||||||
}
|
}
|
||||||
oid, bt := u.fetchOwnerAndBearerToken(c)
|
oid, bt := u.fetchOwnerAndBearerToken(c)
|
||||||
|
|
||||||
// Try to put file into NeoFS or throw an error.
|
|
||||||
conn, tkn, err = u.pool.Connection()
|
|
||||||
if err != nil {
|
|
||||||
log.Error("failed to get neofs connection artifacts", zap.Error(err))
|
|
||||||
c.Error("failed to get neofs connection artifacts", fasthttp.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
rawObject := object.NewRaw()
|
rawObject := object.NewRaw()
|
||||||
rawObject.SetContainerID(cid)
|
rawObject.SetContainerID(cid)
|
||||||
rawObject.SetOwnerID(oid)
|
rawObject.SetOwnerID(oid)
|
||||||
|
@ -121,7 +110,7 @@ func (u *Uploader) Upload(c *fasthttp.RequestCtx) {
|
||||||
|
|
||||||
ops := new(client.PutObjectParams).WithObject(rawObject.Object()).WithPayloadReader(file)
|
ops := new(client.PutObjectParams).WithObject(rawObject.Object()).WithPayloadReader(file)
|
||||||
|
|
||||||
if obj, err = conn.PutObject(c, ops, client.WithSession(tkn), client.WithBearer(bt)); err != nil {
|
if obj, err = u.pool.PutObject(c, ops, client.WithBearer(bt)); err != nil {
|
||||||
log.Error("could not store file in neofs", zap.Error(err))
|
log.Error("could not store file in neofs", zap.Error(err))
|
||||||
c.Error("could not store file in neofs", fasthttp.StatusBadRequest)
|
c.Error("could not store file in neofs", fasthttp.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue