Some checks failed
DCO action / DCO (pull_request) Successful in 59s
Vulncheck / Vulncheck (pull_request) Successful in 1m4s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m55s
Build / Build Components (pull_request) Successful in 2m4s
Tests and linters / Staticcheck (pull_request) Successful in 2m38s
Tests and linters / Lint (pull_request) Successful in 3m16s
Tests and linters / Run gofumpt (pull_request) Successful in 3m54s
Tests and linters / Tests (pull_request) Successful in 4m12s
Tests and linters / gopls check (pull_request) Successful in 4m31s
Tests and linters / Tests with -race (pull_request) Successful in 4m38s
OCI image / Build container images (push) Failing after 18s
Vulncheck / Vulncheck (push) Successful in 1m2s
Pre-commit hooks / Pre-commit (push) Successful in 1m39s
Build / Build Components (push) Successful in 1m45s
Tests and linters / Staticcheck (push) Successful in 2m18s
Tests and linters / Run gofumpt (push) Successful in 2m46s
Tests and linters / Lint (push) Successful in 3m5s
Tests and linters / Tests with -race (push) Successful in 3m23s
Tests and linters / Tests (push) Successful in 3m52s
Tests and linters / gopls check (push) Successful in 4m18s
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
76 lines
2.4 KiB
Go
76 lines
2.4 KiB
Go
package container
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"fmt"
|
|
"strings"
|
|
|
|
containerContract "git.frostfs.info/TrueCloudLab/frostfs-contract/container"
|
|
containercore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
|
"github.com/mr-tron/base58"
|
|
)
|
|
|
|
func (x *containerSource) DeletionInfo(ctx context.Context, cnr cid.ID) (*containercore.DelInfo, error) {
|
|
return DeletionInfo(ctx, (*Client)(x), cnr)
|
|
}
|
|
|
|
type deletionInfo interface {
|
|
DeletionInfo(ctx context.Context, cid []byte) (*containercore.DelInfo, error)
|
|
}
|
|
|
|
func DeletionInfo(ctx context.Context, c deletionInfo, cnr cid.ID) (*containercore.DelInfo, error) {
|
|
binCnr := make([]byte, sha256.Size)
|
|
cnr.Encode(binCnr)
|
|
|
|
return c.DeletionInfo(ctx, binCnr)
|
|
}
|
|
|
|
func (c *Client) DeletionInfo(ctx context.Context, cid []byte) (*containercore.DelInfo, error) {
|
|
prm := client.TestInvokePrm{}
|
|
prm.SetMethod(deletionInfoMethod)
|
|
prm.SetArgs(cid)
|
|
|
|
res, err := c.client.TestInvoke(ctx, prm)
|
|
if err != nil {
|
|
if strings.Contains(err.Error(), containerContract.NotFoundError) {
|
|
return nil, new(apistatus.ContainerNotFound)
|
|
}
|
|
return nil, fmt.Errorf("test invoke (%s): %w", deletionInfoMethod, err)
|
|
} else if ln := len(res); ln != 1 {
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", deletionInfoMethod, ln)
|
|
}
|
|
|
|
arr, err := client.ArrayFromStackItem(res[0])
|
|
if err != nil {
|
|
return nil, fmt.Errorf("get item array of container (%s): %w", deletionInfoMethod, err)
|
|
}
|
|
|
|
if len(arr) != 2 {
|
|
return nil, fmt.Errorf("unexpected container stack item count (%s): %d", deletionInfoMethod, len(arr))
|
|
}
|
|
|
|
rawOwner, err := client.BytesFromStackItem(arr[0])
|
|
if err != nil {
|
|
return nil, fmt.Errorf("get byte array of container (%s): %w", deletionInfoMethod, err)
|
|
}
|
|
|
|
var owner user.ID
|
|
if err := owner.DecodeString(base58.Encode(rawOwner)); err != nil {
|
|
return nil, fmt.Errorf("decode container owner id (%s): %w", deletionInfoMethod, err)
|
|
}
|
|
|
|
epoch, err := client.BigIntFromStackItem(arr[1])
|
|
if err != nil {
|
|
return nil, fmt.Errorf("get byte array of container signature (%s): %w", deletionInfoMethod, err)
|
|
}
|
|
|
|
return &containercore.DelInfo{
|
|
Owner: owner,
|
|
Epoch: epoch.Uint64(),
|
|
}, nil
|
|
}
|