diff --git a/cmd/neofs-cli/modules/control.go b/cmd/neofs-cli/modules/control.go index 9aed2839bc..692c275ab8 100644 --- a/cmd/neofs-cli/modules/control.go +++ b/cmd/neofs-cli/modules/control.go @@ -60,6 +60,7 @@ func init() { healthCheckCmd, setNetmapStatusCmd, dropObjectsCmd, + snapshotCmd, ) setNetmapStatusCmd.Flags().StringVarP(&netmapStatus, netmapStatusFlag, "", "", @@ -77,6 +78,9 @@ func init() { _ = dropObjectsCmd.MarkFlagRequired(dropObjectsFlag) healthCheckCmd.Flags().BoolVar(&healthCheckIRVar, healthcheckIRFlag, false, "Communicate with IR node") + + snapshotCmd.Flags().BoolVar(&netmapSnapshotJSON, "json", false, + "print netmap structure in JSON format") } func healthCheck(cmd *cobra.Command, _ []string) { @@ -279,3 +283,47 @@ var dropObjectsCmd = &cobra.Command{ cmd.Println("Objects were successfully marked to be removed.") }, } + +var snapshotCmd = &cobra.Command{ + Use: "netmap-snapshot", + Short: "Get network map snapshot", + Long: "Get network map snapshot", + Run: func(cmd *cobra.Command, args []string) { + key, err := getKey() + if err != nil { + cmd.PrintErrln(err) + return + } + + req := new(control.NetmapSnapshotRequest) + req.SetBody(new(control.NetmapSnapshotRequest_Body)) + + if err := controlSvc.SignMessage(key, req); err != nil { + cmd.PrintErrln(err) + return + } + + cli, err := getSDKClient(key) + if err != nil { + cmd.PrintErrln(err) + return + } + + resp, err := control.NetmapSnapshot(cli.Raw(), req) + if err != nil { + cmd.PrintErrln(err) + return + } + + sign := resp.GetSignature() + + if err := signature.VerifyDataWithSource(resp, func() ([]byte, []byte) { + return sign.GetKey(), sign.GetSign() + }); err != nil { + cmd.PrintErrln(err) + return + } + + prettyPrintNetmap(cmd, resp.GetBody().GetNetmap(), netmapSnapshotJSON) + }, +} diff --git a/cmd/neofs-cli/modules/netmap.go b/cmd/neofs-cli/modules/netmap.go index a253831163..1ec9d8be50 100644 --- a/cmd/neofs-cli/modules/netmap.go +++ b/cmd/neofs-cli/modules/netmap.go @@ -8,9 +8,7 @@ import ( "github.com/mr-tron/base58" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neofs-api-go/pkg/netmap" - "github.com/nspcc-dev/neofs-api-go/util/signature" "github.com/nspcc-dev/neofs-node/pkg/services/control" - controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server" "github.com/spf13/cobra" ) @@ -33,14 +31,10 @@ func init() { netmapCmd.AddCommand( getEpochCmd, localNodeInfoCmd, - snapshotCmd, netInfoCmd, ) localNodeInfoCmd.Flags().BoolVar(&nodeInfoJSON, "json", false, "print node info in JSON format") - - snapshotCmd.Flags().BoolVar(&netmapSnapshotJSON, "json", false, - "print netmap structure in JSON format") } var getEpochCmd = &cobra.Command{ @@ -97,50 +91,6 @@ var localNodeInfoCmd = &cobra.Command{ }, } -var snapshotCmd = &cobra.Command{ - Use: "snapshot", - Short: "Get network map snapshot", - Long: "Get network map snapshot", - Run: func(cmd *cobra.Command, args []string) { - key, err := getKey() - if err != nil { - cmd.PrintErrln(err) - return - } - - req := new(control.NetmapSnapshotRequest) - req.SetBody(new(control.NetmapSnapshotRequest_Body)) - - if err := controlSvc.SignMessage(key, req); err != nil { - cmd.PrintErrln(err) - return - } - - cli, err := getSDKClient(key) - if err != nil { - cmd.PrintErrln(err) - return - } - - resp, err := control.NetmapSnapshot(cli.Raw(), req) - if err != nil { - cmd.PrintErrln(err) - return - } - - sign := resp.GetSignature() - - if err := signature.VerifyDataWithSource(resp, func() ([]byte, []byte) { - return sign.GetKey(), sign.GetSign() - }); err != nil { - cmd.PrintErrln(err) - return - } - - prettyPrintNetmap(cmd, resp.GetBody().GetNetmap(), netmapSnapshotJSON) - }, -} - var netInfoCmd = &cobra.Command{ Use: "netinfo", Short: "Get information about NeoFS network",