Skip to content

Commit

Permalink
Merge pull request #3758 from nspcc-dev/sdk-fix
Browse files Browse the repository at this point in the history
services: fix error check for NeoFS client Dial
  • Loading branch information
AnnaShaleva authored Dec 16, 2024
2 parents 9189b3e + f5ea79d commit 24f81a7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ require (
golang.org/x/term v0.27.0
golang.org/x/text v0.21.0
golang.org/x/tools v0.24.0
google.golang.org/grpc v1.65.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down Expand Up @@ -73,6 +72,7 @@ require (
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
2 changes: 1 addition & 1 deletion pkg/services/blockfetcher/blockfetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestServiceConstructor(t *testing.T) {
require.Equal(t, service.IsActive(), false)
})

t.Run("SDK client", func(t *testing.T) {
t.Run("NeoFS client", func(t *testing.T) {
cfg := config.NeoFSBlockFetcher{
InternalService: config.InternalService{
Enabled: true,
Expand Down
15 changes: 5 additions & 10 deletions pkg/services/helpers/neofs/neofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/user"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

const (
Expand Down Expand Up @@ -58,7 +56,7 @@ type Client interface {
// URI scheme is "neofs:<Container-ID>/<Object-ID/<Command>/<Params>".
// If Command is not provided, full object is requested.
func Get(ctx context.Context, priv *keys.PrivateKey, u *url.URL, addr string) (io.ReadCloser, error) {
c, err := GetSDKClient(ctx, addr, 0)
c, err := GetClient(ctx, addr, 0)
if err != nil {
return clientCloseWrapper{c: c}, fmt.Errorf("failed to create client: %w", err)
}
Expand Down Expand Up @@ -273,9 +271,9 @@ func ObjectSearch(ctx context.Context, c Client, priv *keys.PrivateKey, containe
return objectIDs, nil
}

// GetSDKClient returns a NeoFS SDK client configured with the specified address and context.
// GetClient returns a NeoFS client configured with the specified address and context.
// If timeout is 0, the default timeout will be used.
func GetSDKClient(ctx context.Context, addr string, timeout time.Duration) (*client.Client, error) {
func GetClient(ctx context.Context, addr string, timeout time.Duration) (*client.Client, error) {
var prmDial client.PrmDial
if addr == "" {
return nil, errors.New("address is empty")
Expand All @@ -288,14 +286,11 @@ func GetSDKClient(ctx context.Context, addr string, timeout time.Duration) (*cli
}
c, err := client.New(client.PrmInit{})
if err != nil {
return nil, fmt.Errorf("can't create SDK client: %w", err)
return nil, fmt.Errorf("can't create NeoFS client: %w", err)
}

if err := c.Dial(prmDial); err != nil {
if status.Code(err) == codes.Unimplemented {
return c, nil
}
return nil, fmt.Errorf("can't init SDK client: %w", err)
return nil, fmt.Errorf("can't init NeoFS client: %w", err)
}

return c, nil
Expand Down

0 comments on commit 24f81a7

Please sign in to comment.