2020-07-03 13:52:04 +00:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2020-07-14 13:12:30 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2020-07-03 13:52:04 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/container"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/refs"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/service"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (n *neofsObject) containerList(ctx context.Context) ([]refs.CID, error) {
|
|
|
|
req := new(container.ListRequest)
|
|
|
|
req.OwnerID = n.owner
|
|
|
|
req.SetTTL(service.SingleForwardingTTL)
|
|
|
|
req.SetVersion(APIVersion)
|
|
|
|
|
2020-07-03 14:12:30 +00:00
|
|
|
err := service.SignRequestData(n.key, req)
|
2020-07-03 13:52:04 +00:00
|
|
|
if err != nil {
|
2020-07-14 13:12:30 +00:00
|
|
|
n.log.Error("could not prepare request",
|
|
|
|
zap.Error(err))
|
2020-07-03 13:52:04 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
conn, err := n.cli.GetConnection(ctx)
|
|
|
|
if err != nil {
|
2020-07-14 13:12:30 +00:00
|
|
|
n.log.Error("could not prepare client",
|
|
|
|
zap.Error(err))
|
2020-07-03 13:52:04 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: think about timeout
|
|
|
|
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
res, err := container.NewServiceClient(conn).List(ctx, req)
|
|
|
|
if err != nil {
|
2020-07-14 13:12:30 +00:00
|
|
|
n.log.Error("could not list buckets",
|
|
|
|
zap.Error(err))
|
2020-07-03 13:52:04 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.CID, nil
|
|
|
|
}
|