[#920] cli: Rename RPC flag for control service
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
f0252e00c1
commit
0866c1fb90
3 changed files with 71 additions and 16 deletions
|
@ -8,8 +8,11 @@ Deleted `NEOFS_IR_NOTARY_SIDE_DEPOSIT_AMOUNT`, `NEOFS_IR_NOTARY_MAIN_DEPOSIT_AMO
|
||||||
and `NEOFS_IR_TIMERS_SIDE_NOTARY`, `NEOFS_IR_TIMERS_MAIN_NOTARY` Inner Ring envs.
|
and `NEOFS_IR_TIMERS_SIDE_NOTARY`, `NEOFS_IR_TIMERS_MAIN_NOTARY` Inner Ring envs.
|
||||||
Deleted `NEOFS_MORPH_NOTARY_DEPOSIT_AMOUNT` and `NEOFS_MORPH_NOTARY_DEPOSIT_DURATION`
|
Deleted `NEOFS_MORPH_NOTARY_DEPOSIT_AMOUNT` and `NEOFS_MORPH_NOTARY_DEPOSIT_DURATION`
|
||||||
Storage Node envs.
|
Storage Node envs.
|
||||||
|
`control` CLI command does not have `--rpc-endpoint`/`r` flag, use `endpoint`
|
||||||
|
instead.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
- Renamed `--rpc-endpoint` CLI flag for `control command` (#879)
|
||||||
- Do not use global flags in CLI; delete useless flags from `accounting balance`
|
- Do not use global flags in CLI; delete useless flags from `accounting balance`
|
||||||
command (#810)
|
command (#810)
|
||||||
- SN and IR notary deposits are made dynamically depending on the Notary and
|
- SN and IR notary deposits are made dynamically depending on the Notary and
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
"github.com/nspcc-dev/neofs-api-go/pkg/client"
|
||||||
|
@ -12,6 +13,7 @@ import (
|
||||||
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server"
|
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server"
|
||||||
controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server"
|
controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var controlCmd = &cobra.Command{
|
var controlCmd = &cobra.Command{
|
||||||
|
@ -19,7 +21,15 @@ var controlCmd = &cobra.Command{
|
||||||
Short: "Operations with storage node",
|
Short: "Operations with storage node",
|
||||||
Long: `Operations with storage node`,
|
Long: `Operations with storage node`,
|
||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||||
bindCommonFlags(cmd)
|
ff := cmd.Flags()
|
||||||
|
|
||||||
|
_ = viper.BindPFlag(generateKey, ff.Lookup(generateKey))
|
||||||
|
_ = viper.BindPFlag(binaryKey, ff.Lookup(binaryKey))
|
||||||
|
_ = viper.BindPFlag(walletPath, ff.Lookup(walletPath))
|
||||||
|
_ = viper.BindPFlag(wif, ff.Lookup(wif))
|
||||||
|
_ = viper.BindPFlag(address, ff.Lookup(address))
|
||||||
|
_ = viper.BindPFlag(controlRPC, ff.Lookup(controlRPC))
|
||||||
|
_ = viper.BindPFlag(verbose, ff.Lookup(verbose))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +54,12 @@ const (
|
||||||
netmapStatusOffline = "offline"
|
netmapStatusOffline = "offline"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
controlRPC = "endpoint"
|
||||||
|
controlRPCDefault = ""
|
||||||
|
controlRPCUsage = "remote node control address (as 'multiaddr' or '<host>:<port>')"
|
||||||
|
)
|
||||||
|
|
||||||
// control healthcheck flags
|
// control healthcheck flags
|
||||||
const (
|
const (
|
||||||
healthcheckIRFlag = "ir"
|
healthcheckIRFlag = "ir"
|
||||||
|
@ -57,15 +73,21 @@ var (
|
||||||
var netmapStatus string
|
var netmapStatus string
|
||||||
|
|
||||||
func initControlHealthCheckCmd() {
|
func initControlHealthCheckCmd() {
|
||||||
initCommonFlags(healthCheckCmd)
|
initCommonFlagsWithoutRPC(healthCheckCmd)
|
||||||
|
|
||||||
healthCheckCmd.Flags().BoolVar(&healthCheckIRVar, healthcheckIRFlag, false, "Communicate with IR node")
|
flags := healthCheckCmd.Flags()
|
||||||
|
|
||||||
|
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
||||||
|
flags.BoolVar(&healthCheckIRVar, healthcheckIRFlag, false, "Communicate with IR node")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initControlSetNetmapStatusCmd() {
|
func initControlSetNetmapStatusCmd() {
|
||||||
initCommonFlags(setNetmapStatusCmd)
|
initCommonFlagsWithoutRPC(setNetmapStatusCmd)
|
||||||
|
|
||||||
setNetmapStatusCmd.Flags().StringVarP(&netmapStatus, netmapStatusFlag, "", "",
|
flags := setNetmapStatusCmd.Flags()
|
||||||
|
|
||||||
|
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
||||||
|
flags.StringVarP(&netmapStatus, netmapStatusFlag, "", "",
|
||||||
fmt.Sprintf("new netmap status keyword ('%s', '%s')",
|
fmt.Sprintf("new netmap status keyword ('%s', '%s')",
|
||||||
netmapStatusOnline,
|
netmapStatusOnline,
|
||||||
netmapStatusOffline,
|
netmapStatusOffline,
|
||||||
|
@ -76,18 +98,23 @@ func initControlSetNetmapStatusCmd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initControlDropObjectsCmd() {
|
func initControlDropObjectsCmd() {
|
||||||
initCommonFlags(dropObjectsCmd)
|
initCommonFlagsWithoutRPC(dropObjectsCmd)
|
||||||
|
|
||||||
dropObjectsCmd.Flags().StringSliceVarP(&dropObjectsList, dropObjectsFlag, "o", nil,
|
flags := dropObjectsCmd.Flags()
|
||||||
|
|
||||||
|
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
||||||
|
flags.StringSliceVarP(&dropObjectsList, dropObjectsFlag, "o", nil,
|
||||||
"List of object addresses to be removed in string format")
|
"List of object addresses to be removed in string format")
|
||||||
|
|
||||||
_ = dropObjectsCmd.MarkFlagRequired(dropObjectsFlag)
|
_ = dropObjectsCmd.MarkFlagRequired(dropObjectsFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initControlSnapshotCmd() {
|
func initControlSnapshotCmd() {
|
||||||
initCommonFlags(snapshotCmd)
|
initCommonFlagsWithoutRPC(snapshotCmd)
|
||||||
|
|
||||||
snapshotCmd.Flags().BoolVar(&netmapSnapshotJSON, "json", false,
|
flags := snapshotCmd.Flags()
|
||||||
|
|
||||||
|
flags.BoolVar(&netmapSnapshotJSON, "json", false,
|
||||||
"print netmap structure in JSON format")
|
"print netmap structure in JSON format")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +138,7 @@ func healthCheck(cmd *cobra.Command, _ []string) {
|
||||||
key, err := getKey()
|
key, err := getKey()
|
||||||
exitOnErr(cmd, err)
|
exitOnErr(cmd, err)
|
||||||
|
|
||||||
cli, err := getSDKClient(key)
|
cli, err := getControlSDKClient(key)
|
||||||
exitOnErr(cmd, err)
|
exitOnErr(cmd, err)
|
||||||
|
|
||||||
if healthCheckIRVar {
|
if healthCheckIRVar {
|
||||||
|
@ -192,7 +219,7 @@ func setNetmapStatus(cmd *cobra.Command, _ []string) {
|
||||||
err = controlSvc.SignMessage(key, req)
|
err = controlSvc.SignMessage(key, req)
|
||||||
exitOnErr(cmd, errf("could not sign request: %w", err))
|
exitOnErr(cmd, errf("could not sign request: %w", err))
|
||||||
|
|
||||||
cli, err := getSDKClient(key)
|
cli, err := getControlSDKClient(key)
|
||||||
exitOnErr(cmd, err)
|
exitOnErr(cmd, err)
|
||||||
|
|
||||||
resp, err := control.SetNetmapStatus(cli.Raw(), req)
|
resp, err := control.SetNetmapStatus(cli.Raw(), req)
|
||||||
|
@ -249,7 +276,7 @@ var dropObjectsCmd = &cobra.Command{
|
||||||
err = controlSvc.SignMessage(key, req)
|
err = controlSvc.SignMessage(key, req)
|
||||||
exitOnErr(cmd, errf("could not sign request: %w", err))
|
exitOnErr(cmd, errf("could not sign request: %w", err))
|
||||||
|
|
||||||
cli, err := getSDKClient(key)
|
cli, err := getControlSDKClient(key)
|
||||||
exitOnErr(cmd, err)
|
exitOnErr(cmd, err)
|
||||||
|
|
||||||
resp, err := control.DropObjects(cli.Raw(), req)
|
resp, err := control.DropObjects(cli.Raw(), req)
|
||||||
|
@ -283,7 +310,7 @@ var snapshotCmd = &cobra.Command{
|
||||||
err = controlSvc.SignMessage(key, req)
|
err = controlSvc.SignMessage(key, req)
|
||||||
exitOnErr(cmd, errf("could not sign request: %w", err))
|
exitOnErr(cmd, errf("could not sign request: %w", err))
|
||||||
|
|
||||||
cli, err := getSDKClient(key)
|
cli, err := getControlSDKClient(key)
|
||||||
exitOnErr(cmd, err)
|
exitOnErr(cmd, err)
|
||||||
|
|
||||||
resp, err := control.NetmapSnapshot(cli.Raw(), req)
|
resp, err := control.NetmapSnapshot(cli.Raw(), req)
|
||||||
|
@ -302,3 +329,28 @@ var snapshotCmd = &cobra.Command{
|
||||||
prettyPrintNetmap(cmd, resp.GetBody().GetNetmap(), netmapSnapshotJSON)
|
prettyPrintNetmap(cmd, resp.GetBody().GetNetmap(), netmapSnapshotJSON)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getControlSDKClient is the same getSDKClient but with
|
||||||
|
// another RPC endpoint flag.
|
||||||
|
func getControlSDKClient(key *ecdsa.PrivateKey) (client.Client, error) {
|
||||||
|
netAddr, err := getEndpointAddress(controlRPC)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
options := []client.Option{
|
||||||
|
client.WithAddress(netAddr.HostAddr()),
|
||||||
|
client.WithDefaultPrivateKey(key),
|
||||||
|
}
|
||||||
|
|
||||||
|
if netAddr.TLSEnabled() {
|
||||||
|
options = append(options, client.WithTLSConfig(&tls.Config{}))
|
||||||
|
}
|
||||||
|
|
||||||
|
c, err := client.New(options...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("coult not init api client:%w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, err
|
||||||
|
}
|
||||||
|
|
|
@ -276,8 +276,8 @@ func getKeyFromWallet(w *wallet.Wallet, addrStr string) (*ecdsa.PrivateKey, erro
|
||||||
|
|
||||||
// getEndpointAddress returns network address structure that stores multiaddr
|
// getEndpointAddress returns network address structure that stores multiaddr
|
||||||
// inside, parsed from global arguments.
|
// inside, parsed from global arguments.
|
||||||
func getEndpointAddress() (addr network.Address, err error) {
|
func getEndpointAddress(endpointFlag string) (addr network.Address, err error) {
|
||||||
endpoint := viper.GetString(rpc)
|
endpoint := viper.GetString(endpointFlag)
|
||||||
|
|
||||||
err = addr.FromString(endpoint)
|
err = addr.FromString(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -290,7 +290,7 @@ func getEndpointAddress() (addr network.Address, err error) {
|
||||||
// getSDKClient returns default neofs-api-go sdk client. Consider using
|
// getSDKClient returns default neofs-api-go sdk client. Consider using
|
||||||
// opts... to provide TTL or other global configuration flags.
|
// opts... to provide TTL or other global configuration flags.
|
||||||
func getSDKClient(key *ecdsa.PrivateKey) (client.Client, error) {
|
func getSDKClient(key *ecdsa.PrivateKey) (client.Client, error) {
|
||||||
netAddr, err := getEndpointAddress()
|
netAddr, err := getEndpointAddress(rpc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue