Skip to content

Commit

Permalink
neofs-lens: add payload-only flag
Browse files Browse the repository at this point in the history
With payload-only flag the inspect commands save only payload of the
object, otherwise full object will be saved.

Refs #2543.

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
  • Loading branch information
AliceInHunterland committed Sep 12, 2023
1 parent b443f8c commit 2185c77
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ minor release, the component will be purged, so be prepared (see `Updating` sect
- SN network validation (is available by its announced addresses) on bootstrap by the IR (#2475)
- Display of container alias fee info in `neofs-cli netmap netinfo` (#2553)
- `neofs-lens storage inspect` CLI command (#1336)
- `neofs-lens` payload-only flag (#2543)

### Fixed
- `neo-go` RPC connection loss handling (#1337)
Expand Down
8 changes: 7 additions & 1 deletion cmd/neofs-lens/internal/blobovnicza/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func init() {
common.AddAddressFlag(inspectCMD, &vAddress)
common.AddComponentPathFlag(inspectCMD, &vPath)
common.AddOutputFileFlag(inspectCMD, &vOut)
common.AddPayloadOnlyFlag(inspectCMD, &vPayloadOnly)
}

func inspectFunc(cmd *cobra.Command, _ []string) {
Expand All @@ -44,5 +45,10 @@ func inspectFunc(cmd *cobra.Command, _ []string) {
)

common.PrintObjectHeader(cmd, o)
common.WriteObjectToFile(cmd, vOut, data)
if vPayloadOnly {
data = o.Payload()
common.WriteObjectToFile(cmd, vOut, data, true)
return
}
common.WriteObjectToFile(cmd, vOut, data, false)
}
7 changes: 4 additions & 3 deletions cmd/neofs-lens/internal/blobovnicza/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
)

var (
vAddress string
vPath string
vOut string
vAddress string
vPath string
vOut string
vPayloadOnly bool
)

// Root contains `blobovnicza` command definition.
Expand Down
4 changes: 4 additions & 0 deletions cmd/neofs-lens/internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ func AddConfigFileFlag(cmd *cobra.Command, v *string) {
_ = cmd.MarkFlagFilename(flagConfigFile)
_ = cmd.MarkFlagRequired(flagConfigFile)
}

func AddPayloadOnlyFlag(cmd *cobra.Command, v *bool) {
cmd.Flags().BoolVar(v, "payload-only", false, "Save only object payload")
}
7 changes: 6 additions & 1 deletion cmd/neofs-lens/internal/peapod/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func init() {
common.AddAddressFlag(inspectCMD, &vAddress)
common.AddComponentPathFlag(inspectCMD, &vPath)
common.AddOutputFileFlag(inspectCMD, &vOut)
common.AddPayloadOnlyFlag(inspectCMD, &vPayloadOnly)
}

func inspectFunc(cmd *cobra.Command, _ []string) {
Expand All @@ -32,5 +33,9 @@ func inspectFunc(cmd *cobra.Command, _ []string) {
common.ExitOnErr(cmd, common.Errf("failed to read object from Peapod: %w", err))

common.PrintObjectHeader(cmd, *res.Object)
common.WriteObjectToFile(cmd, vOut, res.RawData)
if vPayloadOnly {
common.WriteObjectToFile(cmd, vOut, res.RawData, true)
return
}
common.WriteObjectToFile(cmd, vOut, res.RawData, false)
}
7 changes: 4 additions & 3 deletions cmd/neofs-lens/internal/peapod/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
)

var (
vAddress string
vPath string
vOut string
vAddress string
vPath string
vOut string
vPayloadOnly bool
)

// Root defines root command for operations with Peapod.
Expand Down
8 changes: 6 additions & 2 deletions cmd/neofs-lens/internal/printers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ func printObjectID(cmd *cobra.Command, recv func() (oid.ID, bool)) {

// WriteObjectToFile writes object to the provided path. Does nothing if
// the path is empty.
func WriteObjectToFile(cmd *cobra.Command, path string, data []byte) {
func WriteObjectToFile(cmd *cobra.Command, path string, data []byte, payloadOnly bool) {
if path == "" {
return
}

ExitOnErr(cmd, Errf("could not write file: %w",
os.WriteFile(path, data, 0644)))

cmd.Printf("\nSaved payload to '%s' file\n", path)
if payloadOnly {
cmd.Printf("\nSaved payload to '%s' file\n", path)
return
}
cmd.Printf("\nSaved object to '%s' file\n", path)
}
7 changes: 6 additions & 1 deletion cmd/neofs-lens/internal/storage/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func init() {
common.AddAddressFlag(storageInspectObjCMD, &vAddress)
common.AddOutputFileFlag(storageInspectObjCMD, &vOut)
common.AddConfigFileFlag(storageInspectObjCMD, &vConfig)
common.AddPayloadOnlyFlag(storageInspectObjCMD, &vPayloadOnly)
}

func inspectObject(cmd *cobra.Command, _ []string) {
Expand All @@ -34,7 +35,11 @@ func inspectObject(cmd *cobra.Command, _ []string) {
common.ExitOnErr(cmd, common.Errf("could not fetch object: %w", err))

common.PrintObjectHeader(cmd, *obj)
if vPayloadOnly {
common.WriteObjectToFile(cmd, vOut, obj.Payload(), true)
return
}
data, err := obj.Marshal()
common.ExitOnErr(cmd, common.Errf("could not marshal object: %w", err))
common.WriteObjectToFile(cmd, vOut, data)
common.WriteObjectToFile(cmd, vOut, data, false)
}
7 changes: 4 additions & 3 deletions cmd/neofs-lens/internal/storage/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import (
)

var (
vAddress string
vOut string
vConfig string
vAddress string
vOut string
vConfig string
vPayloadOnly bool
)

var Root = &cobra.Command{
Expand Down
7 changes: 6 additions & 1 deletion cmd/neofs-lens/internal/writecache/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func init() {
common.AddAddressFlag(inspectCMD, &vAddress)
common.AddComponentPathFlag(inspectCMD, &vPath)
common.AddOutputFileFlag(inspectCMD, &vOut)
common.AddPayloadOnlyFlag(inspectCMD, &vPayloadOnly)
}

func inspectFunc(cmd *cobra.Command, _ []string) {
Expand All @@ -31,5 +32,9 @@ func inspectFunc(cmd *cobra.Command, _ []string) {
common.ExitOnErr(cmd, common.Errf("could not unmarshal object: %w", o.Unmarshal(data)))

common.PrintObjectHeader(cmd, o)
common.WriteObjectToFile(cmd, vOut, data)
if vPayloadOnly {
common.WriteObjectToFile(cmd, vOut, data, true)
return
}
common.WriteObjectToFile(cmd, vOut, data, false)
}
7 changes: 4 additions & 3 deletions cmd/neofs-lens/internal/writecache/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
)

var (
vAddress string
vPath string
vOut string
vAddress string
vPath string
vOut string
vPayloadOnly bool
)

// Root contains `write-cache` command definition.
Expand Down

0 comments on commit 2185c77

Please sign in to comment.