forked from TrueCloudLab/frostfs-node
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:
parent
b48a4ede02
commit
b12d26f974
5 changed files with 33 additions and 24 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
go.mod
2
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
|
||||
|
|
BIN
go.sum
BIN
go.sum
Binary file not shown.
Loading…
Reference in a new issue