[#206] cli/container: Use GetEACLWithSignature client method

Use GetEACLWithSignature client method in get-eacl cmd of container CLI in
order to print eACL table and signature regardless of their correctness. The
ability to check the correctness of the signature will be added later.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-24 16:06:02 +03:00 committed by Leonard Lyubich
parent 706bdf736e
commit e8bc03d92f
3 changed files with 19 additions and 4 deletions

View file

@ -340,13 +340,21 @@ var getExtendedACLCmd = &cobra.Command{
return err return err
} }
eaclTable, err := cli.GetEACL(ctx, id, client.WithTTL(getTTL())) res, err := cli.GetEACLWithSignature(ctx, id, client.WithTTL(getTTL()))
if err != nil { if err != nil {
return fmt.Errorf("rpc error: %w", err) return fmt.Errorf("rpc error: %w", err)
} }
eaclTable := res.EACL()
sig := res.Signature()
if containerPathTo == "" { if containerPathTo == "" {
fmt.Println("eACL: ")
prettyPrintEACL(eaclTable) prettyPrintEACL(eaclTable)
fmt.Println("Signature:")
printJSONMarshaler(sig, "signature")
return nil return nil
} }
@ -366,6 +374,9 @@ var getExtendedACLCmd = &cobra.Command{
fmt.Println("dumping data to file:", containerPathTo) fmt.Println("dumping data to file:", containerPathTo)
fmt.Println("Signature:")
printJSONMarshaler(sig, "signature")
return ioutil.WriteFile(containerPathTo, data, 0644) return ioutil.WriteFile(containerPathTo, data, 0644)
}, },
} }
@ -694,9 +705,13 @@ func parseEACL(eaclPath string) (*eacl.Table, error) {
} }
func prettyPrintEACL(table *eacl.Table) { func prettyPrintEACL(table *eacl.Table) {
data, err := table.MarshalJSON() printJSONMarshaler(table, "eACL")
}
func printJSONMarshaler(j json.Marshaler, entity string) {
data, err := j.MarshalJSON()
if err != nil { if err != nil {
printVerbose("Can't convert container to json: %w", err) printVerbose("Can't convert %s to json: %w", entity, err)
return return
} }
buf := new(bytes.Buffer) buf := new(bytes.Buffer)

2
go.mod
View file

@ -14,7 +14,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.20201030072836-71216865717b github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b
github.com/nspcc-dev/neofs-api-go v1.20.3-0.20201123111542-5ee500bb43c6 github.com/nspcc-dev/neofs-api-go v1.20.3-0.20201124121642-8c99d9d54c5c
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

Binary file not shown.