From b12d26f974349148bd181491cae27983f181af3f Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 29 Oct 2020 19:36:59 +0300 Subject: [PATCH] Update neofs-api-go to latest version Handle errors provided by JSON encoders. Signed-off-by: Alex Vanin --- cmd/neofs-cli/modules/container.go | 33 +++++++++++++++++++----------- cmd/neofs-cli/modules/object.go | 6 +++--- cmd/neofs-cli/modules/util.go | 16 +++++++-------- go.mod | 2 +- go.sum | 2 ++ 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 805a8226c..877d15ce8 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -308,14 +308,14 @@ var getContainerInfoCmd = &cobra.Command{ ) if containerJSON { - data = v2container.ContainerToJSON(cnr.ToV2()) - if len(data) == 0 { - return errors.New("can't JSON encode container") + data, err = v2container.ContainerToJSON(cnr.ToV2()) + if err != nil { + return fmt.Errorf("can't JSON encode container: %w", err) } } else { data, err = cnr.ToV2().StableMarshal(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 if containerJSON { - data = v2ACL.TableToJSON(eaclTable.ToV2()) - if len(data) == 0 { - return errors.New("can't encode to JSON") + data, err = v2ACL.TableToJSON(eaclTable.ToV2()) + if err != nil { + return fmt.Errorf("can't enode to JSON: %w", err) } } else { data, err = eaclTable.ToV2().StableMarshal(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 { - 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) if err := json.Indent(buf, data, "", " "); err != nil { printVerbose("Can't pretty print json: %w", err) @@ -674,19 +678,24 @@ func parseEACL(eaclPath string) (*eacl.Table, error) { 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") 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) { - 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) if err := json.Indent(buf, data, "", " "); err != nil { printVerbose("Can't pretty print json: %w", err) + return } fmt.Println(buf) } diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index 6995418ae..9781d495d 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -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) } - v2token := v2ACL.BearerTokenFromJSON(data) - if v2token == nil { + v2token, err := v2ACL.BearerTokenFromJSON(data) + if err != nil { msg := new(grpcACL.BearerToken) 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) diff --git a/cmd/neofs-cli/modules/util.go b/cmd/neofs-cli/modules/util.go index c2f92265c..e10413bca 100644 --- a/cmd/neofs-cli/modules/util.go +++ b/cmd/neofs-cli/modules/util.go @@ -89,14 +89,14 @@ func signBearerToken(cmd *cobra.Command, _ []string) error { var data []byte if jsonFlag || len(to) == 0 { - data = v2ACL.BearerTokenToJSON(btok.ToV2()) - if len(data) == 0 { - return errors.New("can't JSON encode bearer token") + data, err = v2ACL.BearerTokenToJSON(btok.ToV2()) + if err != nil { + return fmt.Errorf("can't JSON encode bearer token: %w", err) } } else { data, err = btok.ToV2().StableMarshal(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 if jsonFlag || len(to) == 0 { - data = v2ACL.TableToJSON(table.ToV2()) - if len(data) == 0 { - return errors.New("can't JSON encode extended ACL table") + data, err = v2ACL.TableToJSON(table.ToV2()) + if err != nil { + return fmt.Errorf("can't JSON encode extended ACL table: %w", err) } } else { data, err = table.ToV2().StableMarshal(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) } } diff --git a/go.mod b/go.mod index e7a5484b8..11ba941cc 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( 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/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/tzhash v1.4.0 github.com/panjf2000/ants/v2 v2.3.0 diff --git a/go.sum b/go.sum index ac16c78ea..d0aa12697 100644 --- a/go.sum +++ b/go.sum @@ -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/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.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.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM=