From 6204ca830873910ddfff722a011a3ac0b867f2e2 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 15 Mar 2021 14:23:04 +0300 Subject: [PATCH] [#425] cli: Support latest changes from API library Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/accounting.go | 20 ++++++++++++----- cmd/neofs-cli/modules/container.go | 26 +++++++++++++-------- cmd/neofs-cli/modules/control.go | 35 +++++------------------------ cmd/neofs-cli/modules/netmap.go | 10 ++++----- cmd/neofs-cli/modules/root.go | 2 +- 5 files changed, 43 insertions(+), 50 deletions(-) diff --git a/cmd/neofs-cli/modules/accounting.go b/cmd/neofs-cli/modules/accounting.go index a74b2d65..7a459f89 100644 --- a/cmd/neofs-cli/modules/accounting.go +++ b/cmd/neofs-cli/modules/accounting.go @@ -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) } diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 95cddf75..00b5d301 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -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 } diff --git a/cmd/neofs-cli/modules/control.go b/cmd/neofs-cli/modules/control.go index ddb9b566..ff091ae8 100644 --- a/cmd/neofs-cli/modules/control.go +++ b/cmd/neofs-cli/modules/control.go @@ -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 } diff --git a/cmd/neofs-cli/modules/netmap.go b/cmd/neofs-cli/modules/netmap.go index 36677d9a..74e1e727 100644 --- a/cmd/neofs-cli/modules/netmap.go +++ b/cmd/neofs-cli/modules/netmap.go @@ -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 } diff --git a/cmd/neofs-cli/modules/root.go b/cmd/neofs-cli/modules/root.go index 8c725602..36b91088 100644 --- a/cmd/neofs-cli/modules/root.go +++ b/cmd/neofs-cli/modules/root.go @@ -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 {