Files
mesh/scope.go
T

113 lines
3.0 KiB
Go

// Code generated by zi2go from scope.zi. DO NOT EDIT.
package main
import strings "strings"
// #import identity
// #import protocol
func Scope_ValidAppVisibility(value string) bool {
return value == "private" || value == "shared" || value == "friends" || value == "public"
}
func Scope_ValidLegacyProtocolStatus(value string) bool {
return value == "compatibility" || value == "deprecated" || value == "active"
}
func Scope_ValidTokenPolicyPermission(value string) bool {
return value == "spend" || value == "purchase"
}
func Scope_ValidCollectionPrefix(input string) bool {
value := strings.TrimSpace(input)
if value == "" {
return false
}
if Identity_ValidLegacyEncryptedCollection(value) {
return true
}
if strings.HasSuffix(value, ".*") {
return Scope_ValidCollectionPrefixWildcardBase(strings.TrimSuffix(value, ".*"))
}
return Identity_ValidEncryptedHierarchyCollection(value)
}
func Scope_ValidCollectionPrefixWildcardBase(value string) bool {
parts := strings.Split(strings.TrimSpace(value), ".")
if int64(len(parts)) == 2 && parts[0] == "account" {
return Identity_ValidVersionSegment(parts[1])
}
var value_0 bool = int64(len(parts)) >= 3
if value_0 {
var value_1 bool = Scope_ValidAppVisibility(parts[0])
value_0 = value_1
}
if value_0 {
var value_2 bool = Identity_ValidNamespaceSegment(parts[1])
var value_3 bool = !value_2
if !value_3 {
var value_4 bool = Identity_ValidVersionSegment(parts[2])
value_3 = !value_4
}
if value_3 {
return false
}
var index int64 = 3
for index < int64(len(parts)) {
var value_5 bool = Identity_ValidNamespaceSegment(parts[index])
if !value_5 {
return false
}
index++
}
return true
}
return false
}
func Scope_AppOwnsDeclaredScope(appID string, collection AppCollection) bool {
var value_0 bool = appID == "inbe"
if value_0 {
var value_1 bool = Identity_ValidLegacyEncryptedCollection(collection.CollectionPrefix)
value_0 = value_1
}
if value_0 {
return collection.Visibility == "private"
}
parts := strings.Split(strings.TrimSuffix(collection.CollectionPrefix, ".*"), ".")
if int64(len(parts)) < 3 || parts[1] != appID {
return false
}
return parts[0] == collection.Visibility
}
func Scope_DeclaresCollection(collections []AppCollection, prefix string) bool {
var index int64 = 0
for index < int64(len(collections)) {
if (collections[index]).CollectionPrefix == prefix {
return true
}
index++
}
return false
}
func Scope_CollectionMatchesPrefix(collection string, prefix string) bool {
if collection == prefix {
return true
}
if strings.HasSuffix(prefix, ".*") {
return strings.HasPrefix(collection, strings.TrimSuffix(prefix, "*"))
}
return false
}
func Scope_LikePatternForCollectionPrefix(prefix string) string {
base := strings.TrimSuffix(prefix, ".*")
base = strings.ReplaceAll(base, "\\", "\\\\")
base = strings.ReplaceAll(base, "%", "\\%")
base = strings.ReplaceAll(base, "_", "\\_")
parts := [2]string{base, ".%"}
_ = parts
return strings.Join(parts[0:2:2], "")
}