[#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 21 additions and 6 deletions

View file

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