Documentation
¶
Overview ¶
Package verifieddomain is the domain model for tenant-scoped DNS-TXT domain-ownership verification. A verified row proves a tenant controls an email domain and is the trust boundary that gates SSO JIT auto-provisioning.
Index ¶
- Variables
- func NormalizeDomain(raw string) (string, error)
- type Repository
- type Status
- type VerifiedDomain
- func (d *VerifiedDomain) CreatedAt() time.Time
- func (d *VerifiedDomain) Domain() string
- func (d *VerifiedDomain) ID() shared.ID
- func (d *VerifiedDomain) IsVerified() bool
- func (d *VerifiedDomain) LastCheckedAt() *time.Time
- func (d *VerifiedDomain) MarkChecked(t time.Time)
- func (d *VerifiedDomain) MarkVerified(t time.Time)
- func (d *VerifiedDomain) Status() Status
- func (d *VerifiedDomain) TenantID() shared.ID
- func (d *VerifiedDomain) UpdatedAt() time.Time
- func (d *VerifiedDomain) VerificationToken() string
- func (d *VerifiedDomain) VerifiedAt() *time.Time
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when no matching verified-domain row exists. ErrNotFound = fmt.Errorf("%w: verified domain not found", shared.ErrNotFound) // ErrAlreadyExists is returned when the tenant already has a row for the domain. ErrAlreadyExists = fmt.Errorf("%w: domain already added for this tenant", shared.ErrConflict) // ErrInvalidDomain is returned when a domain fails normalization/validation. ErrInvalidDomain = fmt.Errorf("%w: invalid domain", shared.ErrValidation) // ErrBlockedDomain is returned when a shared/public consumer domain is submitted; // such domains can never be owned by a single tenant. ErrBlockedDomain = fmt.Errorf("%w: shared/public domain cannot be verified", shared.ErrValidation) )
Functions ¶
func NormalizeDomain ¶
NormalizeDomain lowercases, trims, strips a trailing dot / leading "@", and validates the shape of a DNS domain name. It rejects wildcards, whitespace, schemes, and paths so a domain claim is an exact hostname.
Types ¶
type Repository ¶
type Repository interface {
Create(ctx context.Context, d *VerifiedDomain) error
Update(ctx context.Context, d *VerifiedDomain) error
Delete(ctx context.Context, tenantID, id shared.ID) error
GetByID(ctx context.Context, tenantID, id shared.ID) (*VerifiedDomain, error)
GetByTenantAndDomain(ctx context.Context, tenantID shared.ID, domain string) (*VerifiedDomain, error)
ListByTenant(ctx context.Context, tenantID shared.ID) ([]*VerifiedDomain, error)
// ListDueForRecheck returns verified rows whose last_checked_at is null or
// older than `checkedBefore`, across all tenants, capped at `limit`. Used by
// the background re-verify controller.
ListDueForRecheck(ctx context.Context, checkedBefore time.Time, limit int) ([]*VerifiedDomain, error)
}
Repository defines persistence operations for verified domains. All tenant-scoped methods MUST filter by tenant_id (multi-tenant isolation).
type Status ¶
type Status string
Status is the verification lifecycle state of a domain.
const ( // StatusPending — the TXT record has not yet been observed. StatusPending Status = "pending" // StatusVerified — the expected TXT record was observed; the tenant owns it. StatusVerified Status = "verified" // StatusFailed — a previously verified record disappeared (lapsed/hijacked), // or verification was explicitly abandoned. Fail-closed: no JIT authority. StatusFailed Status = "failed" )
type VerifiedDomain ¶
type VerifiedDomain struct {
// contains filtered or unexported fields
}
VerifiedDomain is a tenant's claim over an email domain, proven via DNS TXT.
func New ¶
func New(id, tenantID shared.ID, domain, token string) (*VerifiedDomain, error)
New creates a pending VerifiedDomain. The domain is normalized and validated; callers must supply a non-empty verification token. It does NOT enforce the shared/public-domain blocklist — that policy lives in the service layer.
func Reconstruct ¶
func Reconstruct( id, tenantID shared.ID, domain, token string, status Status, verifiedAt, lastCheckedAt *time.Time, createdAt, updatedAt time.Time, ) *VerifiedDomain
Reconstruct rebuilds a VerifiedDomain from persistence without validation.
func (*VerifiedDomain) CreatedAt ¶
func (d *VerifiedDomain) CreatedAt() time.Time
func (*VerifiedDomain) Domain ¶
func (d *VerifiedDomain) Domain() string
func (*VerifiedDomain) IsVerified ¶
func (d *VerifiedDomain) IsVerified() bool
func (*VerifiedDomain) LastCheckedAt ¶
func (d *VerifiedDomain) LastCheckedAt() *time.Time
func (*VerifiedDomain) MarkChecked ¶
func (d *VerifiedDomain) MarkChecked(t time.Time)
MarkChecked records that a verification attempt ran at t without success. A still-pending domain stays pending; a previously verified domain whose record vanished is downgraded to failed (fail-closed). Never promotes to verified.
func (*VerifiedDomain) MarkVerified ¶
func (d *VerifiedDomain) MarkVerified(t time.Time)
MarkVerified stamps the domain as verified at t and records the check time.
func (*VerifiedDomain) Status ¶
func (d *VerifiedDomain) Status() Status
func (*VerifiedDomain) TenantID ¶
func (d *VerifiedDomain) TenantID() shared.ID
func (*VerifiedDomain) UpdatedAt ¶
func (d *VerifiedDomain) UpdatedAt() time.Time
func (*VerifiedDomain) VerificationToken ¶
func (d *VerifiedDomain) VerificationToken() string
func (*VerifiedDomain) VerifiedAt ¶
func (d *VerifiedDomain) VerifiedAt() *time.Time