[#1917] neofs-cli: Support timeout in control commands

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-10-17 18:37:15 +03:00 committed by fyrchik
parent 4c63be6629
commit 0a1530afa0
13 changed files with 22 additions and 34 deletions

View file

@ -4,6 +4,8 @@ Changelog for NeoFS Node
## [Unreleased]
### Added
- `--timeout` flag in `neofs-cli control` commands (#1917)
### Changed
### Fixed
### Removed

View file

@ -3,7 +3,6 @@ package control
import (
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
"github.com/spf13/cobra"
@ -50,11 +49,9 @@ var dropObjectsCmd = &cobra.Command{
}
func initControlDropObjectsCmd() {
commonflags.InitWithoutRPC(dropObjectsCmd)
initControlFlags(dropObjectsCmd)
flags := dropObjectsCmd.Flags()
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
flags.StringSliceP(dropObjectsFlag, "o", nil,
"List of object addresses to be removed in string format")

View file

@ -3,7 +3,6 @@ package control
import (
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
"github.com/spf13/cobra"
@ -43,10 +42,9 @@ func evacuateShard(cmd *cobra.Command, _ []string) {
}
func initControlEvacuateShardCmd() {
commonflags.InitWithoutRPC(evacuateShardCmd)
initControlFlags(evacuateShardCmd)
flags := evacuateShardCmd.Flags()
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
flags.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding")
flags.Bool(shardAllFlag, false, "Process all shards")
flags.Bool(dumpIgnoreErrorsFlag, false, "Skip invalid/unreadable objects")

View file

@ -3,7 +3,6 @@ package control
import (
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
"github.com/spf13/cobra"
@ -40,10 +39,9 @@ func flushCache(cmd *cobra.Command, _ []string) {
}
func initControlFlushCacheCmd() {
commonflags.InitWithoutRPC(flushCacheCmd)
initControlFlags(flushCacheCmd)
ff := flushCacheCmd.Flags()
ff.String(controlRPC, controlRPCDefault, controlRPCUsage)
ff.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding")
ff.Bool(shardAllFlag, false, "Process all shards")

View file

@ -5,7 +5,6 @@ import (
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
@ -26,11 +25,9 @@ var healthCheckCmd = &cobra.Command{
}
func initControlHealthCheckCmd() {
commonflags.InitWithoutRPC(healthCheckCmd)
initControlFlags(healthCheckCmd)
flags := healthCheckCmd.Flags()
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
flags.Bool(healthcheckIRFlag, false, "Communicate with IR node")
}

View file

@ -16,6 +16,7 @@ var Cmd = &cobra.Command{
_ = viper.BindPFlag(commonflags.WalletPath, ff.Lookup(commonflags.WalletPath))
_ = viper.BindPFlag(commonflags.Account, ff.Lookup(commonflags.Account))
_ = viper.BindPFlag(controlRPC, ff.Lookup(controlRPC))
_ = viper.BindPFlag(commonflags.Timeout, ff.Lookup(commonflags.Timeout))
},
}

View file

@ -5,7 +5,6 @@ import (
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
"github.com/spf13/cobra"
@ -27,11 +26,9 @@ var setNetmapStatusCmd = &cobra.Command{
}
func initControlSetNetmapStatusCmd() {
commonflags.InitWithoutRPC(setNetmapStatusCmd)
initControlFlags(setNetmapStatusCmd)
flags := setNetmapStatusCmd.Flags()
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
flags.String(netmapStatusFlag, "",
fmt.Sprintf("New netmap status keyword ('%s', '%s', '%s')",
netmapStatusOnline,

View file

@ -3,7 +3,6 @@ package control
import (
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
"github.com/spf13/cobra"
@ -54,10 +53,9 @@ func dumpShard(cmd *cobra.Command, _ []string) {
}
func initControlDumpShardCmd() {
commonflags.InitWithoutRPC(dumpShardCmd)
initControlFlags(dumpShardCmd)
flags := dumpShardCmd.Flags()
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
flags.String(shardIDFlag, "", "Shard ID in base58 encoding")
flags.String(dumpFilepathFlag, "", "File to write objects to")
flags.Bool(dumpIgnoreErrorsFlag, false, "Skip invalid/unreadable objects")

View file

@ -23,11 +23,9 @@ var listShardsCmd = &cobra.Command{
}
func initControlShardsListCmd() {
commonflags.InitWithoutRPC(listShardsCmd)
initControlFlags(listShardsCmd)
flags := listShardsCmd.Flags()
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
flags.Bool(commonflags.JSON, false, "Print shard info as a JSON array")
}

View file

@ -3,7 +3,6 @@ package control
import (
"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
"github.com/spf13/cobra"
@ -54,10 +53,9 @@ func restoreShard(cmd *cobra.Command, _ []string) {
}
func initControlRestoreShardCmd() {
commonflags.InitWithoutRPC(restoreShardCmd)
initControlFlags(restoreShardCmd)
flags := restoreShardCmd.Flags()
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
flags.String(shardIDFlag, "", "Shard ID in base58 encoding")
flags.String(restoreFilepathFlag, "", "File to read objects from")
flags.Bool(restoreIgnoreErrorsFlag, false, "Skip invalid/unreadable objects")

View file

@ -6,7 +6,6 @@ import (
"github.com/mr-tron/base58"
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
"github.com/spf13/cobra"
@ -32,11 +31,9 @@ var setShardModeCmd = &cobra.Command{
}
func initControlSetShardModeCmd() {
commonflags.InitWithoutRPC(setShardModeCmd)
initControlFlags(setShardModeCmd)
flags := setShardModeCmd.Flags()
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
flags.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding")
flags.Bool(shardAllFlag, false, "Process all shards")
flags.String(shardModeFlag, "",

View file

@ -6,7 +6,6 @@ import (
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server"
@ -27,10 +26,9 @@ var synchronizeTreeCmd = &cobra.Command{
}
func initControlSynchronizeTreeCmd() {
commonflags.InitWithoutRPC(synchronizeTreeCmd)
initControlFlags(synchronizeTreeCmd)
flags := synchronizeTreeCmd.Flags()
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
flags.String("cid", "", "Container ID")
flags.String(synchronizeTreeIDFlag, "", "Tree ID")
flags.Uint64(synchronizeTreeHeightFlag, 0, "Starting height")

View file

@ -7,12 +7,21 @@ import (
"github.com/nspcc-dev/neofs-api-go/v2/refs"
internalclient "github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server"
"github.com/nspcc-dev/neofs-sdk-go/client"
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
"github.com/spf13/cobra"
)
func initControlFlags(cmd *cobra.Command) {
commonflags.InitWithoutRPC(cmd)
ff := cmd.Flags()
ff.String(controlRPC, controlRPCDefault, controlRPCUsage)
ff.DurationP(commonflags.Timeout, commonflags.TimeoutShorthand, commonflags.TimeoutDefault, commonflags.TimeoutUsage)
}
func signRequest(cmd *cobra.Command, pk *ecdsa.PrivateKey, req controlSvc.SignedMessage) {
err := controlSvc.SignMessage(pk, req)
common.ExitOnErr(cmd, "could not sign request: %w", err)