identity

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

View Source
var ErrIdentityConflict = errors.New("identity: duplicate identifier across users")

ErrIdentityConflict is the sentinel wrapped by ConflictError.

View Source
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

func MaskMail(mail string) string

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

func MaskPhone(phone string) string

MaskPhone masks a phone number, keeping only the last two digits. Empty input returns an empty string. Example: "13800138000" -> "*********00".

func MaskUserID

func MaskUserID(id string) string

MaskUserID masks a derived/opaque user_id, keeping a short non-identifying prefix.

Types

type ConflictError

type ConflictError struct {
	Field       FieldType
	MaskedValue string
	FirstIndex  int
	SecondIndex int
}

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 FieldType

type FieldType string

FieldType identifies which unique field caused a conflict.

const (
	FieldPhone  FieldType = "phone"
	FieldMail   FieldType = "mail"
	FieldUserID FieldType = "user_id"
)

Field type constants identify which unique field caused a conflict.

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL