[#106] Add basic ACL parser

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-12-29 10:48:01 +03:00 committed by Alex Vanin
parent d4d0feb59d
commit bd110d8b41

View file

@ -1,5 +1,11 @@
package acl package acl
import (
"fmt"
"strconv"
"strings"
)
const ( const (
// PublicBasicRule is a basic ACL value for final public-read-write container for which extended ACL CANNOT be set. // PublicBasicRule is a basic ACL value for final public-read-write container for which extended ACL CANNOT be set.
PublicBasicRule = 0x1FBFBFFF PublicBasicRule = 0x1FBFBFFF
@ -51,3 +57,34 @@ const (
// EACLPublicAppendName is a well-known name for 0x0FBF9FFF basic ACL. // EACLPublicAppendName is a well-known name for 0x0FBF9FFF basic ACL.
EACLPublicAppendName = "eacl-public-append" EACLPublicAppendName = "eacl-public-append"
) )
// ParseBasicACL parse string ACL (well-known names or hex representation).
func ParseBasicACL(basicACL string) (uint32, error) {
switch basicACL {
case PublicBasicName:
return PublicBasicRule, nil
case PrivateBasicName:
return PrivateBasicRule, nil
case ReadOnlyBasicName:
return ReadOnlyBasicRule, nil
case PublicAppendName:
return PublicAppendRule, nil
case EACLPublicBasicName:
return EACLPublicBasicRule, nil
case EACLPrivateBasicName:
return EACLPrivateBasicRule, nil
case EACLReadOnlyBasicName:
return EACLReadOnlyBasicRule, nil
case EACLPublicAppendName:
return EACLPublicAppendRule, nil
default:
basicACL = strings.Trim(strings.ToLower(basicACL), "0x")
value, err := strconv.ParseUint(basicACL, 16, 32)
if err != nil {
return 0, fmt.Errorf("can't parse basic ACL: %s", basicACL)
}
return uint32(value), nil
}
}