[#63] Using client.Object from sdk

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-06-15 11:28:30 +03:00
parent 9148cef0fc
commit fffb0b2f12
4 changed files with 8 additions and 44 deletions

View file

@ -15,7 +15,6 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg/client"
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/session"
"github.com/nspcc-dev/neofs-http-gw/tokens"
"github.com/nspcc-dev/neofs-sdk-go/pkg/pool"
"github.com/valyala/fasthttp"
@ -72,9 +71,7 @@ func isValidValue(s string) bool {
return true
}
func (r *request) receiveFile(clnt client.Object,
sessionToken *session.Token,
objectAddress *object.Address) {
func (r *request) receiveFile(clnt client.Object, objectAddress *object.Address) {
var (
err error
dis = "inline"
@ -95,7 +92,6 @@ func (r *request) receiveFile(clnt client.Object,
obj, err = clnt.GetObject(
r.RequestCtx,
options,
client.WithSession(sessionToken),
)
if err != nil {
r.log.Error(
@ -194,8 +190,6 @@ func (d *Downloader) DownloadByAddress(c *fasthttp.RequestCtx) {
oid, _ = c.UserValue("oid").(string)
val = strings.Join([]string{cid, 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 {
log.Error("wrong object address", zap.Error(err))
@ -203,13 +197,7 @@ func (d *Downloader) DownloadByAddress(c *fasthttp.RequestCtx) {
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
}
d.newRequest(c, log).receiveFile(conn, tkn, address)
d.newRequest(c, log).receiveFile(d.pool, address)
}
// DownloadByAttribute handles attribute-based download requests.
@ -221,8 +209,6 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) {
val, _ = c.UserValue("attr_val").(string)
log = d.log.With(zap.String("cid", scid), zap.String("attr_key", key), zap.String("attr_val", val))
ids []*object.ID
conn client.Object
tkn *session.Token
)
cid := cid.New()
if err = cid.Parse(scid); err != nil {
@ -231,19 +217,12 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) {
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.AddRootFilter()
options.AddFilter(key, val, object.MatchStringEqual)
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))
c.Error("something went wrong", fasthttp.StatusBadRequest)
return
@ -261,11 +240,5 @@ func (d *Downloader) DownloadByAttribute(c *fasthttp.RequestCtx) {
address.SetContainerID(cid)
address.SetObjectID(ids[0])
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
}
d.newRequest(c, log).receiveFile(conn, tkn, address)
d.newRequest(c, log).receiveFile(d.pool, address)
}