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..73a8f3cc20 --- /dev/null +++ b/cmd/neofs-cli/modules/control/object_list.go @@ -0,0 +1,47 @@ +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: "Get list of all objects in the storage node", + Long: "Get 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) + + err := cli.ExecRaw(func(client *rawclient.Client) error { + return control.ListObjects(client, req, func(r *control.ListObjectsResponse) { + verifyResponse(cmd, r.GetSignature(), r.GetBody()) + + for _, address := range r.GetBody().GetObjectAddress() { + cmd.Println(string(address)) + } + }) + }) + common.ExitOnErr(cmd, "rpc error: %w", err) +} 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() }