[#455] Use contract to get containers
All checks were successful
/ DCO (pull_request) Successful in 31s
/ Vulncheck (pull_request) Successful in 1m15s
/ Builds (pull_request) Successful in 1m26s
/ OCI image (pull_request) Successful in 2m10s
/ Lint (pull_request) Successful in 2m14s
/ Tests (pull_request) Successful in 1m20s
/ Vulncheck (push) Successful in 1m11s
/ Builds (push) Successful in 1m2s
/ OCI image (push) Successful in 2m5s
/ Lint (push) Successful in 2m6s
/ Tests (push) Successful in 1m16s
All checks were successful
/ DCO (pull_request) Successful in 31s
/ Vulncheck (pull_request) Successful in 1m15s
/ Builds (pull_request) Successful in 1m26s
/ OCI image (pull_request) Successful in 2m10s
/ Lint (pull_request) Successful in 2m14s
/ Tests (pull_request) Successful in 1m20s
/ Vulncheck (push) Successful in 1m11s
/ Builds (push) Successful in 1m2s
/ OCI image (push) Successful in 2m5s
/ Lint (push) Successful in 2m6s
/ Tests (push) Successful in 1m16s
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
This commit is contained in:
parent
949fc0b484
commit
2ad2531d3a
16 changed files with 193 additions and 47 deletions
|
@ -7,14 +7,15 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
containerContract "git.frostfs.info/TrueCloudLab/frostfs-contract/container"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/data"
|
||||
apierr "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer/frostfs"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/logs"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -23,23 +24,23 @@ const (
|
|||
AttributeLockEnabled = "LockEnabled"
|
||||
)
|
||||
|
||||
func (n *Layer) containerInfo(ctx context.Context, prm frostfs.PrmContainer) (*data.BucketInfo, error) {
|
||||
func (n *Layer) containerInfo(ctx context.Context, cnrID cid.ID) (*data.BucketInfo, error) {
|
||||
var (
|
||||
err error
|
||||
res *container.Container
|
||||
log = n.reqLogger(ctx).With(zap.Stringer("cid", prm.ContainerID))
|
||||
log = n.reqLogger(ctx).With(zap.Stringer("cid", cnrID))
|
||||
|
||||
info = &data.BucketInfo{
|
||||
CID: prm.ContainerID,
|
||||
Name: prm.ContainerID.EncodeToString(),
|
||||
CID: cnrID,
|
||||
Name: cnrID.EncodeToString(),
|
||||
}
|
||||
|
||||
reqInfo = middleware.GetReqInfo(ctx)
|
||||
)
|
||||
|
||||
res, err = n.frostFS.Container(ctx, prm)
|
||||
res, err = n.cnrContract.GetContainerByID(cnrID)
|
||||
if err != nil {
|
||||
if client.IsErrContainerNotFound(err) {
|
||||
if strings.Contains(err.Error(), containerContract.NotFoundError) {
|
||||
return nil, fmt.Errorf("%w: %s", apierr.GetAPIError(apierr.ErrNoSuchBucket), err.Error())
|
||||
}
|
||||
return nil, fmt.Errorf("get frostfs container: %w", err)
|
||||
|
@ -71,7 +72,7 @@ func (n *Layer) containerInfo(ctx context.Context, prm frostfs.PrmContainer) (*d
|
|||
|
||||
zone := n.features.FormContainerZone(reqInfo.Namespace)
|
||||
if zone != info.Zone {
|
||||
return nil, fmt.Errorf("ns '%s' and zone '%s' are mismatched for container '%s'", zone, info.Zone, prm.ContainerID)
|
||||
return nil, fmt.Errorf("ns '%s' and zone '%s' are mismatched for container '%s'", zone, info.Zone, cnrID)
|
||||
}
|
||||
|
||||
n.cache.PutBucket(info)
|
||||
|
@ -95,11 +96,7 @@ func (n *Layer) containerList(ctx context.Context, listParams ListBucketsParams)
|
|||
|
||||
list := make([]*data.BucketInfo, 0, len(res))
|
||||
for i := range res {
|
||||
getPrm := frostfs.PrmContainer{
|
||||
ContainerID: res[i],
|
||||
SessionToken: stoken,
|
||||
}
|
||||
info, err := n.containerInfo(ctx, getPrm)
|
||||
info, err := n.containerInfo(ctx, res[i])
|
||||
if err != nil {
|
||||
n.reqLogger(ctx).Error(logs.CouldNotFetchContainerInfo, zap.Error(err), logs.TagField(logs.TagExternalStorage))
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue