forked from TrueCloudLab/policy-engine
e57d213595
Close #26 Signed-off-by: Airat Arifullin <aarifullin@yadro.com>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package util
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"git.frostfs.info/TrueCloudLab/policy-engine/schema/native"
|
|
)
|
|
|
|
var nativePatterns = []string{
|
|
native.ResourceFormatNamespaceObjects, native.ResourceFormatNamespaceContainerObjects,
|
|
native.ResourceFormatNamespaceContainerObject, native.ResourceFormatRootObjects,
|
|
native.ResourceFormatRootContainerObjects, native.ResourceFormatRootContainerObject,
|
|
native.ResourceFormatAllObjects, native.ResourceFormatNamespaceContainer,
|
|
native.ResourceFormatNamespaceContainers, native.ResourceFormatRootContainer,
|
|
native.ResourceFormatRootContainers, native.ResourceFormatAllContainers,
|
|
}
|
|
|
|
func match(resource, pattern string) bool {
|
|
rTokens := strings.Split(resource, "/")
|
|
pToken := strings.Split(pattern, "/")
|
|
|
|
if len(rTokens) != len(pToken) {
|
|
return false
|
|
}
|
|
|
|
for i := range rTokens {
|
|
if pToken[i] == "%s" {
|
|
continue
|
|
}
|
|
if pToken[i] != rTokens[i] {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func IsNativeResourceNameValid(resource string) bool {
|
|
for _, pattern := range nativePatterns {
|
|
if match(resource, pattern) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|