From cf8f640726a09cdd0b4d6213db4ff57c9d408c69 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 8 Jul 2021 20:16:14 +0300 Subject: [PATCH] [#675] cli/container: Support binary eACL format Signed-off-by: Pavel Karpy --- cmd/neofs-cli/modules/container.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index eb23611e7..0cd5c6494 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -68,9 +68,10 @@ var ( ) var ( - errDeleteTimeout = errors.New("timeout: container has not been removed from sidechain") - errCreateTimeout = errors.New("timeout: container has not been persisted on sidechain") - errSetEACLTimeout = errors.New("timeout: EACL has not been persisted on sidechain") + errDeleteTimeout = errors.New("timeout: container has not been removed from sidechain") + errCreateTimeout = errors.New("timeout: container has not been persisted on sidechain") + errSetEACLTimeout = errors.New("timeout: EACL has not been persisted on sidechain") + errUnsupportedEACLFormat = errors.New("unsupported eACL format") ) // containerCmd represents the container command @@ -715,17 +716,27 @@ func parseEACL(eaclPath string) (*eacl.Table, error) { } table := eacl.NewTable() - if err = table.UnmarshalJSON(data); err == nil { - v := table.Version() - if !version.IsValid(v) { - table.SetVersion(*pkg.SDKVersion()) - } + if err = table.UnmarshalJSON(data); err == nil { + validateAndFixEACLVersion(table) printVerbose("Parsed JSON encoded EACL table") return table, nil } - return nil, fmt.Errorf("can't parse EACL table: %w", err) + if err = table.Unmarshal(data); err == nil { + validateAndFixEACLVersion(table) + printVerbose("Parsed binary encoded EACL table") + return table, nil + } + + return nil, errUnsupportedEACLFormat +} + +func validateAndFixEACLVersion(table *eacl.Table) { + v := table.Version() + if !version.IsValid(v) { + table.SetVersion(*pkg.SDKVersion()) + } } func prettyPrintEACL(cmd *cobra.Command, table *eacl.Table) {