NFSSVC-27 Return list of buckets from getContainerList

This commit is contained in:
Evgeniy Kulikov 2020-07-28 01:56:10 +03:00
parent b12b5008e3
commit 504ef4da91

View file

@ -77,9 +77,10 @@ func (h *handler) getContainerInfo(ctx context.Context, p cnrInfoParams) (*Bucke
}, nil }, nil
} }
func (h *handler) getContainerList(ctx context.Context, tkn *service.BearerTokenMsg) ([]refs.CID, error) { func (h *handler) getContainerList(ctx context.Context, tkn *service.BearerTokenMsg) ([]*Bucket, error) {
var ( var (
err error err error
inf *Bucket
con *grpc.ClientConn con *grpc.ClientConn
res *container.ListResponse res *container.ListResponse
) )
@ -97,14 +98,25 @@ func (h *handler) getContainerList(ctx context.Context, tkn *service.BearerToken
return nil, errors.Wrap(err, "could not fetch list containers") return nil, errors.Wrap(err, "could not fetch list containers")
} }
return res.CID, nil params := cnrInfoParams{tkn: tkn}
result := make([]*Bucket, 0, len(res.CID))
for _, cid := range res.CID {
params.cid = cid
if inf, err = h.getContainerInfo(ctx, params); err != nil {
return nil, errors.Wrap(err, "could not fetch container info")
}
result = append(result, inf)
}
return result, nil
} }
func (h *handler) ListBucketsHandler(w http.ResponseWriter, r *http.Request) { func (h *handler) ListBucketsHandler(w http.ResponseWriter, r *http.Request) {
var ( var (
err error err error
inf *Bucket lst []*Bucket
lst []refs.CID
tkn *service.BearerTokenMsg tkn *service.BearerTokenMsg
) )
@ -147,31 +159,7 @@ func (h *handler) ListBucketsHandler(w http.ResponseWriter, r *http.Request) {
DisplayName: tkn.OwnerID.String(), DisplayName: tkn.OwnerID.String(),
}} }}
params := cnrInfoParams{tkn: tkn} result.Buckets.Buckets = lst
for _, cid := range lst {
// should receive each container info (??):
params.cid = cid
if inf, err = h.getContainerInfo(ctx, params); err != nil {
h.log.Error("could not fetch bucket info",
zap.Error(err))
// TODO check that error isn't gRPC error
e := api.GetAPIError(api.ErrInternalError)
api.WriteErrorResponse(ctx, w, api.Error{
Code: e.Code,
Description: err.Error(),
HTTPStatusCode: e.HTTPStatusCode,
}, r.URL)
return
}
result.Buckets.Buckets = append(result.Buckets.Buckets, inf)
}
// Generate response. // Generate response.
encodedSuccessResponse := api.EncodeResponse(result) encodedSuccessResponse := api.EncodeResponse(result)