Skip to content

Commit

Permalink
cli/control: Do not use API client from NeoFS SDK
Browse files Browse the repository at this point in the history
It makes no sense to create client just get underlying connection from
it. Instead, direct gRPC dial should be used.

This inlines `Client.Dial` to keep previous behavior as much as possible
(some error texts could change only). URI parser is copy-pasted because
it's internalized by the SDK. Even if it'd export it, we are not ready
for the upgrade to the latest yet.

Starting from here, `cmd/neofs-cli` packages (all CLI apps actually) no
longer uses `github.com/nspcc-dev/neofs-api-go/v2` directly which is
good considering the upcoming abandonment of it.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Dec 18, 2024
1 parent 474d541 commit c161779
Show file tree
Hide file tree
Showing 19 changed files with 183 additions and 695 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)

Check warning on line 49 in cmd/neofs-cli/modules/control/drop_objects.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/drop_objects.go#L49

Added line #L49 was not covered by tests
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)

Check warning on line 46 in cmd/neofs-cli/modules/control/evacuate_shard.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/evacuate_shard.go#L46

Added line #L46 was not covered by tests
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)

Check warning on line 45 in cmd/neofs-cli/modules/control/flush_cache.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/flush_cache.go#L45

Added line #L45 was not covered by tests
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)

Check warning on line 45 in cmd/neofs-cli/modules/control/healthcheck.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/healthcheck.go#L45

Added line #L45 was not covered by tests
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))

Check warning on line 51 in cmd/neofs-cli/modules/control/healthcheck.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/healthcheck.go#L51

Added line #L51 was not covered by tests
}

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)

Check warning on line 62 in cmd/neofs-cli/modules/control/healthcheck.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/healthcheck.go#L62

Added line #L62 was not covered by tests
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 {

Check warning on line 83 in cmd/neofs-cli/modules/control/healthcheck.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/healthcheck.go#L83

Added line #L83 was not covered by tests
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)

Check warning on line 93 in cmd/neofs-cli/modules/control/healthcheck.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/healthcheck.go#L93

Added line #L93 was not covered by tests
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)

Check warning on line 48 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L48

Added line #L48 was not covered by tests
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)

Check warning on line 59 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L53-L59

Added lines #L53 - L59 were not covered by tests
}

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

Check warning on line 65 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L62-L65

Added lines #L62 - L65 were not covered by tests

for _, address := range body.GetObjectAddress() {
cmd.Println(string(address))
}

Check warning on line 69 in cmd/neofs-cli/modules/control/object_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_list.go#L67-L69

Added lines #L67 - L69 were not covered by tests
}
}
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)

Check warning on line 55 in cmd/neofs-cli/modules/control/object_revive.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_revive.go#L55

Added line #L55 was not covered by tests
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)

Check warning on line 55 in cmd/neofs-cli/modules/control/object_status.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/object_status.go#L55

Added line #L55 was not covered by tests
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)

Check warning on line 95 in cmd/neofs-cli/modules/control/set_netmap_status.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/set_netmap_status.go#L95

Added line #L95 was not covered by tests
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
7 changes: 1 addition & 6 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,11 +57,7 @@ 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)

Check warning on line 60 in cmd/neofs-cli/modules/control/shards_dump.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/shards_dump.go#L60

Added line #L60 was not covered by tests
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/neofs-cli/modules/control/shards_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"github.com/mr-tron/base58"
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 @@ -51,11 +50,7 @@ func listShards(cmd *cobra.Command, _ []string) error {
return err
}

var resp *control.ListShardsResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = control.ListShards(client, req)
return err
})
resp, err := cli.ListShards(ctx, req)

Check warning on line 53 in cmd/neofs-cli/modules/control/shards_list.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/shards_list.go#L53

Added line #L53 was not covered by tests
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/neofs-cli/modules/control/shards_restore.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,11 +57,7 @@ func restoreShard(cmd *cobra.Command, _ []string) error {
return err
}

var resp *control.RestoreShardResponse
err = cli.ExecRaw(func(client *client.Client) error {
resp, err = control.RestoreShard(client, req)
return err
})
resp, err := cli.RestoreShard(ctx, req)

Check warning on line 60 in cmd/neofs-cli/modules/control/shards_restore.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/shards_restore.go#L60

Added line #L60 was not covered by tests
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/neofs-cli/modules/control/shards_set_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"github.com/mr-tron/base58"
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 @@ -144,11 +143,7 @@ func setShardMode(cmd *cobra.Command, _ []string) error {
return err
}

var resp *control.SetShardModeResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = control.SetShardMode(client, req)
return err
})
resp, err := cli.SetShardMode(ctx, req)

Check warning on line 146 in cmd/neofs-cli/modules/control/shards_set_mode.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/shards_set_mode.go#L146

Added line #L146 was not covered by tests
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
7 changes: 1 addition & 6 deletions cmd/neofs-cli/modules/control/synchronize_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"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 @@ -72,11 +71,7 @@ func synchronizeTree(cmd *cobra.Command, _ []string) error {
return err
}

var resp *control.SynchronizeTreeResponse
err = cli.ExecRaw(func(client *rawclient.Client) error {
resp, err = control.SynchronizeTree(client, req)
return err
})
resp, err := cli.SynchronizeTree(ctx, req)

Check warning on line 74 in cmd/neofs-cli/modules/control/synchronize_tree.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-cli/modules/control/synchronize_tree.go#L74

Added line #L74 was not covered by tests
if err != nil {
return fmt.Errorf("rpc error: %w", err)
}
Expand Down
Loading

0 comments on commit c161779

Please sign in to comment.