From 7cead1bc3aedbf3d4732417a53429e0146da6162 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 15 Jun 2021 10:54:09 +0300 Subject: [PATCH] [#414] cmd/cli: Support IR health-check Add `--ir` flag to `control healthcheck` to communicate with IR node. Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/control.go | 59 +++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/cmd/neofs-cli/modules/control.go b/cmd/neofs-cli/modules/control.go index 53907c54..a8ab229b 100644 --- a/cmd/neofs-cli/modules/control.go +++ b/cmd/neofs-cli/modules/control.go @@ -1,11 +1,15 @@ package cmd import ( + "crypto/ecdsa" "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/util/signature" "github.com/nspcc-dev/neofs-node/pkg/services/control" + ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir" + ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server" controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server" "github.com/spf13/cobra" ) @@ -37,6 +41,16 @@ const ( netmapStatusOffline = "offline" ) +// control healthcheck flags +const ( + healthcheckIRFlag = "ir" +) + +// control healthcheck vars +var ( + healthCheckIRVar bool +) + var netmapStatus string func init() { @@ -61,6 +75,8 @@ func init() { "List of object addresses to be removed in string format") _ = dropObjectsCmd.MarkFlagRequired(dropObjectsFlag) + + healthCheckCmd.Flags().BoolVar(&healthCheckIRVar, healthcheckIRFlag, false, "Communicate with IR node") } func healthCheck(cmd *cobra.Command, _ []string) error { @@ -69,6 +85,16 @@ func healthCheck(cmd *cobra.Command, _ []string) error { return err } + cli, err := getSDKClient(key) + if err != nil { + return err + } + + if healthCheckIRVar { + healthCheckIR(cmd, key, cli) + return nil + } + req := new(control.HealthCheckRequest) req.SetBody(new(control.HealthCheckRequest_Body)) @@ -77,11 +103,6 @@ func healthCheck(cmd *cobra.Command, _ []string) error { return err } - cli, err := getSDKClient(key) - if err != nil { - return err - } - resp, err := control.HealthCheck(cli.Raw(), req) if err != nil { return err @@ -101,6 +122,34 @@ func healthCheck(cmd *cobra.Command, _ []string) error { return nil } +func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c client.Client) { + req := new(ircontrol.HealthCheckRequest) + + req.SetBody(new(ircontrol.HealthCheckRequest_Body)) + + if err := ircontrolsrv.SignMessage(key, req); err != nil { + cmd.PrintErrln(fmt.Errorf("could not sign request: %w", err)) + return + } + + resp, err := ircontrol.HealthCheck(c.Raw(), req) + if err != nil { + cmd.PrintErrln(fmt.Errorf("rpc failure: %w", err)) + return + } + + sign := resp.GetSignature() + + if err := signature.VerifyDataWithSource(resp, func() ([]byte, []byte) { + return sign.GetKey(), sign.GetSign() + }); err != nil { + cmd.PrintErrln(fmt.Errorf("invalid response signature: %w", err)) + return + } + + cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus()) +} + func setNetmapStatus(cmd *cobra.Command, _ []string) error { key, err := getKey() if err != nil {