From 07ad41e7294d70fa5f4372aeb3e9bd408367bde5 Mon Sep 17 00:00:00 2001 From: Andrey Butusov Date: Tue, 10 Sep 2024 10:55:46 +0300 Subject: [PATCH] neofs-cli/control: add `object list` control command Support command that gets list of objects in node. Create separate file for `control object` commands. ``` $ neofs-cli control object list --endpoint s01.neofs.devenv:8081 -w services/storage/wallet01.json Enter password > A2FtcmZh76XqAym55fkCvzfB7dJ5dUt3fuGzQitGkW7S/CxSt4cFbwMtnuKHjqEjsWjctdfVWWTZqLkXheLHxjn4p HimRwmgw4PNasobAxGwVMCmV45rkjvYkYdV7toDoavMu/2YCzyvgz9HMfyBAAbGNmcsq98serp77hzJuc6F4qSz5w HimRwmgw4PNasobAxGwVMCmV45rkjvYkYdV7toDoavMu/2hgSnzrZHaQZLxLNXz4XEGbHdB9Y1zUjDZa3Z1foBnma $ neofs-cli control object list --endpoint s02.neofs.devenv:8081 -w services/storage/wallet02.json Enter password > HimRwmgw4PNasobAxGwVMCmV45rkjvYkYdV7toDoavMu/GrHcAXjgWiS69iVXBpe8YGKx1H23rBbfTCBL5WojaoSw $ neofs-cli control object list --endpoint s03.neofs.devenv:8081 -w services/storage/wallet03.json Enter password > A2FtcmZh76XqAym55fkCvzfB7dJ5dUt3fuGzQitGkW7S/5rTDeZTrgMt3DZE8nbT6sKFn1MiZUKZu4Gfk7cFrW7WY HimRwmgw4PNasobAxGwVMCmV45rkjvYkYdV7toDoavMu/2hgSnzrZHaQZLxLNXz4XEGbHdB9Y1zUjDZa3Z1foBnma HimRwmgw4PNasobAxGwVMCmV45rkjvYkYdV7toDoavMu/GrHcAXjgWiS69iVXBpe8YGKx1H23rBbfTCBL5WojaoSw 4rj9mynn8tijZFK9mgdG1Zc2fjwdEJstwYC2iYRM8skw/CRuojN8Lv6nzyoEfQ4FEPWdZxSSAtM2rqQPMuZLMePJQ A2FtcmZh76XqAym55fkCvzfB7dJ5dUt3fuGzQitGkW7S/CxSt4cFbwMtnuKHjqEjsWjctdfVWWTZqLkXheLHxjn4p HimRwmgw4PNasobAxGwVMCmV45rkjvYkYdV7toDoavMu/2YCzyvgz9HMfyBAAbGNmcsq98serp77hzJuc6F4qSz5w $ neofs-cli control object list --endpoint s04.neofs.devenv:8081 -w services/storage/wallet04.json Enter password > 4rj9mynn8tijZFK9mgdG1Zc2fjwdEJstwYC2iYRM8skw/CRuojN8Lv6nzyoEfQ4FEPWdZxSSAtM2rqQPMuZLMePJQ A2FtcmZh76XqAym55fkCvzfB7dJ5dUt3fuGzQitGkW7S/5rTDeZTrgMt3DZE8nbT6sKFn1MiZUKZu4Gfk7cFrW7WY ``` Closes #2853. Signed-off-by: Andrey Butusov --- CHANGELOG.md | 1 + cmd/neofs-cli/modules/control/object.go | 18 ++++++ cmd/neofs-cli/modules/control/object_list.go | 55 +++++++++++++++++++ .../control/{objects.go => object_status.go} | 5 -- cmd/neofs-cli/modules/control/root.go | 6 +- 5 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 cmd/neofs-cli/modules/control/object.go create mode 100644 cmd/neofs-cli/modules/control/object_list.go rename cmd/neofs-cli/modules/control/{objects.go => object_status.go} (94%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16f95c8924..fe1d4e967d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Changelog for NeoFS Node ### Added - More effective FSTree writer for HDDs, new configuration options for it (#2814) +- `neofs-cli control object list` command (#2853) ### Fixed diff --git a/cmd/neofs-cli/modules/control/object.go b/cmd/neofs-cli/modules/control/object.go new file mode 100644 index 0000000000..831a477a7f --- /dev/null +++ b/cmd/neofs-cli/modules/control/object.go @@ -0,0 +1,18 @@ +package control + +import ( + "github.com/spf13/cobra" +) + +var objectCmd = &cobra.Command{ + Use: "object", + Short: "Direct object operations with storage engine", +} + +func initControlObjectsCmd() { + objectCmd.AddCommand(listObjectsCmd) + objectCmd.AddCommand(objectStatusCmd) + + initControlObjectsListCmd() + initObjectStatusFlags() +} diff --git a/cmd/neofs-cli/modules/control/object_list.go b/cmd/neofs-cli/modules/control/object_list.go new file mode 100644 index 0000000000..0dfc02c65d --- /dev/null +++ b/cmd/neofs-cli/modules/control/object_list.go @@ -0,0 +1,55 @@ +package control + +import ( + rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client" + "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" + "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags" + "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key" + "github.com/nspcc-dev/neofs-node/pkg/services/control" + "github.com/spf13/cobra" +) + +var listObjectsCmd = &cobra.Command{ + Use: "list", + Short: "List of all objects in the storage node", + Long: "List of all objects in the storage node", + Args: cobra.NoArgs, + Run: listObjects, +} + +func initControlObjectsListCmd() { + initControlFlags(listObjectsCmd) +} + +func listObjects(cmd *cobra.Command, _ []string) { + ctx, cancel := commonflags.GetCommandContext(cmd) + defer cancel() + + pk := key.Get(cmd) + + req := &control.ListObjectsRequest{ + Body: &control.ListObjectsRequest_Body{}, + } + signRequest(cmd, pk, req) + + cli := getClient(ctx, cmd) + + var resp *control.ListObjectsResponse + var err error + err = cli.ExecRaw(func(client *rawclient.Client) error { + resp, err = control.ListObjects(client, req) + return err + }) + common.ExitOnErr(cmd, "rpc error: %w", err) + + verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) + + objects := resp.GetBody().GetObjects() + if len(objects) == 0 { + cmd.Println("") + } + + for _, object := range objects { + cmd.Println(object.GetAddress()) + } +} diff --git a/cmd/neofs-cli/modules/control/objects.go b/cmd/neofs-cli/modules/control/object_status.go similarity index 94% rename from cmd/neofs-cli/modules/control/objects.go rename to cmd/neofs-cli/modules/control/object_status.go index 7f6280a2d8..9394975542 100644 --- a/cmd/neofs-cli/modules/control/objects.go +++ b/cmd/neofs-cli/modules/control/object_status.go @@ -13,11 +13,6 @@ import ( const objectFlag = "object" -var objectCmd = &cobra.Command{ - Use: "object", - Short: "Direct object operations with storage engine", -} - var objectStatusCmd = &cobra.Command{ Use: "status", Short: "Check current object status", diff --git a/cmd/neofs-cli/modules/control/root.go b/cmd/neofs-cli/modules/control/root.go index c2848bfe1a..b7b8afa294 100644 --- a/cmd/neofs-cli/modules/control/root.go +++ b/cmd/neofs-cli/modules/control/root.go @@ -27,10 +27,6 @@ const ( ) func init() { - objectCmd.AddCommand( - objectStatusCmd, - ) - Cmd.AddCommand( healthCheckCmd, setNetmapStatusCmd, @@ -45,5 +41,5 @@ func init() { initControlDropObjectsCmd() initControlShardsCmd() initControlSynchronizeTreeCmd() - initObjectStatusFlags() + initControlObjectsCmd() }