Some checks failed
/ DCO (pull_request) Failing after 29s
/ Vulncheck (pull_request) Successful in 55s
/ Builds (pull_request) Successful in 1m11s
/ OCI image (pull_request) Successful in 1m21s
/ Lint (pull_request) Successful in 2m22s
/ Tests (pull_request) Successful in 1m7s
/ Integration tests (pull_request) Failing after 5m57s
Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
93 lines
2.6 KiB
Go
93 lines
2.6 KiB
Go
package handler
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
containerContract "git.frostfs.info/TrueCloudLab/frostfs-contract/container"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/data"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/handler/middleware"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/logs"
|
|
v2container "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/container"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
const (
|
|
attributeLocationConstraint = ".s3-location-constraint"
|
|
AttributeLockEnabled = "LockEnabled"
|
|
)
|
|
|
|
func (h *Handler) containerInfo(ctx context.Context, cnrID cid.ID) (*data.BucketInfo, error) {
|
|
var (
|
|
err error
|
|
res *container.Container
|
|
log = h.reqLogger(ctx).With(zap.Stringer("cid", cnrID))
|
|
|
|
info = &data.BucketInfo{
|
|
CID: cnrID,
|
|
Name: cnrID.EncodeToString(),
|
|
}
|
|
)
|
|
|
|
res, err = h.cnrContract.GetContainerByID(cnrID)
|
|
if err != nil {
|
|
if strings.Contains(err.Error(), containerContract.NotFoundError) {
|
|
return nil, fmt.Errorf("get container: %s", err.Error())
|
|
}
|
|
return nil, fmt.Errorf("get frostfs container: %w", err)
|
|
}
|
|
|
|
cnr := *res
|
|
|
|
info.Owner = cnr.Owner()
|
|
if domain := container.ReadDomain(cnr); domain.Name() != "" {
|
|
info.Name = domain.Name()
|
|
info.Zone = domain.Zone()
|
|
}
|
|
info.Created = container.CreatedAt(cnr)
|
|
info.LocationConstraint = cnr.Attribute(attributeLocationConstraint)
|
|
info.HomomorphicHashDisabled = container.IsHomomorphicHashingDisabled(cnr)
|
|
info.PlacementPolicy = cnr.PlacementPolicy()
|
|
|
|
attrLockEnabled := cnr.Attribute(AttributeLockEnabled)
|
|
if len(attrLockEnabled) > 0 {
|
|
info.ObjectLockEnabled, err = strconv.ParseBool(attrLockEnabled)
|
|
if err != nil {
|
|
log.Error(logs.CouldNotParseContainerObjectLockEnabledAttribute,
|
|
zap.String("lock_enabled", attrLockEnabled),
|
|
zap.Error(err),
|
|
logs.TagField(logs.TagDatapath),
|
|
)
|
|
}
|
|
}
|
|
ns, err := middleware.GetNamespace(ctx)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("get namespace: %w", err)
|
|
}
|
|
zone := formContainerZone(ns)
|
|
if zone != info.Zone {
|
|
return nil, fmt.Errorf("ns '%s' and zone '%s' are mismatched for container '%s'", zone, info.Zone, cnrID)
|
|
}
|
|
|
|
if err = h.cache.Put(info); err != nil {
|
|
h.reqLogger(ctx).Warn(logs.CouldntPutBucketIntoCache,
|
|
zap.String("bucket name", info.Name),
|
|
zap.Stringer("bucket cid", info.CID),
|
|
zap.Error(err),
|
|
logs.TagField(logs.TagDatapath))
|
|
}
|
|
|
|
return info, nil
|
|
}
|
|
|
|
func formContainerZone(ns string) string {
|
|
if len(ns) == 0 {
|
|
return v2container.SysAttributeZoneDefault
|
|
}
|
|
|
|
return ns + ".ns"
|
|
}
|