Skip to content

Commit

Permalink
cli/control: Do not use API client from NeoFS SDK (#3078)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Jan 9, 2025
2 parents afc687d + 2af1a62 commit b9c6492
Show file tree
Hide file tree
Showing 23 changed files with 212 additions and 843 deletions.
7 changes: 1 addition & 6 deletions cmd/neofs-cli/modules/control/drop_objects.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,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/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
"github.com/nspcc-dev/neofs-node/pkg/services/control"
Expand Down Expand Up @@ -47,11 +46,7 @@ var dropObjectsCmd = &cobra.Command{
return err
}

var resp *control.DropObjectsResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = control.DropObjects(client, req)
return err
})
resp, err := cli.DropObjects(ctx, req)
if err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/neofs-cli/modules/control/evacuate_shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package control
import (
"fmt"

"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"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"
Expand Down Expand Up @@ -44,11 +43,7 @@ func evacuateShard(cmd *cobra.Command, _ []string) error {
return err
}

var resp *control.EvacuateShardResponse
err = cli.ExecRaw(func(client *client.Client) error {
resp, err = control.EvacuateShard(client, req)
return err
})
resp, err := cli.EvacuateShard(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/neofs-cli/modules/control/flush_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package control
import (
"fmt"

"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"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"
Expand Down Expand Up @@ -43,11 +42,7 @@ func flushCache(cmd *cobra.Command, _ []string) error {
return err
}

var resp *control.FlushCacheResponse
err = cli.ExecRaw(func(client *client.Client) error {
resp, err = control.FlushCache(client, req)
return err
})
resp, err := cli.FlushCache(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
21 changes: 6 additions & 15 deletions cmd/neofs-cli/modules/control/healthcheck.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package control

import (
"context"
"crypto/ecdsa"
"fmt"
"os"

rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"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"
ircontrolsrv "github.com/nspcc-dev/neofs-node/pkg/services/control/ir/server"
"github.com/nspcc-dev/neofs-sdk-go/client"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -43,13 +42,13 @@ func healthCheck(cmd *cobra.Command, _ []string) error {
return err
}

cli, err := getClient(ctx)
conn, err := connect(ctx)
if err != nil {
return err
}

if isIR, _ := cmd.Flags().GetBool(healthcheckIRFlag); isIR {
return healthCheckIR(cmd, pk, cli)
return healthCheckIR(ctx, cmd, pk, ircontrol.NewControlServiceClient(conn))
}

req := new(control.HealthCheckRequest)
Expand All @@ -60,11 +59,7 @@ func healthCheck(cmd *cobra.Command, _ []string) error {
return err
}

var resp *control.HealthCheckResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = control.HealthCheck(client, req)
return err
})
resp, err := control.NewControlServiceClient(conn).HealthCheck(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand All @@ -85,7 +80,7 @@ func healthCheck(cmd *cobra.Command, _ []string) error {
return nil
}

func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c *client.Client) error {
func healthCheckIR(ctx context.Context, cmd *cobra.Command, key *ecdsa.PrivateKey, c ircontrol.ControlServiceClient) error {
req := new(ircontrol.HealthCheckRequest)

req.SetBody(new(ircontrol.HealthCheckRequest_Body))
Expand All @@ -95,11 +90,7 @@ func healthCheckIR(cmd *cobra.Command, key *ecdsa.PrivateKey, c *client.Client)
return fmt.Errorf("could not sign request: %w", err)
}

var resp *ircontrol.HealthCheckResponse
err = c.ExecRaw(func(client *rawclient.Client) error {
resp, err = ircontrol.HealthCheck(client, req)
return err
})
resp, err := c.HealthCheck(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
9 changes: 2 additions & 7 deletions cmd/neofs-cli/modules/control/notary_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/nspcc-dev/neo-go/pkg/util"
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
Expand Down Expand Up @@ -33,7 +32,7 @@ func listNotary(cmd *cobra.Command, _ []string) error {
return err
}

cli, err := getClient(ctx)
cli, err := getIRClient(ctx)
if err != nil {
return err
}
Expand All @@ -47,11 +46,7 @@ func listNotary(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("could not sign request: %w", err)
}

var resp *ircontrol.NotaryListResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = ircontrol.NotaryList(client, req)
return err
})
resp, err := cli.NotaryList(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
9 changes: 2 additions & 7 deletions cmd/neofs-cli/modules/control/notary_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/util"
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
Expand Down Expand Up @@ -42,7 +41,7 @@ func notaryRequest(cmd *cobra.Command, args []string) error {
return err
}

cli, err := getClient(ctx)
cli, err := getIRClient(ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -87,11 +86,7 @@ func notaryRequest(cmd *cobra.Command, args []string) error {
return fmt.Errorf("could not sign request: %w", err)
}

var resp *ircontrol.NotaryRequestResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = ircontrol.NotaryRequest(client, req)
return err
})
resp, err := cli.NotaryRequest(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
9 changes: 2 additions & 7 deletions cmd/neofs-cli/modules/control/notary_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/nspcc-dev/neo-go/pkg/util"
rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/commonflags"
"github.com/nspcc-dev/neofs-node/cmd/neofs-cli/internal/key"
ircontrol "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
Expand Down Expand Up @@ -38,7 +37,7 @@ func notarySign(cmd *cobra.Command, _ []string) error {
return err
}

cli, err := getClient(ctx)
cli, err := getIRClient(ctx)
if err != nil {
return err
}
Expand All @@ -57,11 +56,7 @@ func notarySign(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("could not sign request: %w", err)
}

var resp *ircontrol.NotarySignResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = ircontrol.NotarySign(client, req)
return err
})
resp, err := cli.NotarySign(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
36 changes: 21 additions & 15 deletions cmd/neofs-cli/modules/control/object_list.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package control

import (
"errors"
"fmt"
"io"

rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"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"
Expand Down Expand Up @@ -44,22 +45,27 @@ func listObjects(cmd *cobra.Command, _ []string) error {
return err
}

err = cli.ExecRaw(func(client *rawclient.Client) error {
return control.ListObjects(client, req, func(r *control.ListObjectsResponse) error {
err := verifyResponse(r.GetSignature(), r.GetBody())
if err != nil {
return err
}

for _, address := range r.GetBody().GetObjectAddress() {
cmd.Println(string(address))
}
return nil
})
})
stream, err := cli.ListObjects(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}

return nil
for {
resp, err := stream.Recv()
if err != nil {
if errors.Is(err, io.EOF) {
return nil
}
return fmt.Errorf("rpc error: %w", err)
}

body := resp.GetBody()
if err := verifyResponse(resp.GetSignature(), body); err != nil {
return err
}

for _, address := range body.GetObjectAddress() {
cmd.Println(string(address))
}
}
}
7 changes: 1 addition & 6 deletions cmd/neofs-cli/modules/control/object_revive.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package control
import (
"fmt"

rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"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"
Expand Down Expand Up @@ -38,7 +37,6 @@ func reviveObject(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("reading %s flag: %w", objectFlag, err)
}

var resp *control.ReviveObjectResponse
req := &control.ReviveObjectRequest{
Body: &control.ReviveObjectRequest_Body{
ObjectAddress: []byte(addressRaw),
Expand All @@ -54,10 +52,7 @@ func reviveObject(cmd *cobra.Command, _ []string) error {
return err
}

err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = control.ReviveObject(client, req)
return err
})
resp, err := cli.ReviveObject(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/neofs-cli/modules/control/object_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package control
import (
"fmt"

rawclient "github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"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"
Expand Down Expand Up @@ -38,7 +37,6 @@ func objectStatus(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("validating address (%s): %w", addressRaw, err)
}

var resp *control.ObjectStatusResponse
req := &control.ObjectStatusRequest{
Body: &control.ObjectStatusRequest_Body{
ObjectAddress: addressRaw,
Expand All @@ -54,10 +52,7 @@ func objectStatus(cmd *cobra.Command, _ []string) error {
return err
}

err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = control.ObjectStatus(client, req)
return err
})
resp, err := cli.ObjectStatus(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/neofs-cli/modules/control/set_netmap_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package control
import (
"fmt"

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"
Expand Down Expand Up @@ -93,11 +92,7 @@ func setNetmapStatus(cmd *cobra.Command, _ []string) error {
return err
}

var resp *control.SetNetmapStatusResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = control.SetNetmapStatus(client, req)
return err
})
resp, err := cli.SetNetmapStatus(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
11 changes: 4 additions & 7 deletions cmd/neofs-cli/modules/control/shards_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package control
import (
"fmt"

"github.com/nspcc-dev/neofs-api-go/v2/rpc/client"
"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"
Expand Down Expand Up @@ -58,16 +57,14 @@ func dumpShard(cmd *cobra.Command, _ []string) error {
return err
}

var resp *control.DumpShardResponse
err = cli.ExecRaw(func(client *client.Client) error {
resp, err = control.DumpShard(client, req)
return err
})
resp, err := cli.DumpShard(ctx, req)
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}

err = verifyResponse(resp.GetSignature(), resp.GetBody())
if err = verifyResponse(resp.GetSignature(), resp.GetBody()); err != nil {
return err
}

cmd.Println("Shard has been dumped successfully.")
return nil
Expand Down
Loading

0 comments on commit b9c6492

Please sign in to comment.