Skip to content

Commit

Permalink
neofs-cli/control: add object list control command
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
End-rey committed Sep 12, 2024
1 parent a0e775d commit e6a62c9
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions cmd/neofs-cli/modules/control/object.go
Original file line number Diff line number Diff line change
@@ -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)

Check warning on line 14 in cmd/neofs-cli/modules/control/object.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object.go#L12-L14

Added lines #L12 - L14 were not covered by tests

initControlObjectsListCmd()
initObjectStatusFlags()

Check warning on line 17 in cmd/neofs-cli/modules/control/object.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object.go#L16-L17

Added lines #L16 - L17 were not covered by tests
}
54 changes: 54 additions & 0 deletions cmd/neofs-cli/modules/control/object_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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)

Check warning on line 21 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L20-L21

Added lines #L20 - L21 were not covered by tests
}

func listObjects(cmd *cobra.Command, _ []string) {
ctx, cancel := commonflags.GetCommandContext(cmd)
defer cancel()

Check warning on line 26 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L24-L26

Added lines #L24 - L26 were not covered by tests

pk := key.Get(cmd)

Check warning on line 28 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L28

Added line #L28 was not covered by tests

req := &control.ListObjectsRequest{
Body: &control.ListObjectsRequest_Body{},

Check warning on line 31 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L30-L31

Added lines #L30 - L31 were not covered by tests
}
signRequest(cmd, pk, req)

Check warning on line 33 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L33

Added line #L33 was not covered by tests

cli := getClient(ctx, cmd)

Check warning on line 35 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L35

Added line #L35 was not covered by tests

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)

Check warning on line 43 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L37-L43

Added lines #L37 - L43 were not covered by tests

if len(resp) == 0 {
cmd.Println("<empty response>")

Check warning on line 46 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L45-L46

Added lines #L45 - L46 were not covered by tests
}

for _, r := range resp {
verifyResponse(cmd, r.GetSignature(), r.GetBody())

Check warning on line 50 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L49-L50

Added lines #L49 - L50 were not covered by tests

cmd.Println(string(r.GetBody().GetObjectAddress()))

Check warning on line 52 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L52

Added line #L52 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 1 addition & 5 deletions cmd/neofs-cli/modules/control/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ const (
)

func init() {
objectCmd.AddCommand(
objectStatusCmd,
)

Cmd.AddCommand(
healthCheckCmd,
setNetmapStatusCmd,
Expand All @@ -45,5 +41,5 @@ func init() {
initControlDropObjectsCmd()
initControlShardsCmd()
initControlSynchronizeTreeCmd()
initObjectStatusFlags()
initControlObjectsCmd()

Check warning on line 44 in cmd/neofs-cli/modules/control/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/root.go#L44

Added line #L44 was not covered by tests
}

0 comments on commit e6a62c9

Please sign in to comment.