Documentation
¶
Overview ¶
Package uidp contains utilities for reasoning about and manipulating the Chainguard IAM "UIDP" (UID Path) concept.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Valid = regexp.MustCompile(`^[0-9a-f]{40}(?:/[0-9a-f]{16})*$`).MatchString
Valid returns true for valid UIDP values. The base segment of a UIDP is 20 hex-encoded bytes (40 characters). This may be followed by zero or more parts with 8 hex-encoded bytes (16 characters).
Functions ¶
func Ancestry ¶
Ancestry returns all parent UIDPs and the child. Returns only the child if it is root.
Example:
Ancestry("a/b/c/d") returns ["a/b/c/d", "a/b/c", "a/b", "a"]
Example ¶
ExampleAncestry demonstrates retrieving a UIDP and all its ancestors.
package main
import (
"fmt"
"chainguard.dev/sdk/uidp"
)
func main() {
fmt.Println(uidp.Ancestry("a/b/c/d"))
}
Output: [a/b/c/d a/b/c a/b a]
func InRoot ¶
InRoot checks whether the UIDP is in the root, as opposed to within a group
Example ¶
ExampleInRoot demonstrates checking whether a UIDP is at the root level.
package main
import (
"fmt"
"chainguard.dev/sdk/uidp"
)
func main() {
fmt.Println(uidp.InRoot("a"))
fmt.Println(uidp.InRoot("a/b"))
}
Output: true false
func IsAncestor ¶
IsAncestor checks whether the "parent" UIDP is an ancestor (non-inclusive) of the given "child" UIDP.
Example ¶
ExampleIsAncestor demonstrates checking whether a UIDP is a strict ancestor.
package main
import (
"fmt"
"chainguard.dev/sdk/uidp"
)
func main() {
fmt.Println(uidp.IsAncestor("a", "a/b"))
fmt.Println(uidp.IsAncestor("a", "a"))
}
Output: true false
func IsAncestorOrSelf ¶
IsAncestorOrSelf checks whether the "parent" UIDP is an ancestor (inclusive) of the given "child" UIDP.
Example ¶
ExampleIsAncestorOrSelf demonstrates the inclusive ancestor check.
package main
import (
"fmt"
"chainguard.dev/sdk/uidp"
)
func main() {
fmt.Println(uidp.IsAncestorOrSelf("a", "a"))
fmt.Println(uidp.IsAncestorOrSelf("a", "a/b"))
fmt.Println(uidp.IsAncestorOrSelf("a", "b"))
}
Output: true true false
func Parent ¶
Parent returns the "parent" UIDP for a child UIDP. Returns / if parent is root.
Example:
Parent("a/b/c") returns "a/b"
Parent("a") returns "/"
Example ¶
ExampleParent demonstrates retrieving the parent of a UIDP.
package main
import (
"fmt"
"chainguard.dev/sdk/uidp"
)
func main() {
fmt.Println(uidp.Parent("a/b/c"))
fmt.Println(uidp.Parent("a"))
}
Output: a/b /
func Parents ¶
Parents returns all "parent" UIDP for a child UIDP. Returns empty slice if parent is root.
Example:
Parents("a/b/c/d") returns ["a/b/c", "a/b", "a"]
Example ¶
ExampleParents demonstrates retrieving all ancestors of a UIDP.
package main
import (
"fmt"
"chainguard.dev/sdk/uidp"
)
func main() {
fmt.Println(uidp.Parents("a/b/c/d"))
}
Output: [a/b/c a/b a]
func Root ¶ added in v0.1.40
Root returns the root UIDP for a given UIDP. If the UIDP is already in root, it returns the UIDP itself.
Example ¶
ExampleRoot demonstrates retrieving the root segment of a UIDP.
package main
import (
"fmt"
"chainguard.dev/sdk/uidp"
)
func main() {
fmt.Println(uidp.Root("a/b/c"))
fmt.Println(uidp.Root("a"))
}
Output: a a
Types ¶
type SUID ¶
type SUID string
SUID is be used to form the primary key for items that must be unique within some scoping (non-global).
- A SUID is 8 random bytes, URL safe hex encoded.
type UID ¶
type UID string
UID will is used for the primary key for items that must be globally unique.
- A UID is 20 bytes of random bytes, URL safe hex encoded.
type UIDP ¶
type UIDP string
UIDP is be used to denote the fully-qualified path for scoped keys.
- A UIDP will consist of '/' delimited SUID segments with a UID root, following POSIX directory semantics.
- The "basename" SUID is our key within the scoping of the "dirname" UIDP.
func NewUIDP ¶
Example ¶
ExampleNewUIDP demonstrates creating a root UIDP (no parent path).
package main
import (
"fmt"
"chainguard.dev/sdk/uidp"
)
func main() {
p := uidp.NewUIDP("")
fmt.Println(len(string(p)) == 40)
}
Output: true
func (UIDP) Reparent ¶ added in v0.1.55
Reparent creates a new UIDP under parent using the SUID of u. This produces a deterministic child UIDP, useful when moving a record from one parent to another while preserving its identity within the new parent.
u must not be a root-level UIDP (i.e. it must contain a '/'). Returns an error if u has no SUID component to preserve.
Example ¶
ExampleUIDP_Reparent demonstrates reparenting a UIDP under a new parent.
package main
import (
"fmt"
"chainguard.dev/sdk/uidp"
)
func main() {
child := uidp.UIDP("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbb")
parent := uidp.UIDP("cccccccccccccccccccccccccccccccccccccccc")
result, err := child.Reparent(parent)
fmt.Println(err)
fmt.Println(result)
}
Output: <nil> cccccccccccccccccccccccccccccccccccccccc/bbbbbbbbbbbbbbbb