2020-07-24 13:54:03 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2020-07-24 13:54:03 +00:00
|
|
|
)
|
|
|
|
|
2024-02-06 17:29:39 +00:00
|
|
|
// list returns a list of container identifiers belonging
|
2023-02-05 15:59:38 +00:00
|
|
|
// to the specified user of FrostFS system. The list is composed
|
2022-01-31 13:34:01 +00:00
|
|
|
// through Container contract call.
|
|
|
|
//
|
2023-02-05 15:59:38 +00:00
|
|
|
// Returns the identifiers of all FrostFS containers if pointer
|
2022-05-17 13:59:46 +00:00
|
|
|
// to user identifier is nil.
|
2024-02-06 17:29:39 +00:00
|
|
|
func (c *Client) list(idUser *user.ID) ([]cid.ID, error) {
|
2022-01-31 13:34:01 +00:00
|
|
|
var rawID []byte
|
2022-05-17 13:59:46 +00:00
|
|
|
|
|
|
|
if idUser != nil {
|
|
|
|
rawID = idUser.WalletBytes()
|
2022-01-31 13:34:01 +00:00
|
|
|
}
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
prm := client.TestInvokePrm{}
|
|
|
|
prm.SetMethod(listMethod)
|
|
|
|
prm.SetArgs(rawID)
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
res, err := c.client.TestInvoke(prm)
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2024-12-04 08:17:13 +00:00
|
|
|
return nil, fmt.Errorf("test invoke (%s): %w", listMethod, err)
|
2022-01-31 13:34:01 +00:00
|
|
|
} else if ln := len(res); ln != 1 {
|
2022-01-29 13:06:36 +00:00
|
|
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d", listMethod, ln)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
res, err = client.ArrayFromStackItem(res[0])
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2024-12-12 12:06:20 +00:00
|
|
|
return nil, fmt.Errorf("get stack item array from stack item (%s): %w", listMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cidList := make([]cid.ID, 0, len(res))
|
2022-01-31 13:34:01 +00:00
|
|
|
for i := range res {
|
2022-05-31 17:00:41 +00:00
|
|
|
rawID, err := client.BytesFromStackItem(res[i])
|
2020-07-24 13:54:03 +00:00
|
|
|
if err != nil {
|
2024-12-12 12:06:20 +00:00
|
|
|
return nil, fmt.Errorf("get byte array from stack item (%s): %w", listMethod, err)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
var id cid.ID
|
2022-01-31 13:34:01 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
err = id.Decode(rawID)
|
2022-05-12 16:37:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("decode container ID: %w", err)
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cidList = append(cidList, id)
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 13:34:01 +00:00
|
|
|
return cidList, nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|