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 | Bin 59264 -> 59509 bytes 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 805a8226..877d15ce 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 6995418a..9781d495 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 c2f92265..e10413bc 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 e7a5484b..11ba941c 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 ac16c78ea52e41b6ed96b3f8f8134d8f2dcad1e2..d0aa1269742e40b87eec082d3f328449ffa80245 100644 GIT binary patch delta 114 zcmZoT&;0cQ^9KIR$x<2OPL>AdhNeaqy2hqPsg{;0mPwX|i3%BpR@!Ni-exIzVcI2? zMg{r-`C&dG>3&B3>HeveZs|GtX>O5eo&galWnPh!>(iwt_hm?lU^8m-o{S@P04Dt; A)Bpeg delta 18 Zcmex*fw|#4^9KIR$+Fp8oB6WR>i|x{2Y3Jg