forked from TrueCloudLab/frostfs-http-gw
[#232] Use contract to get container info
Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
This commit is contained in:
parent
dbb1bcad00
commit
96a22d98f2
13 changed files with 229 additions and 44 deletions
42
internal/handler/container.go
Normal file
42
internal/handler/container.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/data"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/logs"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
||||
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (h *Handler) containerInfo(ctx context.Context, cnrID cid.ID) (*data.BucketInfo, error) {
|
||||
info := &data.BucketInfo{
|
||||
CID: cnrID,
|
||||
Name: cnrID.EncodeToString(),
|
||||
}
|
||||
res, err := h.cnrContract.GetContainerByID(cnrID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get frostfs container: %w", err)
|
||||
}
|
||||
|
||||
cnr := *res
|
||||
|
||||
if domain := container.ReadDomain(cnr); domain.Name() != "" {
|
||||
info.Name = domain.Name()
|
||||
info.Zone = domain.Zone()
|
||||
}
|
||||
info.HomomorphicHashDisabled = container.IsHomomorphicHashingDisabled(cnr)
|
||||
info.PlacementPolicy = cnr.PlacementPolicy()
|
||||
|
||||
if err = h.cache.Put(info); err != nil {
|
||||
h.reqLogger(ctx).Warn(logs.CouldntPutBucketIntoCache,
|
||||
zap.String("bucket name", info.Name),
|
||||
zap.Stringer("cid", info.CID),
|
||||
zap.Error(err),
|
||||
logs.TagField(logs.TagDatapath))
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue