Assemble collection resources by qualified ID
This commit is contained in:
@@ -38,3 +38,27 @@ func resourceNamespaceFromID(id string) (string, bool) {
|
||||
namespace, _, _ := strings.Cut(id, "/")
|
||||
return namespace, true
|
||||
}
|
||||
|
||||
// IsValidResourceID reports whether id is an unqualified resource ID or one
|
||||
// valid namespace/local-ID pair.
|
||||
func IsValidResourceID(id string) bool { return validResourceID(id) }
|
||||
|
||||
// IsValidResourceNamespace reports whether namespace is nonblank and contains
|
||||
// no namespace separator.
|
||||
func IsValidResourceNamespace(namespace string) bool { return validResourceNamespace(namespace) }
|
||||
|
||||
// IsValidLocalResourceKey reports whether key is a nonblank key for a
|
||||
// namespace-local resource mapping.
|
||||
func IsValidLocalResourceKey(key string) bool { return validLocalResourceKey(key) }
|
||||
|
||||
// QualifyLocalResourceID combines a validated namespace and local mapping key.
|
||||
// An empty namespace leaves a valid unqualified key unchanged.
|
||||
func QualifyLocalResourceID(namespace, key string) (string, bool) {
|
||||
if !validLocalResourceKey(key) || (namespace != "" && !validResourceNamespace(namespace)) {
|
||||
return "", false
|
||||
}
|
||||
if namespace == "" {
|
||||
return key, true
|
||||
}
|
||||
return namespace + "/" + key, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user