From 61f48a27367adcd8e3fd716a17f2b52c4b1a7593 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 28 Jun 2021 16:28:12 +0300 Subject: [PATCH] [#651] cmd/cli: Replace netmap snapshot from netmap section to control There is a need to have all `Control` service-related commands in `control` section. Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/control.go | 48 ++++++++++++++++++++++++++++++ cmd/neofs-cli/modules/netmap.go | 50 -------------------------------- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/cmd/neofs-cli/modules/control.go b/cmd/neofs-cli/modules/control.go index 9aed2839b..692c275ab 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 a25383116..1ec9d8be5 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",