[#425] cli: Support latest changes from API library

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-03-15 14:23:04 +03:00 committed by Alex Vanin
parent e6cde0ab28
commit 6204ca8308
5 changed files with 43 additions and 50 deletions

View file

@ -39,18 +39,26 @@ var accountingBalanceCmd = &cobra.Command{
return err
}
switch balanceOwner {
case "":
response, err = cli.GetSelfBalance(ctx, globalCallOptions()...)
default:
oid, err = ownerFromString(balanceOwner)
if balanceOwner == "" {
key, err := getKey()
if err != nil {
return err
}
response, err = cli.GetBalance(ctx, oid, globalCallOptions()...)
wallet, err := owner.NEO3WalletFromPublicKey(&key.PublicKey)
if err != nil {
return err
}
oid = owner.NewIDFromNeo3Wallet(wallet)
} else {
oid, err = ownerFromString(balanceOwner)
if err != nil {
return err
}
}
response, err = cli.GetBalance(ctx, oid, globalCallOptions()...)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}

View file

@ -78,18 +78,26 @@ var listContainersCmd = &cobra.Command{
return err
}
switch containerOwner {
case "":
response, err = cli.ListSelfContainers(ctx, globalCallOptions()...)
default:
oid, err = ownerFromString(containerOwner)
if containerOwner == "" {
key, err := getKey()
if err != nil {
return err
}
response, err = cli.ListContainers(ctx, oid, globalCallOptions()...)
wallet, err := owner.NEO3WalletFromPublicKey(&key.PublicKey)
if err != nil {
return err
}
oid = owner.NewIDFromNeo3Wallet(wallet)
} else {
oid, err = ownerFromString(containerOwner)
if err != nil {
return err
}
}
response, err = cli.ListContainers(ctx, oid, globalCallOptions()...)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
@ -343,7 +351,7 @@ var getExtendedACLCmd = &cobra.Command{
return err
}
res, err := cli.GetEACLWithSignature(ctx, id, globalCallOptions()...)
res, err := cli.GetEACL(ctx, id, globalCallOptions()...)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
@ -425,10 +433,10 @@ Container ID in EACL table will be substituted with ID from the CLI.`,
for i := 0; i < awaitTimeout; i++ {
time.Sleep(1 * time.Second)
table, err := cli.GetEACL(ctx, id, globalCallOptions()...)
tableSig, err := cli.GetEACL(ctx, id, globalCallOptions()...)
if err == nil {
// compare binary values because EACL could have been set already
got, err := table.Marshal()
got, err := tableSig.EACL().Marshal()
if err != nil {
continue
}

View file

@ -1,12 +1,10 @@
package cmd
import (
"context"
"fmt"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-api-go/util/signature"
"github.com/nspcc-dev/neofs-api-go/v2/client"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
controlSvc "github.com/nspcc-dev/neofs-node/pkg/services/control/server"
"github.com/pkg/errors"
@ -66,27 +64,6 @@ func init() {
_ = dropObjectsCmd.MarkFlagRequired(dropObjectsFlag)
}
func getControlServiceClient() (control.ControlServiceClient, error) {
netAddr, err := getEndpointAddress()
if err != nil {
return nil, err
}
ipAddr, err := netAddr.IPAddrString()
if err != nil {
return nil, errInvalidEndpoint
}
con, err := client.NewGRPCClientConn(
client.WithNetworkAddress(ipAddr),
)
if err != nil {
return nil, err
}
return control.NewControlServiceClient(con), nil
}
func healthCheck(cmd *cobra.Command, _ []string) error {
key, err := getKey()
if err != nil {
@ -101,12 +78,12 @@ func healthCheck(cmd *cobra.Command, _ []string) error {
return err
}
cli, err := getControlServiceClient()
cli, err := getSDKClient()
if err != nil {
return err
}
resp, err := cli.HealthCheck(context.Background(), req)
resp, err := control.HealthCheck(cli.Raw(), req)
if err != nil {
return err
}
@ -153,12 +130,12 @@ func setNetmapStatus(cmd *cobra.Command, _ []string) error {
return err
}
cli, err := getControlServiceClient()
cli, err := getSDKClient()
if err != nil {
return err
}
resp, err := cli.SetNetmapStatus(context.Background(), req)
resp, err := control.SetNetmapStatus(cli.Raw(), req)
if err != nil {
return err
}
@ -219,12 +196,12 @@ var dropObjectsCmd = &cobra.Command{
return err
}
cli, err := getControlServiceClient()
cli, err := getSDKClient()
if err != nil {
return err
}
resp, err := cli.DropObjects(context.Background(), req)
resp, err := control.DropObjects(cli.Raw(), req)
if err != nil {
return err
}

View file

@ -56,12 +56,12 @@ var getEpochCmd = &cobra.Command{
return err
}
e, err := cli.Epoch(context.Background(), globalCallOptions()...)
netInfo, err := cli.NetworkInfo(context.Background(), globalCallOptions()...)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
fmt.Println(e)
fmt.Println(netInfo.CurrentEpoch())
return nil
},
@ -82,7 +82,7 @@ var localNodeInfoCmd = &cobra.Command{
return fmt.Errorf("rpc error: %w", err)
}
prettyPrintNodeInfo(nodeInfo, nodeInfoJSON)
prettyPrintNodeInfo(nodeInfo.NodeInfo(), nodeInfoJSON)
return nil
},
@ -105,12 +105,12 @@ var snapshotCmd = &cobra.Command{
return err
}
cli, err := getControlServiceClient()
cli, err := getSDKClient()
if err != nil {
return err
}
resp, err := cli.NetmapSnapshot(context.Background(), req)
resp, err := control.NetmapSnapshot(cli.Raw(), req)
if err != nil {
return err
}

View file

@ -177,7 +177,7 @@ func getSDKClient() (*client.Client, error) {
return nil, errInvalidEndpoint
}
return client.New(key, client.WithAddress(ipAddr))
return client.New(client.WithAddress(ipAddr), client.WithDefaultPrivateKey(key))
}
func getTTL() uint32 {