[#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 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

4
go.sum
View file

@ -276,8 +276,8 @@ github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:
github.com/nspcc-dev/neo-go v0.91.0/go.mod h1:G6HdOWvzQ6tlvFdvFSN/PgCzLPN/X/X4d5hTjFRUDcc= github.com/nspcc-dev/neo-go v0.91.0/go.mod h1:G6HdOWvzQ6tlvFdvFSN/PgCzLPN/X/X4d5hTjFRUDcc=
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b h1:gk5bZgpWOehaDVKI5vBDkcjXTpRkKqcvIb1h/vHnBH4= github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b h1:gk5bZgpWOehaDVKI5vBDkcjXTpRkKqcvIb1h/vHnBH4=
github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b/go.mod h1:9s7LNp2lMgf0caH2t0sam4+WT2SIauXozwP0AdBqnEo= github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b/go.mod h1:9s7LNp2lMgf0caH2t0sam4+WT2SIauXozwP0AdBqnEo=
github.com/nspcc-dev/neofs-api-go v1.20.3-0.20201123111542-5ee500bb43c6 h1:ecsG0Q9416WBLBV3+dzGOwMZvC+F9Z+UttwZ/f1kFLY= github.com/nspcc-dev/neofs-api-go v1.20.3-0.20201124121642-8c99d9d54c5c h1:VboS3Nn9lyv24ar5mQK5uwww3w2aJUc0DEL/GXhwmE8=
github.com/nspcc-dev/neofs-api-go v1.20.3-0.20201123111542-5ee500bb43c6/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8= github.com/nspcc-dev/neofs-api-go v1.20.3-0.20201124121642-8c99d9d54c5c/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8=
github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA=
github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw=
github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM= github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM=