Documentation
¶
Overview ¶
Package identity provides centralized validation and indexing of allow-list users before they enter the shared cache. It enforces identifier uniqueness (no last-write-wins), produces deterministic ordering, and returns structured, masked errors that never leak full phone numbers or email addresses.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrIdentityConflict = errors.New("identity: duplicate identifier across users")
ErrIdentityConflict is the sentinel wrapped by ConflictError.
var ErrMissingUserID = errors.New("identity: explicit user_id required but missing")
ErrMissingUserID is returned when REQUIRE_EXPLICIT_USER_ID is set but a record has none.
Functions ¶
func MaskMail ¶
MaskMail masks an email, keeping the first character of the local part and the full domain. Example: "alice@example.com" -> "a****@example.com".
func MaskPhone ¶
MaskPhone masks a phone number, keeping only the last two digits. Empty input returns an empty string. Example: "13800138000" -> "*********00".
func MaskUserID ¶
MaskUserID masks a derived/opaque user_id, keeping a short non-identifying prefix.
Types ¶
type ConflictError ¶
ConflictError describes a uniqueness violation. Values are masked; only positions (record indices) and the field type are exposed for diagnostics.
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
func (*ConflictError) Unwrap ¶
func (e *ConflictError) Unwrap() error
type MissingUserIDError ¶
type MissingUserIDError struct {
// MaskedIdentifier is a masked phone/mail used only for diagnostics.
MaskedIdentifier string
Index int
}
MissingUserIDError describes a record missing a required explicit user_id.
func (*MissingUserIDError) Error ¶
func (e *MissingUserIDError) Error() string
func (*MissingUserIDError) Unwrap ¶
func (e *MissingUserIDError) Unwrap() error
type Options ¶
type Options struct {
// RequireExplicitUserID rejects records whose user_id is empty after normalization.
RequireExplicitUserID bool
// ReportOnly performs a dry run: it collects conflict/missing counts without
// failing on the first violation and does not require a clean set.
ReportOnly bool
}
Options controls validation behavior.
type Result ¶
type Result struct {
// Users is the validated, deterministically-ordered rule set (only when Err == nil).
Users []define.AllowListUser
// ConflictCount / MissingIDCount are populated in read-only (report) mode.
ConflictCount int
MissingIDCount int
}
Result is the outcome of ValidateAndIndexUsers.
func ValidateAndIndexUsers ¶
func ValidateAndIndexUsers(users []define.AllowListUser, opts Options) (Result, error)
ValidateAndIndexUsers normalizes, validates identifier uniqueness, and returns a deterministically-ordered copy of users. Two different records may not share any non-empty user_id, phone, or normalized mail (last-write-wins is rejected).
In normal mode it returns the first violation as a typed error. In ReportOnly mode it returns counts of all violations without an error (used by the read-only check).