Update neofs-api-go to latest version

Handle errors provided by JSON encoders.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-29 19:36:59 +03:00 committed by Alex Vanin
parent b48a4ede02
commit b12d26f974
5 changed files with 35 additions and 24 deletions

View file

@ -308,14 +308,14 @@ var getContainerInfoCmd = &cobra.Command{
) )
if containerJSON { if containerJSON {
data = v2container.ContainerToJSON(cnr.ToV2()) data, err = v2container.ContainerToJSON(cnr.ToV2())
if len(data) == 0 { if err != nil {
return errors.New("can't JSON encode container") return fmt.Errorf("can't JSON encode container: %w", err)
} }
} else { } else {
data, err = cnr.ToV2().StableMarshal(nil) data, err = cnr.ToV2().StableMarshal(nil)
if err != nil { if err != nil {
return errors.New("can't binary encode container") return fmt.Errorf("can't binary encode container: %w", err)
} }
} }
@ -365,14 +365,14 @@ var getExtendedACLCmd = &cobra.Command{
var data []byte var data []byte
if containerJSON { if containerJSON {
data = v2ACL.TableToJSON(eaclTable.ToV2()) data, err = v2ACL.TableToJSON(eaclTable.ToV2())
if len(data) == 0 { if err != nil {
return errors.New("can't encode to JSON") return fmt.Errorf("can't enode to JSON: %w", err)
} }
} else { } else {
data, err = eaclTable.ToV2().StableMarshal(nil) data, err = eaclTable.ToV2().StableMarshal(nil)
if err != nil { if err != nil {
return errors.New("can't encode to binary") return fmt.Errorf("can't enode to binary: %w", err)
} }
} }
@ -607,7 +607,11 @@ func prettyPrintContainer(cnr *container.Container, jsonEncoding bool) {
} }
if jsonEncoding { if jsonEncoding {
data := v2container.ContainerToJSON(cnr.ToV2()) data, err := v2container.ContainerToJSON(cnr.ToV2())
if err != nil {
printVerbose("Can't convert container to json: %w", err)
return
}
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
if err := json.Indent(buf, data, "", " "); err != nil { if err := json.Indent(buf, data, "", " "); err != nil {
printVerbose("Can't pretty print json: %w", err) printVerbose("Can't pretty print json: %w", err)
@ -674,19 +678,24 @@ func parseEACL(eaclPath string) (*eacl.Table, error) {
return eacl.NewTableFromV2(v2), nil return eacl.NewTableFromV2(v2), nil
} }
if v2 := v2ACL.TableFromJSON(data); v2 != nil { if v2, err := v2ACL.TableFromJSON(data); err == nil {
printVerbose("Parsed JSON encoded EACL table") printVerbose("Parsed JSON encoded EACL table")
return eacl.NewTableFromV2(v2), nil return eacl.NewTableFromV2(v2), nil
} }
return nil, errors.New("can't parse EACL table") return nil, fmt.Errorf("can't parse EACL table: %w", err)
} }
func prettyPrintEACL(table *eacl.Table) { func prettyPrintEACL(table *eacl.Table) {
data := v2ACL.TableToJSON(table.ToV2()) data, err := v2ACL.TableToJSON(table.ToV2())
if err != nil {
printVerbose("Can't convert container to json: %w", err)
return
}
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
if err := json.Indent(buf, data, "", " "); err != nil { if err := json.Indent(buf, data, "", " "); err != nil {
printVerbose("Can't pretty print json: %w", err) printVerbose("Can't pretty print json: %w", err)
return
} }
fmt.Println(buf) fmt.Println(buf)
} }

View file

@ -624,11 +624,11 @@ func getBearerToken(cmd *cobra.Command, flagname string) (*token.BearerToken, er
return nil, fmt.Errorf("can't read bearer token file: %w", err) return nil, fmt.Errorf("can't read bearer token file: %w", err)
} }
v2token := v2ACL.BearerTokenFromJSON(data) v2token, err := v2ACL.BearerTokenFromJSON(data)
if v2token == nil { if err != nil {
msg := new(grpcACL.BearerToken) msg := new(grpcACL.BearerToken)
if proto.Unmarshal(data, msg) != nil { if proto.Unmarshal(data, msg) != nil {
return nil, errors.New("can't decode bearer token") return nil, fmt.Errorf("can't decode beare token: %w", err)
} }
v2token = v2ACL.BearerTokenFromGRPCMessage(msg) v2token = v2ACL.BearerTokenFromGRPCMessage(msg)

View file

@ -89,14 +89,14 @@ func signBearerToken(cmd *cobra.Command, _ []string) error {
var data []byte var data []byte
if jsonFlag || len(to) == 0 { if jsonFlag || len(to) == 0 {
data = v2ACL.BearerTokenToJSON(btok.ToV2()) data, err = v2ACL.BearerTokenToJSON(btok.ToV2())
if len(data) == 0 { if err != nil {
return errors.New("can't JSON encode bearer token") return fmt.Errorf("can't JSON encode bearer token: %w", err)
} }
} else { } else {
data, err = btok.ToV2().StableMarshal(nil) data, err = btok.ToV2().StableMarshal(nil)
if err != nil { if err != nil {
return errors.New("can't binary encode bearer token") return fmt.Errorf("can't binary encode bearer token: %w", err)
} }
} }
@ -128,14 +128,14 @@ func convertEACLTable(cmd *cobra.Command, _ []string) error {
var data []byte var data []byte
if jsonFlag || len(to) == 0 { if jsonFlag || len(to) == 0 {
data = v2ACL.TableToJSON(table.ToV2()) data, err = v2ACL.TableToJSON(table.ToV2())
if len(data) == 0 { if err != nil {
return errors.New("can't JSON encode extended ACL table") return fmt.Errorf("can't JSON encode extended ACL table: %w", err)
} }
} else { } else {
data, err = table.ToV2().StableMarshal(nil) data, err = table.ToV2().StableMarshal(nil)
if err != nil { if err != nil {
return errors.New("can't binary encode extended ACL table") return fmt.Errorf("can't binary encode extended ACL table: %w", err)
} }
} }

2
go.mod
View file

@ -13,7 +13,7 @@ require (
github.com/multiformats/go-multiaddr-net v0.1.2 // v0.1.1 => v0.1.2 github.com/multiformats/go-multiaddr-net v0.1.2 // v0.1.1 => v0.1.2
github.com/multiformats/go-multihash v0.0.13 // indirect github.com/multiformats/go-multihash v0.0.13 // indirect
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20200827184617-7560aa345a78 github.com/nspcc-dev/neo-go v0.91.1-pre.0.20200827184617-7560aa345a78
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201028111149-ac38d13f04ff github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201029071528-352e99d9b91a
github.com/nspcc-dev/neofs-crypto v0.3.0 github.com/nspcc-dev/neofs-crypto v0.3.0
github.com/nspcc-dev/tzhash v1.4.0 github.com/nspcc-dev/tzhash v1.4.0
github.com/panjf2000/ants/v2 v2.3.0 github.com/panjf2000/ants/v2 v2.3.0

2
go.sum
View file

@ -273,6 +273,8 @@ github.com/nspcc-dev/neo-go v0.91.1-pre.0.20200827184617-7560aa345a78 h1:stIa+nB
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20200827184617-7560aa345a78/go.mod h1:G6HdOWvzQ6tlvFdvFSN/PgCzLPN/X/X4d5hTjFRUDcc= github.com/nspcc-dev/neo-go v0.91.1-pre.0.20200827184617-7560aa345a78/go.mod h1:G6HdOWvzQ6tlvFdvFSN/PgCzLPN/X/X4d5hTjFRUDcc=
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201028111149-ac38d13f04ff h1:TBybhFCjTdSgpw0zGLw7ucjA3gTTLZDfp4D2trcSyT4= github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201028111149-ac38d13f04ff h1:TBybhFCjTdSgpw0zGLw7ucjA3gTTLZDfp4D2trcSyT4=
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201028111149-ac38d13f04ff/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8= github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201028111149-ac38d13f04ff/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8=
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201029071528-352e99d9b91a h1:+fYK6dnV+ty2p/PoVLTgN2OgOeyFgl/fFYfIPXdvJYI=
github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201029071528-352e99d9b91a/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8=
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=