Documentation
¶
Overview ¶
Package id defines TypeID-based identity types for all Warden entities.
Every entity in Warden uses a single ID struct with a prefix that identifies the entity type. IDs are K-sortable (UUIDv7-based), globally unique, and URL-safe in the format "prefix_suffix".
Index ¶
- type AnyID
- type AssignmentID
- type CheckLogID
- type ConditionID
- type ID
- func MustParse(s string) ID
- func MustParseWithPrefix(s string, expected Prefix) ID
- func New(prefix Prefix) ID
- func NewAssignmentID() ID
- func NewCheckLogID() ID
- func NewConditionID() ID
- func NewPermissionID() ID
- func NewPolicyID() ID
- func NewRelationID() ID
- func NewResourceTypeID() ID
- func NewRoleID() ID
- func Parse(s string) (ID, error)
- func ParseAny(s string) (ID, error)
- func ParseAssignmentID(s string) (ID, error)
- func ParseCheckLogID(s string) (ID, error)
- func ParseConditionID(s string) (ID, error)
- func ParsePermissionID(s string) (ID, error)
- func ParsePolicyID(s string) (ID, error)
- func ParseRelationID(s string) (ID, error)
- func ParseResourceTypeID(s string) (ID, error)
- func ParseRoleID(s string) (ID, error)
- func ParseWithPrefix(s string, expected Prefix) (ID, error)
- func (i ID) IsNil() bool
- func (i ID) MarshalBSONValue() (bsonType byte, data []byte, err error)
- func (i ID) MarshalText() ([]byte, error)
- func (i ID) Prefix() Prefix
- func (i *ID) Scan(src any) error
- func (i ID) String() string
- func (i *ID) UnmarshalBSONValue(t byte, data []byte) error
- func (i *ID) UnmarshalText(data []byte) error
- func (i ID) Value() (driver.Value, error)
- type PermissionID
- type PolicyID
- type Prefix
- type RelationID
- type ResourceTypeID
- type RoleID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssignmentID ¶
type AssignmentID = ID
AssignmentID is a type-safe identifier for role assignments (prefix: "asgn").
type CheckLogID ¶
type CheckLogID = ID
CheckLogID is a type-safe identifier for check log entries (prefix: "chklog").
type ConditionID ¶
type ConditionID = ID
ConditionID is a type-safe identifier for policy conditions (prefix: "cond").
type ID ¶
type ID struct {
// contains filtered or unexported fields
}
ID is the primary identifier type for all Warden entities. It wraps a TypeID providing a prefix-qualified, globally unique, sortable, URL-safe identifier in the format "prefix_suffix".
var Nil ID
Nil is the zero-value ID.
func MustParseWithPrefix ¶
MustParseWithPrefix is like ParseWithPrefix but panics on error.
func New ¶
New generates a new globally unique ID with the given prefix. It panics if prefix is not a valid TypeID prefix (programming error).
func NewAssignmentID ¶
func NewAssignmentID() ID
NewAssignmentID generates a new unique assignment ID.
func NewPermissionID ¶
func NewPermissionID() ID
NewPermissionID generates a new unique permission ID.
func NewResourceTypeID ¶
func NewResourceTypeID() ID
NewResourceTypeID generates a new unique resource type ID.
func Parse ¶
Parse parses a TypeID string (e.g., "role_01h2xcejqtf2nbrexx3vqjhp41") into an ID. Returns an error if the string is not valid.
func ParseAssignmentID ¶
ParseAssignmentID parses a string and validates the "asgn" prefix.
func ParseCheckLogID ¶
ParseCheckLogID parses a string and validates the "chklog" prefix.
func ParseConditionID ¶
ParseConditionID parses a string and validates the "cond" prefix.
func ParsePermissionID ¶
ParsePermissionID parses a string and validates the "perm" prefix.
func ParsePolicyID ¶
ParsePolicyID parses a string and validates the "wpol" prefix.
func ParseRelationID ¶
ParseRelationID parses a string and validates the "rel" prefix.
func ParseResourceTypeID ¶
ParseResourceTypeID parses a string and validates the "rtype" prefix.
func ParseRoleID ¶
ParseRoleID parses a string and validates the "role" prefix.
func ParseWithPrefix ¶
ParseWithPrefix parses a TypeID string and validates that its prefix matches the expected value.
func (ID) MarshalBSONValue ¶
MarshalBSONValue satisfies bson.ValueMarshaler (mongo-driver v2) so the ID is stored as a BSON string instead of an opaque struct. No bson import needed because Go uses structural typing for interface satisfaction.
func (ID) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (ID) String ¶
String returns the full TypeID string representation (prefix_suffix). Returns an empty string for the Nil ID.
func (*ID) UnmarshalBSONValue ¶
UnmarshalBSONValue satisfies bson.ValueUnmarshaler (mongo-driver v2).
func (*ID) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type PermissionID ¶
type PermissionID = ID
PermissionID is a type-safe identifier for permissions (prefix: "perm").
type PolicyID ¶
type PolicyID = ID
PolicyID is a type-safe identifier for ABAC policies (prefix: "wpol").
type Prefix ¶
type Prefix string
Prefix identifies the entity type encoded in a TypeID.
const ( PrefixRole Prefix = "role" PrefixPermission Prefix = "perm" PrefixAssignment Prefix = "asgn" PrefixPolicy Prefix = "wpol" PrefixRelation Prefix = "rel" PrefixCheckLog Prefix = "chklog" PrefixResourceType Prefix = "rtype" PrefixCondition Prefix = "cond" )
Prefix constants for all Warden entity types.
type RelationID ¶
type RelationID = ID
RelationID is a type-safe identifier for relation tuples (prefix: "rel").
type ResourceTypeID ¶
type ResourceTypeID = ID
ResourceTypeID is a type-safe identifier for resource type definitions (prefix: "rtype").