Skip to content

Commit c6a3201

Browse files
authored
neofs-lens: Add a simple link objects inspector (#2799)
2 parents 97a2dc7 + efa1c8d commit c6a3201

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Changelog for NeoFS Node
88
- Support of `GT`, `GE`, `LT` and `LE` numeric comparison operators in CLI (#2733)
99
- SN eACL processing of NULL and numeric operators (#2742)
1010
- CLI now allows to create and print eACL with numeric filters (#2742)
11-
- gRPC connection limits per endpoint (#1240)
11+
- gRPC connection limits per endpoint (#1240)
12+
- `neofs-lens object link` command for the new link object inspection (#2799)
1213

1314
### Fixed
1415
- Access to `PUT` objects no longer grants `DELETE` rights (#2261)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package object
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
"os"
7+
8+
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
9+
"github.com/nspcc-dev/neofs-sdk-go/object"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var linkCMD = &cobra.Command{
14+
Use: "link",
15+
Short: "Inspect link object",
16+
Run: linkFunc,
17+
}
18+
19+
func linkFunc(cmd *cobra.Command, _ []string) {
20+
if vPath == "" {
21+
common.ExitOnErr(cmd, errors.New("empty path to file"))
22+
}
23+
24+
raw, err := os.ReadFile(vPath)
25+
common.ExitOnErr(cmd, common.Errf("reading file: %w", err))
26+
27+
var link object.Link
28+
err = link.Unmarshal(raw)
29+
if err != nil {
30+
cmd.Printf("%q file does not contain raw link payload, trying to decode it as a full NeoFS object", vPath)
31+
32+
var obj object.Object
33+
err = obj.Unmarshal(raw)
34+
common.ExitOnErr(cmd, common.Errf("decoding NeoFS object: %w", err))
35+
36+
if typeGot := obj.Type(); typeGot != object.TypeLink {
37+
common.ExitOnErr(cmd, fmt.Errorf("unexpected object type (not %s): %s", object.TypeLink, typeGot))
38+
}
39+
40+
err = obj.ReadLink(&link)
41+
}
42+
common.ExitOnErr(cmd, common.Errf("decoding link object: %w", err))
43+
44+
if len(link.Objects()) == 0 {
45+
common.ExitOnErr(cmd, errors.New("empty children list"))
46+
}
47+
48+
cmd.Println("Children (sorted according to the read payload):")
49+
50+
for _, measuredObject := range link.Objects() {
51+
cmd.Printf("Size: %d, object ID: %s\n", measuredObject.ObjectSize(), measuredObject.ObjectID())
52+
}
53+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package object
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var vPath string
10+
11+
// Root defines root command for operations with NeoFS objects.
12+
var Root = &cobra.Command{
13+
Use: "object",
14+
Short: "NeoFS object inspection",
15+
}
16+
17+
const filePathFlagKey = "file"
18+
19+
func init() {
20+
pFlags := Root.PersistentFlags()
21+
pFlags.StringVar(&vPath, filePathFlagKey, "", "Path to file with NeoFS object")
22+
23+
err := cobra.MarkFlagFilename(pFlags, filePathFlagKey)
24+
if err != nil {
25+
panic(fmt.Errorf("MarkFlagFilename for %s flag: %w", filePathFlagKey, err))
26+
}
27+
err = cobra.MarkFlagRequired(pFlags, filePathFlagKey)
28+
if err != nil {
29+
panic(fmt.Errorf("MarkFlagRequired for %s flag: %w", filePathFlagKey, err))
30+
}
31+
32+
Root.AddCommand(linkCMD)
33+
}

cmd/neofs-lens/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55

66
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/meta"
7+
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/object"
78
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/peapod"
89
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/storage"
910
"github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal/writecache"
@@ -40,6 +41,7 @@ func init() {
4041
meta.Root,
4142
writecache.Root,
4243
storage.Root,
44+
object.Root,
4345
gendoc.Command(command),
4446
)
4547
}

0 commit comments

Comments
 (0)