[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-06-28 16:28:12 +03:00 committed by Leonard Lyubich
parent 8eadf18e01
commit 61f48a2736
2 changed files with 48 additions and 50 deletions

View file

@ -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)
},
}