2022-05-31 14:27:08 +00:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
errorsStd "errors"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api/errors"
|
|
|
|
)
|
|
|
|
|
2022-06-28 13:35:05 +00:00
|
|
|
func (n *layer) GetObjectTaggingAndLock(ctx context.Context, objVersion *ObjectVersion, nodeVersion *data.NodeVersion) (map[string]string, *data.LockInfo, error) {
|
2022-05-31 14:27:08 +00:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
tags map[string]string
|
|
|
|
)
|
|
|
|
|
2022-10-03 14:33:49 +00:00
|
|
|
tags = n.cache.GetTagging(objectTaggingCacheKey(objVersion))
|
|
|
|
lockInfo := n.cache.GetLockInfo(lockObjectKey(objVersion))
|
2022-05-31 14:27:08 +00:00
|
|
|
|
|
|
|
if tags != nil && lockInfo != nil {
|
|
|
|
return tags, lockInfo, nil
|
|
|
|
}
|
|
|
|
|
2022-06-28 13:35:05 +00:00
|
|
|
if nodeVersion == nil {
|
|
|
|
nodeVersion, err = n.getNodeVersion(ctx, objVersion)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2022-05-31 14:27:08 +00:00
|
|
|
}
|
|
|
|
|
2022-09-13 09:44:18 +00:00
|
|
|
tags, lockInfo, err = n.treeService.GetObjectTaggingAndLock(ctx, objVersion.BktInfo, nodeVersion)
|
2022-05-31 14:27:08 +00:00
|
|
|
if err != nil {
|
|
|
|
if errorsStd.Is(err, ErrNodeNotFound) {
|
|
|
|
return nil, nil, errors.GetAPIError(errors.ErrNoSuchKey)
|
|
|
|
}
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2022-10-03 14:33:49 +00:00
|
|
|
n.cache.PutTagging(objectTaggingCacheKey(objVersion), tags)
|
|
|
|
n.cache.PutLockInfo(lockObjectKey(objVersion), lockInfo)
|
2022-05-31 14:27:08 +00:00
|
|
|
|
|
|
|
return tags, lockInfo, nil
|
|
|
|
}
|