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 {
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
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-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
|
||||||
|
|
BIN
go.sum
BIN
go.sum
Binary file not shown.
Loading…
Reference in a new issue