[#1826] neofs-cli: Add --timeout flag

Allow to specify it everywhere `--rpc-endpoint` flag is present.

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-10-05 10:39:47 +03:00 committed by fyrchik
parent 0cb8e7f6f1
commit 90bfe0bad9
3 changed files with 19 additions and 0 deletions

View file

@ -14,6 +14,7 @@ Changelog for NeoFS Node
- `flush-cache` control service command to flush write-cache (#1806) - `flush-cache` control service command to flush write-cache (#1806)
- `wallet-address` flag in `neofs-adm morph refill-gas` command (#1820) - `wallet-address` flag in `neofs-adm morph refill-gas` command (#1820)
- Validate policy before container creation (#1704) - Validate policy before container creation (#1704)
- `--timeout` flag in `neofs-cli` subcommands (#1837)
### Changed ### Changed
- Allow to evacuate shard data with `EvacuateShard` control RPC (#1800) - Allow to evacuate shard data with `EvacuateShard` control RPC (#1800)

View file

@ -9,6 +9,7 @@ import (
"fmt" "fmt"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/common" "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/pkg/network" "github.com/nspcc-dev/neofs-node/pkg/network"
"github.com/nspcc-dev/neofs-sdk-go/client" "github.com/nspcc-dev/neofs-sdk-go/client"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -48,6 +49,13 @@ func GetSDKClient(key *ecdsa.PrivateKey, addr network.Address) (*client.Client,
prmInit.SetDefaultPrivateKey(*key) prmInit.SetDefaultPrivateKey(*key)
prmInit.ResolveNeoFSFailures() prmInit.ResolveNeoFSFailures()
prmDial.SetServerURI(addr.URIAddr()) prmDial.SetServerURI(addr.URIAddr())
if timeout := viper.GetDuration(commonflags.Timeout); timeout > 0 {
// In CLI we can only set a timeout for the whole operation.
// By also setting stream timeout we ensure that no operation hands
// for too long.
prmDial.SetTimeout(timeout)
prmDial.SetStreamTimeout(timeout)
}
c.Init(prmInit) c.Init(prmInit)

View file

@ -1,6 +1,8 @@
package commonflags package commonflags
import ( import (
"time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -28,6 +30,11 @@ const (
RPCDefault = "" RPCDefault = ""
RPCUsage = "remote node address (as 'multiaddr' or '<host>:<port>')" RPCUsage = "remote node address (as 'multiaddr' or '<host>:<port>')"
Timeout = "timeout"
TimeoutShorthand = "t"
TimeoutDefault = 15 * time.Second
TimeoutUsage = "timeout for an operation"
Verbose = "verbose" Verbose = "verbose"
VerboseShorthand = "v" VerboseShorthand = "v"
VerboseUsage = "verbose output" VerboseUsage = "verbose output"
@ -41,11 +48,13 @@ const (
// - WalletPath // - WalletPath
// - Account // - Account
// - RPC // - RPC
// - Timeout
func Init(cmd *cobra.Command) { func Init(cmd *cobra.Command) {
InitWithoutRPC(cmd) InitWithoutRPC(cmd)
ff := cmd.Flags() ff := cmd.Flags()
ff.StringP(RPC, RPCShorthand, RPCDefault, RPCUsage) ff.StringP(RPC, RPCShorthand, RPCDefault, RPCUsage)
ff.DurationP(Timeout, TimeoutShorthand, TimeoutDefault, TimeoutUsage)
} }
// InitWithoutRPC is similar to Init but doesn't create the RPC flag. // InitWithoutRPC is similar to Init but doesn't create the RPC flag.
@ -65,4 +74,5 @@ func Bind(cmd *cobra.Command) {
_ = viper.BindPFlag(WalletPath, ff.Lookup(WalletPath)) _ = viper.BindPFlag(WalletPath, ff.Lookup(WalletPath))
_ = viper.BindPFlag(Account, ff.Lookup(Account)) _ = viper.BindPFlag(Account, ff.Lookup(Account))
_ = viper.BindPFlag(RPC, ff.Lookup(RPC)) _ = viper.BindPFlag(RPC, ff.Lookup(RPC))
_ = viper.BindPFlag(Timeout, ff.Lookup(Timeout))
} }