Merge pull request #2003 from carpawell/update-neofs-api-go

Update neofs-api-go
This commit is contained in:
Roman Khimov 2021-06-11 14:19:12 +03:00 committed by GitHub
commit 61dfca346c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 22 deletions

3
go.mod
View file

@ -7,12 +7,11 @@ require (
github.com/btcsuite/btcd v0.20.1-beta github.com/btcsuite/btcd v0.20.1-beta
github.com/dgraph-io/badger/v2 v2.0.3 github.com/dgraph-io/badger/v2 v2.0.3
github.com/go-redis/redis v6.10.2+incompatible github.com/go-redis/redis v6.10.2+incompatible
github.com/gogo/protobuf v1.1.1
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/hashicorp/golang-lru v0.5.4 github.com/hashicorp/golang-lru v0.5.4
github.com/mr-tron/base58 v1.1.2 github.com/mr-tron/base58 v1.1.2
github.com/nspcc-dev/dbft v0.0.0-20210302103605-cc75991b7cfb github.com/nspcc-dev/dbft v0.0.0-20210302103605-cc75991b7cfb
github.com/nspcc-dev/neofs-api-go v1.24.0 github.com/nspcc-dev/neofs-api-go v1.27.1
github.com/nspcc-dev/rfc6979 v0.2.0 github.com/nspcc-dev/rfc6979 v0.2.0
github.com/pierrec/lz4 v2.5.2+incompatible github.com/pierrec/lz4 v2.5.2+incompatible
github.com/prometheus/client_golang v1.2.1 github.com/prometheus/client_golang v1.2.1

5
go.sum
View file

@ -85,7 +85,6 @@ github.com/go-redis/redis v6.10.2+incompatible h1:SLbqrO/Ik1nhXA5/cbEs1P5MUBo1Qq
github.com/go-redis/redis v6.10.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-redis/redis v6.10.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
@ -165,8 +164,10 @@ github.com/nspcc-dev/hrw v1.0.9 h1:17VcAuTtrstmFppBjfRiia4K2wA/ukXZhLFS8Y8rz5Y=
github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU= github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU=
github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg= github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg=
github.com/nspcc-dev/neo-go v0.91.0/go.mod h1:G6HdOWvzQ6tlvFdvFSN/PgCzLPN/X/X4d5hTjFRUDcc= github.com/nspcc-dev/neo-go v0.91.0/go.mod h1:G6HdOWvzQ6tlvFdvFSN/PgCzLPN/X/X4d5hTjFRUDcc=
github.com/nspcc-dev/neofs-api-go v1.24.0 h1:ZxROxsaCmIiv56sNHPf/FBeGHTT51fldp6uhDq0xwVE= github.com/nspcc-dev/neo-go v0.95.1/go.mod h1:bW07ge1WFXsBgqrcPpLUr6OcyQxHqM26MZNesWMdH0c=
github.com/nspcc-dev/neofs-api-go v1.24.0/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8= github.com/nspcc-dev/neofs-api-go v1.24.0/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8=
github.com/nspcc-dev/neofs-api-go v1.27.1 h1:ONdKOnm0/hK6m38VTUliCHY6RTxg+IpAzY4G+BeOZG4=
github.com/nspcc-dev/neofs-api-go v1.27.1/go.mod h1:i0Cwgvcu9A4M4e58pydbXFisUhSxpfljmuWFPIp2btE=
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM= github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM=

View file

@ -1,7 +1,6 @@
package neofs package neofs
import ( import (
"bytes"
"context" "context"
"errors" "errors"
"fmt" "fmt"
@ -10,13 +9,11 @@ import (
"strings" "strings"
"unicode/utf8" "unicode/utf8"
"github.com/gogo/protobuf/jsonpb"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-api-go/pkg/client" "github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/object"
objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object"
) )
const ( const (
@ -50,7 +47,7 @@ func Get(ctx context.Context, priv *keys.PrivateKey, u *url.URL, addr string) ([
return nil, err return nil, err
} }
c, err := client.New(&priv.PrivateKey, client.WithAddress(addr)) c, err := client.New(client.WithDefaultPrivateKey(&priv.PrivateKey), client.WithURIAddress(addr, nil))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -80,7 +77,7 @@ func parseNeoFSURL(u *url.URL) (*object.Address, []string, error) {
return nil, nil, ErrMissingObject return nil, nil, ErrMissingObject
} }
containerID := container.NewID() containerID := cid.New()
if err := containerID.Parse(ps[0]); err != nil { if err := containerID.Parse(ps[0]); err != nil {
return nil, nil, fmt.Errorf("%w: %v", ErrInvalidContainer, err) return nil, nil, fmt.Errorf("%w: %v", ErrInvalidContainer, err)
} }
@ -96,7 +93,7 @@ func parseNeoFSURL(u *url.URL) (*object.Address, []string, error) {
return objectAddr, ps[2:], nil return objectAddr, ps[2:], nil
} }
func getPayload(ctx context.Context, c *client.Client, addr *object.Address) ([]byte, error) { func getPayload(ctx context.Context, c client.Client, addr *object.Address) ([]byte, error) {
obj, err := c.GetObject(ctx, new(client.GetObjectParams).WithAddress(addr)) obj, err := c.GetObject(ctx, new(client.GetObjectParams).WithAddress(addr))
if err != nil { if err != nil {
return nil, err return nil, err
@ -104,7 +101,7 @@ func getPayload(ctx context.Context, c *client.Client, addr *object.Address) ([]
return checkUTF8(obj.Payload()) return checkUTF8(obj.Payload())
} }
func getRange(ctx context.Context, c *client.Client, addr *object.Address, ps ...string) ([]byte, error) { func getRange(ctx context.Context, c client.Client, addr *object.Address, ps ...string) ([]byte, error) {
if len(ps) == 0 { if len(ps) == 0 {
return nil, ErrInvalidRange return nil, ErrInvalidRange
} }
@ -119,18 +116,15 @@ func getRange(ctx context.Context, c *client.Client, addr *object.Address, ps ..
return checkUTF8(data) return checkUTF8(data)
} }
func getHeader(ctx context.Context, c *client.Client, addr *object.Address) ([]byte, error) { func getHeader(ctx context.Context, c client.Client, addr *object.Address) ([]byte, error) {
obj, err := c.GetObjectHeader(ctx, new(client.ObjectHeaderParams).WithAddress(addr)) obj, err := c.GetObjectHeader(ctx, new(client.ObjectHeaderParams).WithAddress(addr))
if err != nil { if err != nil {
return nil, err return nil, err
} }
msg := objectv2.ObjectToGRPCMessage(obj.ToV2()).Header return obj.MarshalHeaderJSON()
b := bytes.NewBuffer(nil)
err = new(jsonpb.Marshaler).Marshal(b, msg)
return b.Bytes(), err
} }
func getHash(ctx context.Context, c *client.Client, addr *object.Address, ps ...string) ([]byte, error) { func getHash(ctx context.Context, c client.Client, addr *object.Address, ps ...string) ([]byte, error) {
if len(ps) == 0 || ps[0] == "" { // hash of the full payload if len(ps) == 0 || ps[0] == "" { // hash of the full payload
obj, err := c.GetObjectHeader(ctx, new(client.ObjectHeaderParams).WithAddress(addr)) obj, err := c.GetObjectHeader(ctx, new(client.ObjectHeaderParams).WithAddress(addr))
if err != nil { if err != nil {

View file

@ -5,7 +5,7 @@ import (
"net/url" "net/url"
"testing" "testing"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -37,8 +37,8 @@ func TestParseRange(t *testing.T) {
func TestParseNeoFSURL(t *testing.T) { func TestParseNeoFSURL(t *testing.T) {
cStr := "C3swfg8MiMJ9bXbeFG6dWJTCoHp9hAEZkHezvbSwK1Cc" cStr := "C3swfg8MiMJ9bXbeFG6dWJTCoHp9hAEZkHezvbSwK1Cc"
cid := container.NewID() containerID := cid.New()
require.NoError(t, cid.Parse(cStr)) require.NoError(t, containerID.Parse(cStr))
oStr := "3nQH1L8u3eM9jt2mZCs6MyjzdjerdSzBkXCYYj4M4Znk" oStr := "3nQH1L8u3eM9jt2mZCs6MyjzdjerdSzBkXCYYj4M4Znk"
oid := object.NewID() oid := object.NewID()
@ -46,7 +46,7 @@ func TestParseNeoFSURL(t *testing.T) {
validPrefix := "neofs:" + cStr + "/" + oStr validPrefix := "neofs:" + cStr + "/" + oStr
objectAddr := object.NewAddress() objectAddr := object.NewAddress()
objectAddr.SetContainerID(cid) objectAddr.SetContainerID(containerID)
objectAddr.SetObjectID(oid) objectAddr.SetObjectID(oid)
testCases := []struct { testCases := []struct {