[#675] cli/container: Support binary eACL format

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-07-08 20:16:14 +03:00 committed by Alex Vanin
parent d189d60925
commit cf8f640726

View file

@ -71,6 +71,7 @@ var (
errDeleteTimeout = errors.New("timeout: container has not been removed from sidechain") errDeleteTimeout = errors.New("timeout: container has not been removed from sidechain")
errCreateTimeout = errors.New("timeout: container has not been persisted on sidechain") errCreateTimeout = errors.New("timeout: container has not been persisted on sidechain")
errSetEACLTimeout = errors.New("timeout: EACL 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 // containerCmd represents the container command
@ -715,17 +716,27 @@ func parseEACL(eaclPath string) (*eacl.Table, error) {
} }
table := eacl.NewTable() 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") printVerbose("Parsed JSON encoded EACL table")
return table, nil 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) { func prettyPrintEACL(cmd *cobra.Command, table *eacl.Table) {